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


Python ProjectFactory.add_contributor方法代码示例

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


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

示例1: test_migrate_project_contributed

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
    def test_migrate_project_contributed(self):
        user1 = UserFactory()

        fullname1 = 'hello world'
        email1 = '[email protected]'
        project1 = ProjectFactory(creator=user1)
        user2 = project1.add_unregistered_contributor(
            fullname=fullname1, email=email1, auth=Auth(user=user1)
        )
        project1.save()
        assert project1.is_contributor(user2) is True
        assert len(project1.contributors) is 2

        migrate_project_contributed(user2)
        assert project1.is_contributor(user2) is False
        assert len(project1.contributors) is 1

        user3 = UserFactory()
        project2 = ProjectFactory(creator=user1)
        project2.add_contributor(user3)
        project2.save()

        assert project2.is_contributor(user3) is True
        assert len(project2.contributors) is 2

        migrate_project_contributed(user3)
        assert project2.is_contributor(user3) is False
        assert len(project2.contributors) is 1
开发者ID:545zhou,项目名称:osf.io,代码行数:30,代码来源:test_migrate_presentation_service.py

示例2: test_do_migration

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
    def test_do_migration(self):
        user1 = UserFactory()

        fullname1 = 'Presentation Service'
        email1 = '[email protected]'
        project1 = ProjectFactory(creator=user1)
        user2 = project1.add_unregistered_contributor(
            fullname=fullname1, email=email1, auth=Auth(user=user1)
        )
        project1.save()

        user3 = UserFactory.build(username='[email protected]', fullname=fullname1)
        user3.save()
        project2 = ProjectFactory(creator=user1)
        project2.add_contributor(user3)
        project2.save()

        assert project1.is_contributor(user2) is True
        assert len(project1.contributors) is 2
        assert project2.is_contributor(user3) is True
        assert len(project2.contributors) is 2

        user_list = get_targets()
        do_migration(user_list)

        assert project2.is_contributor(user3) is False
        assert len(project2.contributors) is 1

        assert project1.is_contributor(user2) is False
        assert len(project1.contributors) is 1

        assert user2.is_disabled is True
        assert user3.is_disabled is True
开发者ID:545zhou,项目名称:osf.io,代码行数:35,代码来源:test_migrate_presentation_service.py

示例3: LogsTestCase

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

    def setUp(self):
        super(LogsTestCase, self).setUp()

        self.user = AuthUserFactory()

        self.action_set = NodeLog.actions
        self.node = ProjectFactory(is_public=False)
        for i in range(len(self.action_set)):
            self.node.add_log(
                self.action_set[i],
                {},
                Auth(self.node.creator),
                save=True
            )
        self.node.add_contributor(self.user, permissions=[osf_permissions.READ], auth=Auth(self.node.creator), log=False, save=True)
        self.node_log_url = '/{}nodes/{}/logs/'.format(API_BASE, self.node._id)
        self.url = '/{}logs/'.format(API_BASE)

        self.public_node = ProjectFactory(is_public=True)
        for i in range(len(self.action_set)):
            self.public_node.add_log(
                self.action_set[i],
                {},
                Auth(self.public_node.creator),
                save=True
            )

    def tearDown(self):
        NodeLog.remove()
        Node.remove()
开发者ID:mauromsl,项目名称:osf.io,代码行数:34,代码来源:test_views.py

示例4: LogsTestCase

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

    def setUp(self):
        super(LogsTestCase, self).setUp()

        self.user = AuthUserFactory()
        self.user_two = AuthUserFactory()

        self.action_set = NodeLog.actions
        self.node = ProjectFactory(is_public=False)

        self.node.add_contributor(self.user, permissions=[osf_permissions.READ], auth=Auth(self.node.creator), log=True, save=True)

        self.log = self.node.logs[0]
        self.log_add_contributor = self.node.logs[1]

        self.public_node = ProjectFactory(is_public=True)
        self.public_node.add_contributor(self.user, permissions=[osf_permissions.READ], auth=Auth(self.node.creator), log=True, save=True)

        self.public_log = self.public_node.logs[0]
        self.public_log_add_contributor = self.public_node.logs[1]

        self.node_log_url = '/{}nodes/{}/logs/'.format(API_BASE, self.node._id)
        self.url = '/{}logs/'.format(API_BASE)
        self.log_nodes_url = self.url + '{}/nodes/'.format(self.log._id)
        self.private_log_detail = self.url + '{}/'.format(self.log._id)
        self.log_public_nodes_url = self.url + '{}/nodes/'.format(self.public_log._id)
        self.public_log_detail = self.url + '{}/'.format(self.public_log._id)

    def tearDown(self):
        NodeLog.remove()
        Node.remove()
