当前位置: 首页>>代码示例>>Python>>正文


Python GoogleDriveNodeSettingsFactory.save方法代码示例

本文整理汇总了Python中website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python GoogleDriveNodeSettingsFactory.save方法的具体用法?Python GoogleDriveNodeSettingsFactory.save怎么用?Python GoogleDriveNodeSettingsFactory.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory的用法示例。


在下文中一共展示了GoogleDriveNodeSettingsFactory.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_set_user_auth

# 需要导入模块: from website.addons.googledrive.tests.factories import GoogleDriveNodeSettingsFactory [as 别名]
# 或者: from website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory import save [as 别名]
    def test_set_user_auth(self):
        node_settings = GoogleDriveNodeSettingsFactory()
        user_settings = GoogleDriveUserSettingsFactory()

        node_settings.set_user_auth(user_settings)
        node_settings.save()

        assert_true(node_settings.has_auth)
        assert_equal(node_settings.user_settings, user_settings)
        # A log was saved
        last_log = node_settings.owner.logs[-1]
        log_params = last_log.params

        assert_equal(last_log.user, user_settings.owner)
        assert_equal(log_params['folder'], node_settings.folder_path)
        assert_equal(last_log.action, 'googledrive_node_authorized')
        assert_equal(log_params['node'], node_settings.owner._primary_key)
开发者ID:billyhunt,项目名称:osf.io,代码行数:19,代码来源:test_models.py

示例2: TestNodeSettingsCallbacks

# 需要导入模块: from website.addons.googledrive.tests.factories import GoogleDriveNodeSettingsFactory [as 别名]
# 或者: from website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory import save [as 别名]
class TestNodeSettingsCallbacks(OsfTestCase):

    def setUp(self):
        super(TestNodeSettingsCallbacks, self).setUp()
        # Create node settings with auth
        self.user_settings = GoogleDriveUserSettingsFactory(access_token='123abc', username='name/email')
        self.node_settings = GoogleDriveNodeSettingsFactory(
            user_settings=self.user_settings,
            folder='',
        )

        self.project = self.node_settings.owner
        self.user = self.user_settings.owner

    def test_after_fork_by_authorized_googledrive_user(self):
        fork = ProjectFactory()
        clone, message = self.node_settings.after_fork(
            node=self.project, fork=fork, user=self.user_settings.owner
        )
        assert_equal(clone.user_settings, self.user_settings)

    def test_after_fork_by_unauthorized_googledrive_user(self):
        fork = ProjectFactory()
        user = UserFactory()
        clone, message = self.node_settings.after_fork(
            node=self.project, fork=fork, user=user,
            save=True
        )
        # need request context for url_for
        assert_is(clone.user_settings, None)

    def test_before_fork(self):
        node = ProjectFactory()
        message = self.node_settings.before_fork(node, self.user)
        assert_true(message)

    def test_before_remove_contributor_message(self):
        message = self.node_settings.before_remove_contributor(
            self.project, self.user)
        assert_true(message)
        assert_in(self.user.fullname, message)
        assert_in(self.project.project_or_component, message)

    def test_after_remove_authorized_googledrive_user_not_self(self):
        message = self.node_settings.after_remove_contributor(
            self.project, self.user_settings.owner)
        self.node_settings.save()
        assert_is_none(self.node_settings.user_settings)
        assert_true(message)
        assert_in("You can re-authenticate", message)

    def test_after_remove_authorized_googledrive_user_self(self):
        auth = Auth(user=self.user_settings.owner)
        message = self.node_settings.after_remove_contributor(
            self.project, self.user_settings.owner, auth)
        self.node_settings.save()
        assert_is_none(self.node_settings.user_settings)
        assert_true(message)
        assert_not_in("You can re-authenticate", message)

    def test_after_delete(self):
        self.project.remove_node(Auth(user=self.project.creator))
        # Ensure that changes to node settings have been saved
        self.node_settings.reload()
        assert_true(self.node_settings.folder_id is None)
        assert_true(self.node_settings.folder_path is None)
        assert_true(self.node_settings.user_settings is None)

    @mock.patch('website.archiver.tasks.archive')
    def test_does_not_get_copied_to_registrations(self, mock_archive):
        registration = self.project.register_node(
            schema=None,
            auth=Auth(user=self.project.creator),
            template='Template1',
            data='hodor'
        )
        assert_false(registration.has_addon('googledrive'))
开发者ID:billyhunt,项目名称:osf.io,代码行数:79,代码来源:test_models.py

示例3: TestGoogleDriveNodeSettingsModel

# 需要导入模块: from website.addons.googledrive.tests.factories import GoogleDriveNodeSettingsFactory [as 别名]
# 或者: from website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory import save [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.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。