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


Python utils.make_drf_request函数代码示例

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


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

示例1: test_node_serialization

    def test_node_serialization(self):
        parent = ProjectFactory(creator=self.user)
        node = NodeFactory(creator=self.user, parent=parent)
        req = make_drf_request()
        result = NodeSerializer(node, context={'request': req}).data
        data = result['data']
        assert_equal(data['id'], node._id)
        assert_equal(data['type'], 'nodes')

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

        # Relationships
        relationships = data['relationships']
        assert_in('children', relationships)
        assert_in('contributors', relationships)
        assert_in('files', relationships)
        assert_in('parent', relationships)
        assert_in('primary_institution', relationships)
        parent_link = relationships['parent']['links']['related']['href']
        assert_equal(
            urlparse(parent_link).path,
            '/{}nodes/{}/'.format(API_BASE, parent._id)
        )
        assert_in('registrations', relationships)
        # Not a fork, so forked_from is removed entirely
        assert_not_in('forked_from', relationships)
开发者ID:545zhou,项目名称:osf.io,代码行数:35,代码来源:test_serializers.py

示例2: test_field_with_non_attribute

 def test_field_with_non_attribute(self):
     req = make_drf_request()
     project = factories.ProjectFactory()
     node = factories.NodeFactory(parent=project)
     data = self.BasicNodeSerializer(node, context={'request': req}).data['data']
     field = data['relationships']['not_attribute_on_target']['links']
     assert_in('/v2/nodes/{}/children/'.format('12345'), field['related']['href'])
开发者ID:545zhou,项目名称:osf.io,代码行数:7,代码来源:test_serializers.py

示例3: test_node_serialization

    def test_node_serialization(self):
        parent = ProjectFactory(creator=self.user)
        node = NodeFactory(creator=self.user, parent=parent)
        req = make_drf_request()
        result = NodeSerializer(node, context={"request": req}).data
        data = result["data"]
        assert_equal(data["id"], node._id)
        assert_equal(data["type"], "nodes")

        # Attributes
        attributes = data["attributes"]
        assert_equal(attributes["title"], node.title)
        assert_equal(attributes["description"], node.description)
        assert_equal(attributes["public"], node.is_public)
        assert_equal(attributes["tags"], [str(each) for each in node.tags])
        assert_equal(attributes["category"], node.category)
        assert_equal(attributes["registration"], node.is_registration)
        assert_equal(attributes["fork"], node.is_fork)
        assert_equal(attributes["collection"], node.is_folder)

        # Relationships
        relationships = data["relationships"]
        assert_in("children", relationships)
        assert_in("contributors", relationships)
        assert_in("files", relationships)
        assert_in("parent", relationships)
        parent_link = relationships["parent"]["links"]["related"]["href"]
        assert_equal(urlparse(parent_link).path, "/{}nodes/{}/".format(API_BASE, parent._id))
        assert_in("registrations", relationships)
        # Not a fork, so forked_from is removed entirely
        assert_not_in("forked_from", relationships)
开发者ID:Alpani,项目名称:osf.io,代码行数:31,代码来源:test_serializers.py

示例4: test_field_with_two_kwargs

 def test_field_with_two_kwargs(self):
     req = make_drf_request()
     project = factories.ProjectFactory()
     node = factories.NodeFactory(parent=project)
     data = self.BasicNodeSerializer(node, context={'request': req}).data['data']
     field = data['relationships']['two_url_kwargs']['links']
     assert_in('/v2/nodes/{}/node_links/{}/'.format(node._id, node._id), field['related']['href'])
开发者ID:545zhou,项目名称:osf.io,代码行数:7,代码来源:test_serializers.py

