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


Python ProjectFactory.save方法代码示例

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


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

示例1: TestClaimingAsARegisteredUser

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [as 别名]
class TestClaimingAsARegisteredUser(OsfTestCase):
    def setUp(self):
        super(TestClaimingAsARegisteredUser, self).setUp()
        self.referrer = AuthUserFactory()
        self.project = ProjectFactory(creator=self.referrer, is_public=True)
        name, email = fake.name(), fake.email()
        self.user = self.project.add_unregistered_contributor(fullname=name, email=email, auth=Auth(user=self.referrer))
        self.project.save()

    def test_claim_user_registered_with_correct_password(self):
        reg_user = AuthUserFactory()  # NOTE: AuthUserFactory sets password as 'password'
        url = self.user.get_claim_url(self.project._primary_key)
        # Follow to password re-enter page
        res = self.app.get(url, auth=reg_user.auth).follow(auth=reg_user.auth)

        # verify that the "Claim Account" form is returned
        assert_in("Claim Contributor", res.body)

        form = res.forms["claimContributorForm"]
        form["password"] = "password"
        res = form.submit(auth=reg_user.auth).follow(auth=reg_user.auth)

        self.project.reload()
        self.user.reload()
        # user is now a contributor to the project
        assert_in(reg_user._primary_key, self.project.contributors)

        # the unregistered user (self.user) is removed as a contributor, and their
        assert_not_in(self.user._primary_key, self.project.contributors)

        # unclaimed record for the project has been deleted
        assert_not_in(self.project._primary_key, self.user.unclaimed_records)
开发者ID:Alpani,项目名称:osf.io,代码行数:34,代码来源:webtest_tests.py

