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


Python factories.NodeFactory类代码示例

本文整理汇总了Python中osf_tests.factories.NodeFactory的典型用法代码示例。如果您正苦于以下问题:Python NodeFactory类的具体用法?Python NodeFactory怎么用?Python NodeFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: node_with_abstract

 def node_with_abstract(self, user):
     node_with_abstract = NodeFactory(title='Sambolera', creator=user, is_public=True)
     node_with_abstract.set_description(
         'Sambolera by Khadja Nin',
         auth=Auth(user),
         save=True)
     return node_with_abstract
开发者ID:icereval,项目名称:osf.io,代码行数:7,代码来源:test_views.py

示例2: test__initiate_embargo_adds_admins_on_child_nodes

    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(child.creator), save=True)

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

        registration = RegistrationFactory(project=project)

        embargo = registration._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:leb2dg,项目名称:osf.io,代码行数:28,代码来源:test_embargoes.py

示例3: test_fork_reverts_to_using_user_storage_default

    def test_fork_reverts_to_using_user_storage_default(self):
        user = UserFactory()
        user2 = UserFactory()
        us = RegionFactory()
        canada = RegionFactory()

        user_settings = user.get_addon('osfstorage')
        user_settings.default_region = us
        user_settings.save()
        user2_settings = user2.get_addon('osfstorage')
        user2_settings.default_region = canada
        user2_settings.save()

        project = ProjectFactory(creator=user, is_public=True)
        child = NodeFactory(parent=project, creator=user, is_public=True)
        child_settings = child.get_addon('osfstorage')
        child_settings.region_id = canada.id
        child_settings.save()

        fork = project.fork_node(Auth(user))
        child_fork = models.Node.objects.get_children(fork).first()
        assert fork.get_addon('osfstorage').region_id == us.id
        assert fork.get_addon('osfstorage').user_settings == user.get_addon('osfstorage')
        assert child_fork.get_addon('osfstorage').region_id == us.id

        fork = project.fork_node(Auth(user2))
        child_fork = models.Node.objects.get_children(fork).first()
        assert fork.get_addon('osfstorage').region_id == canada.id
        assert fork.get_addon('osfstorage').user_settings == user2.get_addon('osfstorage')
        assert child_fork.get_addon('osfstorage').region_id == canada.id
开发者ID:,项目名称:,代码行数:30,代码来源:

示例4: test_node_serializer

    def test_node_serializer(self, user):

    #   test_node_serialization
        parent = ProjectFactory(creator=user)
        node = NodeFactory(creator=user, parent=parent)
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(node, context={'request': req}).data
        data = result['data']
        assert data['id'] == node._id
        assert data['type'] == 'nodes'

        # Attributes
        attributes = data['attributes']
        assert attributes['title'] == node.title
        assert attributes['description'] == node.description
        assert attributes['public'] == node.is_public
        assert attributes['tags'] == [str(each.name) for each in node.tags.all()]
        assert attributes['current_user_can_comment'] == False
        assert attributes['category'] == node.category
        assert attributes['registration'] == node.is_registration
        assert attributes['fork'] == node.is_fork
        assert attributes['collection'] == node.is_collection

        # Relationships
        relationships = data['relationships']
        assert 'children' in relationships
        assert 'contributors' in relationships
        assert 'files' in relationships
        assert 'parent' in relationships
        assert 'affiliated_institutions' in relationships
        assert 'registrations' in relationships
        # Not a fork, so forked_from is removed entirely
        assert 'forked_from' not in relationships
        parent_link = relationships['parent']['links']['related']['href']
        assert urlparse(parent_link).path == '/{}nodes/{}/'.format(API_BASE, parent._id)

    #   test_fork_serialization
        node = NodeFactory(creator=user)
        fork = node.fork_node(auth=Auth(user))
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(fork, context={'request': req}).data
        data = result['data']

        # Relationships
        relationships = data['relationships']
        forked_from = relationships['forked_from']['links']['related']['href']
        assert urlparse(forked_from).path == '/{}nodes/{}/'.format(API_BASE, node._id)

    #   test_template_serialization
        node = NodeFactory(creator=user)
        fork = node.use_as_template(auth=Auth(user))
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(fork, context={'request': req}).data
        data = result['data']

        # Relationships
        relationships = data['relationships']
        templated_from = relationships['template_node']['links']['related']['href']
        assert urlparse(templated_from).path == '/{}nodes/{}/'.format(API_BASE, node._id)