示例5: test_serialization

    def test_serialization(self):
        user = UserFactory()
        req = make_drf_request()
        reg = RegistrationFactory(creator=user)
        result = RegistrationSerializer(reg, context={'request': req}).data
        data = result['data']
        assert_equal(data['id'], reg._id)
        assert_equal(data['type'], 'registrations')

        # Attributes
        attributes = data['attributes']
        assert_datetime_equal(
            parse_date(attributes['date_registered']),
            reg.registered_date
        )
        assert_equal(attributes['retracted'], reg.is_retracted)

        # Relationships
        relationships = data['relationships']
        assert_in('registered_by', relationships)
        registered_by = relationships['registered_by']['links']['related']['href']
        assert_equal(
            urlparse(registered_by).path,
            '/{}users/{}/'.format(API_BASE, user._id)
        )
        assert_in('registered_from', relationships)
        registered_from = relationships['registered_from']['links']['related']['href']
        assert_equal(
            urlparse(registered_from).path,
            '/{}nodes/{}/'.format(API_BASE, reg.registered_from._id)
        )
开发者ID:jeffsteinmetz,项目名称:osf.io,代码行数:31,代码来源:test_serializers.py

示例6: test_null_links_are_omitted

    def test_null_links_are_omitted(self):
        req = make_drf_request()
        rep = FakeSerializer(FakeModel, context={'request': req}).data['data']

        assert_not_in('null_field', rep['links'])
        assert_in('valued_field', rep['links'])
        assert_not_in('null_link_field', rep['relationships'])
        assert_in('valued_link_field', rep['relationships'])
开发者ID:545zhou,项目名称:osf.io,代码行数:8,代码来源:test_serializers.py

示例7: test_self_and_related_fields

    def test_self_and_related_fields(self):
        req = make_drf_request()
        project = factories.ProjectFactory()
        node = factories.NodeFactory(parent=project)
        data = self.BasicNodeSerializer(node, context={'request': req}).data['data']

        relationship_field = data['relationships']['self_and_related_field']['links']
        assert_in('/v2/nodes/{}/contributors/'.format(node._id), relationship_field['self']['href'])
        assert_in('/v2/nodes/{}/'.format(node._id), relationship_field['related']['href'])
开发者ID:545zhou,项目名称:osf.io,代码行数:9,代码来源:test_serializers.py

示例8: test_serializing_meta

    def test_serializing_meta(self):
        req = make_drf_request()
        project = factories.ProjectFactory()
        node = factories.NodeFactory(parent=project)
        data = self.BasicNodeSerializer(node, context={'request': req}).data['data']

        meta = data['relationships']['parent_with_meta']['links']['related']['meta']
        assert_not_in('count', meta)
        assert_in('extra', meta)
        assert_equal(meta['extra'], 'foo')
开发者ID:545zhou,项目名称:osf.io,代码行数:10,代码来源:test_serializers.py

示例9: test_fork_serialization

    def test_fork_serialization(self):
        node = NodeFactory(creator=self.user)
        fork = node.fork_node(auth=Auth(user=node.creator))
        result = NodeSerializer(fork, context={"request": make_drf_request()}).data
        data = result["data"]

        # Relationships
        relationships = data["relationships"]
        forked_from = relationships["forked_from"]["links"]["related"]["href"]
        assert_equal(urlparse(forked_from).path, "/{}nodes/{}/".format(API_BASE, node._id))
开发者ID:Alpani,项目名称:osf.io,代码行数:10,代码来源:test_serializers.py

示例10: test_fork_serialization

    def test_fork_serialization(self):
        node = NodeFactory(creator=self.user)
        fork = node.fork_node(auth=Auth(user=node.creator))
        result = NodeSerializer(fork, context={'request': make_drf_request()}).data
        data = result['data']

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

示例11: test_field_with_callable_related_attrs

    def test_field_with_callable_related_attrs(self):
        req = make_drf_request()
        project = factories.ProjectFactory()
        node = factories.NodeFactory(parent=project)
        data = self.BasicNodeSerializer(node, context={'request': req}).data['data']
        assert_not_in('registered_from', data['relationships'])

        registration = factories.RegistrationFactory(project=node)
        data = self.BasicNodeSerializer(registration, context={'request': req}).data['data']
        field = data['relationships']['registered_from']['links']
        assert_in('/v2/nodes/{}/'.format(node._id), field['related']['href'])

        registration_registration = factories.RegistrationFactory(project=registration)
        data = self.BasicNodeSerializer(registration_registration, context={'request': req}).data['data']
        field = data['relationships']['registered_from']['links']
        assert_in('/v2/registrations/{}/'.format(registration._id), field['related']['href'])
