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


Python ProjectFactory.get_or_add_addon方法代码示例

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


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

示例1: test_import_auth

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_or_add_addon [as 别名]
    def test_import_auth(self):
        ea = self.ExternalAccountFactory()
        self.user.external_accounts.append(ea)
        self.user.save()

        node = ProjectFactory(creator=self.user)
        node_settings = node.get_or_add_addon(self.ADDON_SHORT_NAME, auth=Auth(self.user))
        node.save()
        url = node.api_url_for("{0}_import_auth".format(self.ADDON_SHORT_NAME))
        res = self.app.put_json(url, {"external_account_id": ea._id}, auth=self.user.auth)
        assert_equal(res.status_code, http.OK)
        assert_in("result", res.json)
        node_settings.reload()
        assert_equal(node_settings.external_account._id, ea._id)

        node.reload()
        last_log = node.logs[-1]
        assert_equal(last_log.action, "{0}_node_authorized".format(self.ADDON_SHORT_NAME))
开发者ID:ycchen1989,项目名称:osf.io,代码行数:20,代码来源:views.py

示例2: TestNodeSettings

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_or_add_addon [as 别名]
class TestNodeSettings(OsfTestCase):

    ADDONS_UNDER_TEST = {
        MockOAuth2Provider.short_name: {
            'user_settings': MockUserSettings,
            'node_settings': MockNodeSettings,
        }
    }

    @classmethod
    def setUpClass(cls):
        super(TestNodeSettings, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestNodeSettings, cls).tearDownClass()

    def setUp(self):
        super(TestNodeSettings, self).setUp()
        self.project = ProjectFactory()
        self.user = self.project.creator
        self.node_settings = self.project.get_or_add_addon(
            MockNodeSettings.oauth_provider.short_name,
            auth=Auth(user=self.user)
        )
        self.user_settings = self.user.get_or_add_addon(
            MockUserSettings.oauth_provider.short_name
        )
        self.external_account = ExternalAccountFactory()
        self.user.external_accounts.append(self.external_account)
        self.user.save()

    def test_has_auth_false(self):
        assert_false(self.node_settings.has_auth)

    def test_has_auth_no_grant(self):
        self.node_settings.external_account = self.external_account
        self.node_settings.user_settings = self.user_settings

        assert_false(self.node_settings.has_auth)

    def test_has_auth(self):
        self.node_settings.set_auth(
            external_account=self.external_account,
            user=self.user
        )

        assert_true(self.node_settings.has_auth)

    def test_set_auth(self):
        self.node_settings.set_auth(
            external_account=self.external_account,
            user=self.user
        )

        assert_equal(
            self.node_settings.external_account,
            self.external_account
        )
        assert_equal(
            self.node_settings.user_settings,
            self.user_settings
        )
        assert_in(
            self.project._id,
            self.user_settings.oauth_grants.keys()
        )

    def test_revoke_auth(self):
        self.node_settings.set_auth(
            external_account=self.external_account,
            user=self.user
        )
        self.user_settings.revoke_oauth_access(self.external_account)

        assert_equal(
            self.user_settings.oauth_grants,
            {self.project._id: {}}
        )

    def test_clear_auth(self):
        self.node_settings.external_account = self.external_account
        self.node_settings.user_settings = self.user_settings

        self.node_settings.clear_auth()

        assert_is_none(self.node_settings.external_account)
        assert_is_none(self.node_settings.user_settings)
开发者ID:GageGaskins,项目名称:osf.io,代码行数:90,代码来源:test_addons_oauth.py