开发者ID:adlius,项目名称:osf.io,代码行数:59,代码来源:test_serializers.py

示例5: test_is_current_with_single_version

 def test_is_current_with_single_version(self):
     node = NodeFactory()
     page = NodeWikiPage(page_name='foo', node=node)
     page.save()
     node.wiki_pages_current['foo'] = page._id
     node.wiki_pages_versions['foo'] = [page._id]
     node.save()
     assert page.is_current is True
开发者ID:geeksnglitter,项目名称:osf.io,代码行数:8,代码来源:test_models.py

示例6: test_collect_components_deleted

 def test_collect_components_deleted(self):
     node = NodeFactory(creator=self.project.creator, parent=self.project)
     node.is_deleted = True
     collector = rubeus.NodeFileCollector(
         self.project, Auth(user=UserFactory())
     )
     nodes = collector._collect_components(self.project, visited=[])
     assert_equal(len(nodes), 0)
开发者ID:adlius,项目名称:osf.io,代码行数:8,代码来源:test_rubeus.py

示例7: child_node_two

 def child_node_two(self, user, parent_project, institution):
     child_node_two = NodeFactory(
         parent=parent_project,
         creator=user,
         is_public=True)
     child_node_two.affiliated_institutions.add(institution)
     child_node_two.save()
     return child_node_two
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:8,代码来源:test_institution_nodes_list.py

示例8: test_get_nodes_deleted_component

 def test_get_nodes_deleted_component(self):
     node = NodeFactory(creator=self.project.creator, parent=self.project)
     node.is_deleted = True
     collector = rubeus.NodeFileCollector(
         self.project, Auth(user=UserFactory())
     )
     nodes = collector._get_nodes(self.project)
     assert_equal(len(nodes['children']), 0)
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:8,代码来源:test_rubeus.py

示例9: great_grandchild_node_two

 def great_grandchild_node_two(
         self, user, grandchild_node_two,
         institution
 ):
     great_grandchild_node_two = NodeFactory(
         parent=grandchild_node_two, creator=user, is_public=True)
     great_grandchild_node_two.affiliated_institutions.add(institution)
     great_grandchild_node_two.save()
     return great_grandchild_node_two
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:9,代码来源:test_institution_nodes_list.py

示例10: test_serialize_node_search_returns_only_visible_contributors

    def test_serialize_node_search_returns_only_visible_contributors(self):
        node = NodeFactory()
        non_visible_contributor = UserFactory()
        node.add_contributor(non_visible_contributor, visible=False)
        serialized_node = _serialize_node_search(node)

        assert_equal(serialized_node['firstAuthor'], node.visible_contributors[0].family_name)
        assert_equal(len(node.visible_contributors), 1)
        assert_false(serialized_node['etal'])
开发者ID:leb2dg,项目名称:osf.io,代码行数:9,代码来源:test_serializers.py

示例11: TestValidProject