开发者ID:KAsante95,项目名称:osf.io,代码行数:34,代码来源:test_log_nodes_list.py

示例5: TestViewsAuth

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

    def setUp(self):

        super(TestViewsAuth, self).setUp()

        self.user = AuthUserFactory()
        self.consolidated_auth = Auth(user=self.user)
        self.auth = ('test', self.user.api_keys[0]._primary_key)
        self.project = ProjectFactory(creator=self.user)

        self.non_authenticator = AuthUserFactory()
        self.project.add_contributor(
            contributor=self.non_authenticator,
            auth=Auth(self.project.creator),
        )

        self.project.add_addon('figshare', auth=self.consolidated_auth)
        self.project.creator.add_addon('figshare')
        self.node_settings = self.project.get_addon('figshare')
        self.user_settings = self.project.creator.get_addon('figshare')
        self.node_settings.user_settings = self.user_settings
        self.node_settings.figshare_id = '436'
        self.node_settings.figshare_type = 'project'
        self.node_settings.save()

    @unittest.skip('finish this')
    def test_oauth_fail(self):
        url = '/api/v1/project/{0}/figshare/oauth/'.format(self.project._id)
        self.app.get(url, auth=self.user.auth)

    @unittest.skip('finish this')
    def test_oauth_bad_token(self):
        pass
开发者ID:GageGaskins,项目名称:osf.io,代码行数:36,代码来源:test_views.py

示例6: test_get_most_in_common_contributors

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
 def test_get_most_in_common_contributors(self):
     # project 1 (contrib 1, contrib 2, unreg_contrib 3)
     #  - component 1 (contrib 1)
     # project 2 - add should show contrib 1 first (2 links), contrib 2 second (1 link)
     contributor_1 = AuthUserFactory()
     contributor_2 = AuthUserFactory()
     self.project.add_contributor(contributor_1, auth=self.auth)
     self.project.add_contributor(contributor_2, auth=self.auth)
     # has one unregistered contributor
     self.project.add_unregistered_contributor(
         fullname=fake.name(),
         email=fake.email(),
         auth=self.auth,
     )
     self.project.save()
     component = NodeFactory(parent=self.project, creator=self.user)
     component.add_contributor(contributor_1, auth=self.auth)
     component.save()
     project_2 = ProjectFactory(creator=self.user)
     project_2.add_contributor(contributor_1, auth=self.auth)
     url = project_2.api_url_for('get_most_in_common_contributors')
     res = self.app.get(url, auth=self.user.auth)
     project_2.reload()
     res_contribs = res.json['contributors']
     assert_equal(len(res.json['contributors']), 2)
     assert_equal(contributor_1._id, res_contribs[0]['id'])
     assert_equal(res_contribs[0]['n_projects_in_common'], 2)
     assert_equal(contributor_2._id, res_contribs[1]['id'])
     assert_equal(res_contribs[1]['n_projects_in_common'], 1)
开发者ID:GageGaskins,项目名称:osf.io,代码行数:31,代码来源:test_contributors_views.py

示例7: test_get_children_only_returns_child_nodes_with_admin_permissions

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
    def test_get_children_only_returns_child_nodes_with_admin_permissions(self):
        user = UserFactory()
        admin_project = ProjectFactory()
        admin_project.add_contributor(
            user, auth=Auth(admin_project.creator), permissions=permissions.expand_permissions(permissions.ADMIN)
        )
        admin_project.save()

        admin_component = NodeFactory(parent=admin_project)
        admin_component.add_contributor(
            user, auth=Auth(admin_component.creator), permissions=permissions.expand_permissions(permissions.ADMIN)
        )
        admin_component.save()

        read_and_write = NodeFactory(parent=admin_project)
        read_and_write.add_contributor(
            user, auth=Auth(read_and_write.creator), permissions=permissions.expand_permissions(permissions.WRITE)
        )
        read_and_write.save()
        read_only = NodeFactory(parent=admin_project)
        read_only.add_contributor(
            user, auth=Auth(read_only.creator), permissions=permissions.expand_permissions(permissions.READ)
        )
        read_only.save()

        non_contributor = NodeFactory(parent=admin_project)
        components = _get_children(admin_project, Auth(user))
        assert_equal(len(components), 1)
