當前位置: 首頁>>代碼示例>>Python>>正文


Python GoogleDriveNodeSettingsFactory.deauthorize方法代碼示例

本文整理匯總了Python中website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory.deauthorize方法的典型用法代碼示例。如果您正苦於以下問題:Python GoogleDriveNodeSettingsFactory.deauthorize方法的具體用法?Python GoogleDriveNodeSettingsFactory.deauthorize怎麽用?Python GoogleDriveNodeSettingsFactory.deauthorize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory的用法示例。


在下文中一共展示了GoogleDriveNodeSettingsFactory.deauthorize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestGoogleDriveNodeSettingsModel

# 需要導入模塊: from website.addons.googledrive.tests.factories import GoogleDriveNodeSettingsFactory [as 別名]
# 或者: from website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory import deauthorize [as 別名]
class TestGoogleDriveNodeSettingsModel(OsfTestCase):

    def setUp(self):
        super(TestGoogleDriveNodeSettingsModel, self).setUp()
        self.user = UserFactory()
        self.user.add_addon('googledrive')
        self.user.save()
        self.user_settings = self.user.get_addon('googledrive')
        oauth_settings = GoogleDriveOAuthSettingsFactory()
        oauth_settings.save()
        self.user_settings.oauth_settings = oauth_settings
        self.user_settings.save()
        self.project = ProjectFactory()
        self.node_settings = GoogleDriveNodeSettingsFactory(
            user_settings=self.user_settings,
            owner=self.project,
        )

    def test_fields(self):
        node_settings = GoogleDriveNodeSettings(user_settings=self.user_settings)
        node_settings.save()

        assert_true(node_settings.user_settings)
        assert_true(hasattr(node_settings, 'folder_id'))
        assert_true(hasattr(node_settings, 'folder_path'))
        assert_true(hasattr(node_settings, 'folder_name'))
        assert_equal(node_settings.user_settings.owner, self.user)

    def test_complete_true(self):
        assert_true(self.node_settings.has_auth)
        assert_true(self.node_settings.complete)

    def test_complete_false(self):
        self.node_settings.folder_id = None

        assert_true(self.node_settings.has_auth)
        assert_false(self.node_settings.complete)

    def test_complete_auth_false(self):
        self.node_settings.user_settings = None

        assert_false(self.node_settings.has_auth)
        assert_false(self.node_settings.complete)

    def test_folder_defaults_to_none(self):
        node_settings = GoogleDriveNodeSettings(user_settings=self.user_settings)
        node_settings.save()

        assert_is_none(node_settings.folder_id)
        assert_is_none(node_settings.folder_path)

    def test_has_auth(self):
        settings = GoogleDriveNodeSettings(user_settings=self.user_settings)
        settings.user_settings.access_token = None
        settings.save()

        assert_false(settings.has_auth)

        settings.user_settings.access_token = '123abc'
        settings.user_settings.save()

        assert_true(settings.has_auth)

    # TODO use this test if delete function is used in googledrive/model
    # def test_delete(self):
    #     assert_true(self.node_settings.user_settings)
    #     assert_true(self.node_settings.folder)
    #     old_logs = self.project.logs
    #     self.node_settings.delete()
    #     self.node_settings.save()
    #     assert_is(self.node_settings.user_settings, None)
    #     assert_is(self.node_settings.folder, None)
    #     assert_true(self.node_settings.deleted)
    #     assert_equal(self.project.logs, old_logs)

    def test_deauthorize(self):
        assert_true(self.node_settings.folder_id)
        assert_true(self.node_settings.user_settings)

        self.node_settings.deauthorize(auth=Auth(self.user))
        self.node_settings.save()

        assert_is(self.node_settings.folder_id, None)
        assert_is(self.node_settings.user_settings, None)

        last_log = self.project.logs[-1]
        params = last_log.params

        assert_in('node', params)
        assert_in('folder', params)
        assert_in('project', params)
        assert_equal(last_log.action, 'googledrive_node_deauthorized')

    def test_set_folder(self):
        folder_name = {
            'id': '1234',
            'name': 'freddie',
            'path': 'queen/freddie',
        }

#.........這裏部分代碼省略.........
開發者ID:billyhunt,項目名稱:osf.io,代碼行數:103,代碼來源:test_models.py


注:本文中的website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory.deauthorize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。