class TestValidProject(OsfTestCase):

    def setUp(self):
        super(TestValidProject, self).setUp()
        self.project = ProjectFactory()
        self.node = NodeFactory()
        self.auth = Auth(user=self.project.creator)

    def test_populates_kwargs_node(self):
        res = valid_project_helper(pid=self.project._id)
        assert_equal(res['node'], self.project)
        assert_is_none(res['parent'])

    def test_populates_kwargs_node_and_parent(self):
        res = valid_project_helper(pid=self.project._id, nid=self.node._id)
        assert_equal(res['parent'], self.project)
        assert_equal(res['node'], self.node)

    def test_project_not_found(self):
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid='fakepid')
        assert_equal(exc_info.exception.code, 404)

    def test_project_deleted(self):
        self.project.is_deleted = True
        self.project.save()
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid=self.project._id)
        assert_equal(exc_info.exception.code, 410)

    def test_node_not_found(self):
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid=self.project._id, nid='fakenid')
        assert_equal(exc_info.exception.code, 404)

    def test_node_deleted(self):
        self.node.is_deleted = True
        self.node.save()
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid=self.project._id, nid=self.node._id)
        assert_equal(exc_info.exception.code, 410)

    def test_valid_project_as_factory_allow_retractions_is_retracted(self):
        registration = RegistrationFactory(project=self.project)
        registration.retraction = RetractionFactory()
        registration.retraction.state = Sanction.UNAPPROVED
        registration.retraction.save()
        res = as_factory_allow_retractions(pid=registration._id)
        assert_equal(res['node'], registration)

    def test_collection_guid_not_found(self):
        collection = CollectionFactory()
        collection.collect_object(self.project, self.auth.user)
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid=collection._id, nid=collection._id)
        assert_equal(exc_info.exception.code, 404)
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:56,代码来源:test_project_decorators.py

示例12: test_email_not_sent_to_parent_admins_on_submit

 def test_email_not_sent_to_parent_admins_on_submit(self, mock_mail, app, project, noncontrib, url, create_payload, second_admin):
     component = NodeFactory(parent=project, creator=second_admin)
     component.is_public = True
     project.save()
     url = '/{}nodes/{}/requests/'.format(API_BASE, component._id)
     res = app.post_json_api(url, create_payload, auth=noncontrib.auth)
     assert res.status_code == 201
     assert component.admin_contributors.count() == 2
     assert component.contributors.count() == 1
     assert mock_mail.call_count == 1
开发者ID:icereval,项目名称:osf.io,代码行数:10,代码来源:test_request_list_create.py

示例13: test_a_public_component_from_home_page

 def test_a_public_component_from_home_page(self):
     component = NodeFactory(title='Foobar Component', is_public=True)
     # Searches a part of the name
     res = self.app.get('/').maybe_follow()
     component.reload()
     form = res.forms['searchBar']
     form['q'] = 'Foobar'
     res = form.submit().maybe_follow()
     # A link to the component is shown as a result
     assert_in('Foobar Component', res)
开发者ID:icereval,项目名称:osf.io,代码行数:10,代码来源:test_webtests.py

示例14: test_user_is_admin

 def test_user_is_admin(self):
     node = NodeFactory(creator=self.user)
     res = self.app.post_json_api(
         self.institution_nodes_url,
         self.create_payload(node._id),
         auth=self.user.auth
     )
     assert_equal(res.status_code, 201)
     node.reload()
     assert_in(self.institution, node.affiliated_institutions.all())
开发者ID:adlius,项目名称:osf.io,代码行数:10,代码来源:test_institution_relationship_nodes.py

示例15: test_affiliated_component_with_affiliated_parent_not_returned

 def test_affiliated_component_with_affiliated_parent_not_returned(self, app, user, institution, public_node, institution_node_url):
     # version < 2.2
     component = NodeFactory(parent=public_node, is_public=True)
     component.affiliated_institutions.add(institution)
     component.save()
     res = app.get(institution_node_url, auth=user.auth)
     affiliated_node_ids = [node['id'] for node in res.json['data']]
     assert res.status_code == 200
     assert public_node._id in affiliated_node_ids
     assert component._id not in affiliated_node_ids
开发者ID:adlius,项目名称:osf.io,代码行数:10,代码来源:test_institution_nodes_list.py


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