开发者ID:kch8qx,项目名称:osf.io,代码行数:30,代码来源:test_serializers.py

示例8: test_migrate_contributors

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
    def test_migrate_contributors(self):
        creator = UserFactory(is_registered=True)
        project = ProjectFactory(creator=creator)
        auth = Auth(project.creator)

        contrib1 = UserFactory()
        project.add_contributor(contrib1, auth=auth)
        project.save()
        # sanity checks
        assert len(project.contributor_list) == 2

        nr_contrib = DeprecatedUnregUserFactory()
        project.contributor_list.append(nr_contrib)
        project.save()
        assert len(project.contributors) == 2
        assert len(project.contributor_list) == 3
        old_length = len(project.contributor_list)

        migrate_contributors(project)
        project.save()

        assert len(project.contributor_list) == old_length
        assert len(project.contributors) == old_length

        migrated_user = project.contributors[-1]
        assert migrated_user.fullname == nr_contrib['nr_name']
        assert migrated_user.is_registered is False

        # has an unclaimed record
        assert project._primary_key in migrated_user.unclaimed_records
        rec = migrated_user.get_unclaimed_record(project._primary_key)
        assert rec['name'] == nr_contrib['nr_name']
        assert rec['referrer_id'] == creator._primary_key
        assert rec['token']
        assert rec['email'] == nr_contrib['nr_email']
开发者ID:545zhou,项目名称:osf.io,代码行数:37,代码来源:migrate_unregistered.py

示例9: test_cant_see_make_private_button_if_not_admin

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
 def test_cant_see_make_private_button_if_not_admin(self):
     # User is a contributor on a project
     project = ProjectFactory(is_public=True)
     project.add_contributor(self.user, permissions=["read", "write"], save=True)
     # User goes to the project page
     res = self.app.get(project.url, auth=self.auth).maybe_follow()
     assert_not_in("Make Private", res)
开发者ID:Alpani,项目名称:osf.io,代码行数:9,代码来源:webtest_tests.py

示例10: test__initiate_embargo_adds_admins_on_child_nodes

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
    def test__initiate_embargo_adds_admins_on_child_nodes(self):
        project_admin = UserFactory()
        project_non_admin = UserFactory()
        child_admin = UserFactory()
        child_non_admin = UserFactory()
        grandchild_admin = UserFactory()

        project = ProjectFactory(creator=project_admin)
        project.add_contributor(project_non_admin, auth=Auth(project.creator), save=True)

        child = NodeFactory(creator=child_admin, parent=project)
        child.add_contributor(child_non_admin, auth=Auth(project.creator), save=True)

        grandchild = NodeFactory(creator=grandchild_admin, parent=child)  # noqa

        embargo = project._initiate_embargo(
            project.creator,
            self.valid_embargo_end_date,
            for_existing_registration=True
        )
        assert_in(project_admin._id, embargo.approval_state)
        assert_in(child_admin._id, embargo.approval_state)
        assert_in(grandchild_admin._id, embargo.approval_state)

        assert_not_in(project_non_admin._id, embargo.approval_state)
        assert_not_in(child_non_admin._id, embargo.approval_state)
开发者ID:mchelen,项目名称:osf.io,代码行数:28,代码来源:test_embargoes.py

示例11: create_fake_project

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
def create_fake_project(creator, n_users, privacy, n_components, name, n_tags, presentation_name, is_registration):
    auth = Auth(user=creator)
    project_title = name if name else fake.science_sentence()
    if not is_registration:
        project = ProjectFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
    else:
        project = RegistrationFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
    project.set_privacy(privacy)
    for _ in range(n_users):
        contrib = create_fake_user()
        project.add_contributor(contrib, auth=auth)
    if isinstance(n_components, int):
        for _ in range(n_components):
            NodeFactory(project=project, title=fake.science_sentence(), description=fake.science_paragraph(),
                        creator=creator)
    elif isinstance(n_components, list):
        render_generations_from_node_structure_list(project, creator, n_components)
    for _ in range(n_tags):
        project.add_tag(fake.science_word(), auth=auth)
    if presentation_name is not None:
        project.add_tag(presentation_name, auth=auth)
        project.add_tag('poster', auth=auth)

    project.save()
    logger.info('Created project: {0}'.format(project.title))
    return project