开发者ID:atelic,项目名称:osf.io,代码行数:16,代码来源:test_serializers.py

示例12: test_serialization

    def test_serialization(self):
        user = UserFactory()
        req = make_drf_request()
        reg = RegistrationFactory(creator=user)
        result = RegistrationSerializer(reg, context={'request': req}).data
        data = result['data']
        assert_equal(data['id'], reg._id)
        assert_equal(data['type'], 'registrations')
        should_not_relate_to_registrations = [
            'registered_from',
            'registered_by',
            'registration_schema'
        ]

        # Attributes
        attributes = data['attributes']
        assert_datetime_equal(
            parse_date(attributes['date_registered']),
            reg.registered_date
        )
        assert_equal(attributes['withdrawn'], reg.is_retracted)

        # Relationships
        relationships = data['relationships']
        relationship_urls = {}
        for relationship in relationships:
            relationship_urls[relationship]=relationships[relationship]['links']['related']['href']
        assert_in('registered_by', relationships)
        registered_by = relationships['registered_by']['links']['related']['href']
        assert_equal(
            urlparse(registered_by).path,
            '/{}users/{}/'.format(API_BASE, user._id)
        )
        assert_in('registered_from', relationships)
        registered_from = relationships['registered_from']['links']['related']['href']
        assert_equal(
            urlparse(registered_from).path,
            '/{}nodes/{}/'.format(API_BASE, reg.registered_from._id)
        )
        for relationship in relationship_urls:
            if relationship in should_not_relate_to_registrations:
                assert_not_in('/{}registrations/'.format(API_BASE), relationship_urls[relationship])
            else:
                assert_in('/{}registrations/'.format(API_BASE), relationship_urls[relationship],
                          'For key {}'.format(relationship))
开发者ID:caspinelli,项目名称:osf.io,代码行数:45,代码来源:test_serializers.py

示例13: test_serialization

    def test_serialization(self):
        user = UserFactory()
        req = make_drf_request()
        reg = RegistrationFactory(creator=user)
        result = RegistrationSerializer(reg, context={"request": req}).data
        data = result["data"]
        assert_equal(data["id"], reg._id)
        assert_equal(data["type"], "registrations")

        # Attributes
        attributes = data["attributes"]
        assert_datetime_equal(parse_date(attributes["date_registered"]), reg.registered_date)
        assert_equal(attributes["retracted"], reg.is_retracted)

        # Relationships
        relationships = data["relationships"]
        assert_in("registered_by", relationships)
        registered_by = relationships["registered_by"]["links"]["related"]["href"]
        assert_equal(urlparse(registered_by).path, "/{}users/{}/".format(API_BASE, user._id))
        assert_in("registered_from", relationships)
        registered_from = relationships["registered_from"]["links"]["related"]["href"]
        assert_equal(urlparse(registered_from).path, "/{}nodes/{}/".format(API_BASE, reg.registered_from._id))
开发者ID:Alpani,项目名称:osf.io,代码行数:22,代码来源:test_serializers.py

示例14: test_collection_serialization

    def test_collection_serialization(self):
        collection = FolderFactory(creator=self.user)
        req = make_drf_request()
        result = CollectionSerializer(collection, context={'request': req}).data
        data = result['data']
        assert_equal(data['id'], collection._id)
        assert_equal(data['type'], 'collections')

        # Attributes
        attributes = data['attributes']
        assert_equal(attributes['title'], collection.title)
        assert_equal(attributes['date_created'], collection.date_created.isoformat())
        assert_equal(attributes['date_modified'], collection.date_modified.isoformat())

        # Relationships
        relationships = data['relationships']
        assert_in('node_links', relationships)
        # Bunch of stuff in Nodes that should not be in Collections
        assert_not_in('contributors', relationships)
        assert_not_in('files', relationships)
        assert_not_in('parent', relationships)
        assert_not_in('registrations', relationships)
        assert_not_in('forked_from', relationships)
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:23,代码来源:test_serializers.py


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