示例2: create_fake_project

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [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

示例3: test_get_children_only_returns_child_nodes_with_admin_permissions

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [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

示例4: test_oauth_callback_with_node

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [as 别名]
    def test_oauth_callback_with_node(self, mock_get_token, mock_github_user):
        mock_get_token.return_value = {
            "access_token": "testing access token",
            "token_type": "testing token type",
            "scope": ["repo"]
        }
        user = mock.Mock()
        user.id = "testing user id"
        user.login = "testing user"
        mock_github_user.return_value = user

        project = ProjectFactory(creator=self.user)
        project.add_addon('github', auth=Auth(user=self.user))
        project.save()

        url = api_url_for('github_oauth_callback', uid=self.user._id, nid=project._id)
        res = self.app.get(url, {"code": "12345"}, auth=self.user.auth)
        self.user_settings.reload()

        node_settings = project.get_addon('github')
        node_settings.reload()

        assert_true(res.status_code, 302)
        assert_not_in("/settings/addons/", res.location)
        assert_in("/settings", res.location)
        assert_true(self.user_settings.oauth_settings)
        assert_equal(self.user_settings.oauth_access_token, "testing access token")
        assert_equal(self.user_settings.oauth_token_type, "testing token type")
        assert_equal(self.user_settings.github_user_name, "testing user")
        assert_equal(self.user_settings.oauth_settings.github_user_id, "testing user id")
        assert_equal(node_settings.user_settings, self.user_settings)
开发者ID:lbanner,项目名称:osf.io,代码行数:33,代码来源:test_views.py

示例5: TestCheckAuth

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

    def setUp(self):
        super(TestCheckAuth, self).setUp()
        self.user = AuthUserFactory()
        self.node = ProjectFactory(creator=self.user)

    def test_has_permission(self):
        res = views.check_access(self.node, self.user, 'upload')
        assert_true(res)

    def test_not_has_permission_read_public(self):
        self.node.is_public = True
        self.node.save()
        res = views.check_access(self.node, None, 'download')

    def test_not_has_permission_read_has_link(self):
        link = new_private_link('red-special', self.user, [self.node], anonymous=False)
        res = views.check_access(self.node, None, 'download', key=link.key)

    def test_not_has_permission_logged_in(self):
        user2 = AuthUserFactory()
        with assert_raises(HTTPError) as exc_info:
            views.check_access(self.node, user2, 'download')
        assert_equal(exc_info.exception.code, 403)

    def test_not_has_permission_not_logged_in(self):
        with assert_raises(HTTPError) as exc_info:
            views.check_access(self.node, None, 'download')
        assert_equal(exc_info.exception.code, 401)
开发者ID:ticklemepierce,项目名称:osf.io,代码行数:32,代码来源:test_addons.py

示例6: TestMustBeContributorDecorator

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [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

示例7: DraftRegistrationTestCase

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [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

示例8: test_migrate_project_contributed

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [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

示例9: test_do_migration

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [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

示例10: TestSearchExceptions

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [as 别名]
class TestSearchExceptions(OsfTestCase):
    """
    Verify that the correct exception is thrown when the connection is lost
    """

    @classmethod
    def setUpClass(cls):
        logging.getLogger('website.project.model').setLevel(logging.CRITICAL)
        super(TestSearchExceptions, cls).setUpClass()
        if settings.SEARCH_ENGINE == 'elastic':
            cls._es = search.search_engine.es
            search.search_engine.es = None

    @classmethod
    def tearDownClass(cls):
        super(TestSearchExceptions, cls).tearDownClass()
        if settings.SEARCH_ENGINE == 'elastic':
            search.search_engine.es = cls._es

    def test_connection_error(self):
        # Ensures that saving projects/users doesn't break as a result of connection errors
        self.user = UserFactory(usename='Doug Bogie')
        self.project = ProjectFactory(
            title="Tom Sawyer",
            creator=self.user,
            is_public=True,
        )
        self.user.save()
        self.project.save()
开发者ID:PatrickEGorman,项目名称:osf.io,代码行数:31,代码来源:test_elastic.py

示例11: TestSearchExceptions

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [as 别名]
class TestSearchExceptions(OsfTestCase):
    """
    Verify that the correct exception is thrown when the connection is lost
    """

    @classmethod
    def setUpClass(cls):
        super(TestSearchExceptions, cls).setUpClass()
        if settings.SEARCH_ENGINE == "elastic":
            cls._es = search.search_engine.es
            search.search_engine.es = None

    @classmethod
    def tearDownClass(cls):
        super(TestSearchExceptions, cls).tearDownClass()
        if settings.SEARCH_ENGINE == "elastic":
            search.search_engine.es = cls._es

    def test_connection_error(self):
        """
        Ensures that saving projects/users doesn't break as a result of connection errors
        """
        self.user = UserFactory(usename="Doug Bogie")
        self.project = ProjectFactory(title="Tom Sawyer", creator=self.user, is_public=True)
        self.user.save()
        self.project.save()
开发者ID:erinmayhood,项目名称:osf.io,代码行数:28,代码来源:test_elastic.py

示例12: test_sees_projects_in_her_dashboard

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [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

示例13: test_node_citation_view

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [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

示例14: test_read_permission_contributor_can_comment

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [as 别名]
    def test_read_permission_contributor_can_comment(self):
        project = ProjectFactory()
        user = UserFactory()
        project.set_privacy('private')
        project.add_contributor(user, permissions=[permissions.READ])
        project.save()

        assert_true(project.can_comment(Auth(user=user)))
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:10,代码来源:test_comments.py

示例15: test_retract_public_non_registration_raises_NodeStateError

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import save [as 别名]
    def test_retract_public_non_registration_raises_NodeStateError(self):
        project = ProjectFactory(is_public=True, creator=self.user)
        project.save()
        with assert_raises(NodeStateError):
            project.retract_registration(self.user, self.valid_justification)

        project.reload()
        assert_is_none(project.retraction)
开发者ID:baylee-d,项目名称:osf.io,代码行数:10,代码来源:test_retractions.py


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