开发者ID:545zhou,项目名称:osf.io,代码行数:28,代码来源:create_fakes.py

示例12: TestMustBeContributorDecorator

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

    def setUp(self):
        super(TestMustBeContributorDecorator, self).setUp()
        self.contrib = AuthUserFactory()
        self.project = ProjectFactory()
        self.project.add_contributor(self.contrib, auth=Auth(self.project.creator))
        self.project.save()

    def test_must_be_contributor_when_user_is_contributor(self):
        result = view_that_needs_contributor(
            pid=self.project._primary_key,
            api_key=self.contrib.auth[1],
            api_node=self.project,
            user=self.contrib)
        assert_equal(result, self.project)

    def test_must_be_contributor_when_user_is_not_contributor_raises_error(self):
        non_contributor = AuthUserFactory()
        with assert_raises(HTTPError):
            view_that_needs_contributor(
                pid=self.project._primary_key,
                api_key=non_contributor.auth[1],
                api_node=non_contributor.auth[1],
                user=non_contributor
            )

    def test_must_be_contributor_no_user(self):
        res = view_that_needs_contributor(
            pid=self.project._primary_key,
            user=None,
            api_key='123',
            api_node='abc',
        )
        assert_is_redirect(res)
        redirect_url = res.headers['Location']
        assert_equal(redirect_url, '/login/?next=/')

    def test_must_be_contributor_parent_admin(self):
        user = UserFactory()
        node = NodeFactory(parent=self.project, creator=user)
        res = view_that_needs_contributor(
            pid=self.project._id,
            nid=node._id,
            user=self.project.creator,
        )
        assert_equal(res, node)

    def test_must_be_contributor_parent_write(self):
        user = UserFactory()
        node = NodeFactory(parent=self.project, creator=user)
        self.project.set_permissions(self.project.creator, ['read', 'write'])
        self.project.save()
        with assert_raises(HTTPError) as exc_info:
            view_that_needs_contributor(
                pid=self.project._id,
                nid=node._id,
                user=self.project.creator,
            )
        assert_equal(exc_info.exception.code, 403)
开发者ID:erinmayhood,项目名称:osf.io,代码行数:62,代码来源:test_auth.py

示例13: test_sees_projects_in_her_dashboard

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
 def test_sees_projects_in_her_dashboard(self):
     # the user already has a project
     project = ProjectFactory(creator=self.user)
     project.add_contributor(self.user)
     project.save()
     res = self.app.get('/myprojects/', auth=self.user.auth)
     assert_in('Projects', res)  # Projects heading
开发者ID:baylee-d,项目名称:osf.io,代码行数:9,代码来源:webtest_tests.py

示例14: DraftRegistrationTestCase

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
class DraftRegistrationTestCase(ApiTestCase):
    def setUp(self):
        super(DraftRegistrationTestCase, self).setUp()
        self.user = AuthUserFactory()
        self.read_only_user = AuthUserFactory()
        self.read_write_user = AuthUserFactory()
        self.non_contributor = AuthUserFactory()

        self.public_project = ProjectFactory(is_public=True, creator=self.user)
        self.public_project.add_contributor(self.read_only_user, permissions=[permissions.READ])
        self.public_project.add_contributor(self.read_write_user, permissions=[permissions.WRITE])
        self.public_project.save()

    def prereg_metadata(self, draft):
        test_metadata = {}
        json_schema = create_jsonschema_from_metaschema(draft.registration_schema.schema)

        for key, value in json_schema["properties"].iteritems():
            response = "Test response"
            if value["properties"]["value"].get("enum"):
                response = value["properties"]["value"]["enum"][0]

            if value["properties"]["value"].get("properties"):
                response = {"question": {"value": "Test Response"}}

            test_metadata[key] = {"value": response}
        return test_metadata
开发者ID:ccfair,项目名称:osf.io,代码行数:29,代码来源:test_node_draft_registration_list.py

示例15: test_node_citation_view

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_contributor [as 别名]
 def test_node_citation_view(self):
     node = ProjectFactory()
     user = AuthUserFactory()
     node.add_contributor(user)
     node.save()
     response = self.app.get("/api/v1" + "/project/" + node._id + "/citation/", auto_follow=True, auth=user.auth)
     assert_true(response.json)
开发者ID:545zhou,项目名称:osf.io,代码行数:9,代码来源:test_citations.py


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