示例3: TestUserSettings

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_or_add_addon [as 别名]
class TestUserSettings(OsfTestCase):

    ADDONS_UNDER_TEST = {
        MockOAuth2Provider.short_name: {
            'user_settings': MockUserSettings,
            'node_settings': MockNodeSettings,
        }
    }

    @classmethod
    def setUpClass(cls):
        super(TestUserSettings, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestUserSettings, cls).tearDownClass()

    def setUp(self):
        super(TestUserSettings, self).setUp()
        self.user = AuthUserFactory()

        self.user_settings = self.user.get_or_add_addon(
            MockUserSettings.oauth_provider.short_name
        )

        self.external_account = ExternalAccountFactory()
        self.user.external_accounts.append(self.external_account)
        self.user.save()

        self.project = ProjectFactory(creator=self.user)

    def tearDown(self):
        super(TestUserSettings, self).tearDown()

    def test_connected_accounts_empty(self):
        self.user.external_accounts = []

        assert_equal(
            self.user_settings.external_accounts,
            []
        )

    def test_connected_accounts(self):
        assert_equal(
            self.user_settings.external_accounts,
            [self.external_account]
        )

    def test_verify_false_no_grants(self):
        assert_false(
            self.user_settings.verify_oauth_access(
                external_account=self.external_account,
                node=self.project
            )
        )

    def test_verify_false_with_grants(self):
        self.user_settings.grant_oauth_access(
            external_account=self.external_account,
            node=ProjectFactory()
        )

        assert_false(
            self.user_settings.verify_oauth_access(
                external_account=self.external_account,
                node=self.project
            )
        )

    def test_verify_false_metadata(self):
        self.user_settings.grant_oauth_access(
            external_account=self.external_account,
            node=self.project,
            metadata={'foo': 'bar'}
        )

        assert_false(
            self.user_settings.verify_oauth_access(
                external_account=self.external_account,
                node=self.project,
                metadata={'baz': 'qiz'}
            )
        )

    def test_verify_true(self):
        self.user_settings.grant_oauth_access(
            external_account=self.external_account,
            node=self.project
        )

        assert_true(
            self.user_settings.verify_oauth_access(
                external_account=self.external_account,
                node=self.project
            )
        )

    def test_verify_true_with_metadata(self):
        self.user_settings.grant_oauth_access(
            external_account=self.external_account,
#.........这里部分代码省略.........
开发者ID:GageGaskins,项目名称:osf.io,代码行数:103,代码来源:test_addons_oauth.py

示例4: TestNodeSettings

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_or_add_addon [as 别名]
class TestNodeSettings(OsfTestCase):

    ADDONS_UNDER_TEST = {
        MockOAuth2Provider.short_name: {
            'user_settings': MockUserSettings,
            'node_settings': MockNodeSettings,
        }
    }

    @classmethod
    def setUpClass(cls):
        super(TestNodeSettings, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestNodeSettings, cls).tearDownClass()

    def setUp(self):
        super(TestNodeSettings, self).setUp()
        self.project = ProjectFactory()
        self.user = self.project.creator
        self.node_settings = self.project.get_or_add_addon(
            MockNodeSettings.oauth_provider.short_name,
            auth=Auth(user=self.user)
        )
        self.user_settings = self.user.get_or_add_addon(
            MockUserSettings.oauth_provider.short_name
        )
        self.external_account = ExternalAccountFactory()
        self.user.external_accounts.append(self.external_account)
        self.user.save()

    def test_has_auth_false(self):
        assert_false(self.node_settings.has_auth)

    def test_has_auth_no_grant(self):
        self.node_settings.external_account = self.external_account
        self.node_settings.user_settings = self.user_settings

        assert_false(self.node_settings.has_auth)

    def test_has_auth(self):
        self.node_settings.set_auth(
            external_account=self.external_account,
            user=self.user
        )

        assert_true(self.node_settings.has_auth)

    def test_set_auth(self):
        self.node_settings.set_auth(
            external_account=self.external_account,
            user=self.user
        )

        assert_equal(
            self.node_settings.external_account,
            self.external_account
        )
        assert_equal(
            self.node_settings.user_settings,
            self.user_settings
        )
        assert_in(
            self.project._id,
            self.user_settings.oauth_grants.keys()
        )

    @mock.patch('tests.test_addons_oauth.MockNodeSettings.deauthorize')
    @mock.patch('framework.auth.core._get_current_user')
    def test_revoke_auth(self, mock_decorator, mock_deauth):
        mock_decorator.return_value = self.user
        self.node_settings.set_auth(
            external_account=self.external_account,
            user=self.user
        )
        self.user_settings.revoke_oauth_access(self.external_account, auth=Auth(self.user))
        self.user_settings.reload()

        mock_deauth.assert_called()
        assert_equal(
            self.user_settings.oauth_grants,
            {self.project._id: {}}
        )

    def test_clear_auth(self):
        self.node_settings.external_account = self.external_account
        self.node_settings.user_settings = self.user_settings

        self.node_settings.clear_auth()

        assert_is_none(self.node_settings.external_account)
        assert_is_none(self.node_settings.user_settings)
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:95,代码来源:test_addons_oauth.py

示例5: TestMigrateFiles

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_or_add_addon [as 别名]
class TestMigrateFiles(OsfTestCase):

    def setUp(self):
        super(TestMigrateFiles, self).setUp()
        self.project = ProjectFactory()
        self.user = self.project.creator
        self.auth_obj = Auth(user=self.user)
        self.project.delete_addon('osfstorage', auth=None, _force=True)
        for idx in range(5):
            content = 'i want {0} pizzas'.format(idx)
            self.project.add_file(
                auth=self.auth_obj,
                file_name='pizza.md',
                content=content,
                size=len(content),
                content_type='text/markdown',
            )

    def check_record(self, record):
        assert_true(record)
        assert_equal(len(record.versions), 5)
        for idx, version in enumerate(record.versions):
            assert_false(version.pending)
            expected = 'i want {0} pizzas'.format(idx)
            download_url = utils.get_waterbutler_download_url(idx + 1, version, record)
            resp = requests.get(download_url)
            assert_equal(expected, resp.content)

    def test_migrate(self):
        main(dry_run=False)
        node_settings = self.project.get_addon('osfstorage')
        assert_true(node_settings)
        record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
        self.check_record(record)
        # Test idempotence of migration
        main(dry_run=False)
        assert_equal(len(record.versions), 5)

    def test_migrate_incomplete(self):
        node_settings = self.project.get_or_add_addon('osfstorage', auth=None, log=False)
        record = model.OsfStorageFileRecord.get_or_create('pizza.md', node_settings)
        node_file = NodeFile.load(self.project.files_versions['pizza_md'][0])
        content, _ = self.project.read_file_object(node_file)
        file_pointer = StringIO(content)
        hash_str = scripts_settings.UPLOAD_PRIMARY_HASH(content).hexdigest()
        record.create_pending_version(node_file.uploader, hash_str)
        main(dry_run=False)

    def test_migrate_fork(self):
        fork = self.project.fork_node(auth=self.auth_obj)
        main(dry_run=False)
        node_settings = self.project.get_addon('osfstorage')
        record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
        self.check_record(record)
        fork_node_settings = fork.get_addon('osfstorage')
        fork_record = model.OsfStorageFileRecord.find_by_path('pizza.md', fork_node_settings)
        self.check_record(fork_record)

    def test_migrate_corrupt_fork_repo_deleted(self):
        fork = self.project.fork_node(auth=self.auth_obj)
        fork_repo = os.path.join(settings.UPLOADS_PATH, fork._id)
        shutil.rmtree(fork_repo)
        main(dry_run=False)
        node_settings = self.project.get_addon('osfstorage')
        record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
        self.check_record(record)
        fork_node_settings = fork.get_addon('osfstorage')
        fork_record = model.OsfStorageFileRecord.find_by_path('pizza.md', fork_node_settings)
        self.check_record(fork_record)

    def test_migrate_corrupt_fork_git_dir_deleted(self):
        fork = self.project.fork_node(auth=self.auth_obj)
        fork_git_dir = os.path.join(settings.UPLOADS_PATH, fork._id, '.git')
        shutil.rmtree(fork_git_dir)
        main(dry_run=False)
        node_settings = self.project.get_addon('osfstorage')
        record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
        self.check_record(record)
        fork_node_settings = fork.get_addon('osfstorage')
        fork_record = model.OsfStorageFileRecord.find_by_path('pizza.md', fork_node_settings)
        self.check_record(fork_record)
开发者ID:adlius,项目名称:osf.io,代码行数:83,代码来源:migrate_files.py


注:本文中的tests.factories.ProjectFactory.get_or_add_addon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。