• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.make_drf_request_with_version函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_file_serializer

    def test_file_serializer(self, file_one):
        date_created = file_one.versions.first().date_created
        date_modified = file_one.versions.last().date_created
        date_created_tz_aware = date_created.replace(tzinfo=utc)
        date_modified_tz_aware = date_modified.replace(tzinfo=utc)
        new_format = '%Y-%m-%dT%H:%M:%S.%fZ'

        # test_date_modified_formats_to_old_format
        req = make_drf_request_with_version(version='2.0')
        data = FileSerializer(file_one, context={'request': req}).data['data']
        assert date_modified_tz_aware == data['attributes']['date_modified']

        # test_date_modified_formats_to_new_format
        req = make_drf_request_with_version(version='2.2')
        data = FileSerializer(file_one, context={'request': req}).data['data']
        assert datetime.strftime(date_modified, new_format) == data['attributes']['date_modified']

        # test_date_created_formats_to_old_format
        req = make_drf_request_with_version(version='2.0')
        data = FileSerializer(file_one, context={'request': req}).data['data']
        assert date_created_tz_aware == data['attributes']['date_created']

        # test_date_created_formats_to_new_format
        req = make_drf_request_with_version(version='2.2')
        data = FileSerializer(file_one, context={'request': req}).data['data']
        assert datetime.strftime(date_created, new_format) == data['attributes']['date_created']
开发者ID:adlius,项目名称:osf.io,代码行数:26,代码来源:test_file_serializer.py


示例2: 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


示例3: test_no_node_relationship_after_version_2_7

    def test_no_node_relationship_after_version_2_7(self, file_one):
        req_2_7 = make_drf_request_with_version(version='2.7')
        data_2_7 = FileSerializer(file_one, context={'request': req_2_7}).data['data']
        assert 'node' in data_2_7['relationships'].keys()

        req_2_8 = make_drf_request_with_version(version='2.8')
        data_2_8 = FileSerializer(file_one, context={'request': req_2_8}).data['data']
        assert 'node' not in data_2_8['relationships'].keys()
开发者ID:aaxelb,项目名称:osf.io,代码行数:8,代码来源:test_file_serializer.py


示例4: test_node_links_allowed_version_registration_serializer

 def test_node_links_allowed_version_registration_serializer(self):
     req = make_drf_request_with_version(version='2.0')
     data = RegistrationSerializer(
         self.registration,
         context={'request': req}
     ).data['data']
     assert_in('node_links', data['relationships'])
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:7,代码来源:test_serializers.py


示例5: test_preprint_provider_serialization_v25

    def test_preprint_provider_serialization_v25(self):
        req = make_drf_request_with_version(version='2.5')
        result = PreprintProviderSerializer(
            self.preprint_provider,
            context={'request': req}
        ).data

        data = result['data']
        attributes = data['attributes']

        assert_equal(data['id'], self.preprint_provider._id)
        assert_equal(data['type'], 'preprint_providers')

        assert_not_in('banner_path', attributes)
        assert_not_in('logo_path', attributes)
        assert_not_in('header_text', attributes)
        assert_not_in('email_contact', attributes)
        assert_not_in('social_facebook', attributes)
        assert_not_in('social_instagram', attributes)
        assert_not_in('social_twitter', attributes)
        assert_not_in('subjects_acceptable', attributes)

        assert_in('name', attributes)
        assert_in('description', attributes)
        assert_in('advisory_board', attributes)
        assert_in('example', attributes)
        assert_in('domain', attributes)
        assert_in('domain_redirect_enabled', attributes)
        assert_in('footer_links', attributes)
        assert_in('share_source', attributes)
        assert_in('share_publish_type', attributes)
        assert_in('email_support', attributes)
        assert_in('preprint_word', attributes)
        assert_in('allow_submissions', attributes)
        assert_in('additional_providers', attributes)
开发者ID:leb2dg,项目名称:osf.io,代码行数:35,代码来源:test_serializers.py


示例6: test_field_with_non_attribute

 def test_field_with_non_attribute(self):
     req = make_drf_request_with_version(version='2.0')
     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:baylee-d,项目名称:osf.io,代码行数:7,代码来源:test_serializers.py


示例7: test_collection_serialization

    def test_collection_serialization(self):
        user = UserFactory()
        collection = CollectionFactory(creator=user)
        req = make_drf_request_with_version()
        if req.version >= '2.2':
            created_format = '%Y-%m-%dT%H:%M:%S.%fZ'
            modified_format = '%Y-%m-%dT%H:%M:%S.%fZ'
        else:
            created_format = '%Y-%m-%dT%H:%M:%S.%f' if collection.created.microsecond else '%Y-%m-%dT%H:%M:%S'
            modified_format = '%Y-%m-%dT%H:%M:%S.%f' if collection.modified.microsecond else '%Y-%m-%dT%H:%M:%S'

        result = CollectionSerializer(
            collection, context={'request': req}
        ).data
        data = result['data']
        assert data['id'] == collection._id
        assert data['type'] == 'collections'
        # Attributes
        attributes = data['attributes']
        assert attributes['title'] == collection.title
        assert attributes['date_created'] == collection.created.strftime(
            created_format)
        assert attributes['date_modified'] == collection.modified.strftime(
            modified_format)
        assert attributes['bookmarks'] == collection.is_bookmark_collection

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


示例8: test_search_serializer_mixed_model

    def test_search_serializer_mixed_model(self):

        user = AuthUserFactory()
        project = ProjectFactory(creator=user, is_public=True)
        component = NodeFactory(parent=project, creator=user, is_public=True)
        file_component = utils.create_test_file(component, user)
        context = {'request': make_drf_request_with_version(version='2.0')}
        schema = RegistrationSchema.objects.filter(
            name='Replication Recipe (Brandt et al., 2013): Post-Completion',
            schema_version=LATEST_SCHEMA_VERSION).first()

        # test_search_serializer_mixed_model_project
        result = SearchSerializer(project, context=context).data
        assert result['data']['type'] == 'nodes'

        # test_search_serializer_mixed_model_component
        result = SearchSerializer(component, context=context).data
        assert result['data']['type'] == 'nodes'

        # test_search_serializer_mixed_model_registration
        with mock_archive(project, autocomplete=True, autoapprove=True, schema=schema) as registration:
            result = SearchSerializer(registration, context=context).data
            assert result['data']['type'] == 'registrations'

        # test_search_serializer_mixed_model_file
        result = SearchSerializer(file_component, context=context).data
        assert result['data']['type'] == 'files'

        # test_search_serializer_mixed_model_user
        result = SearchSerializer(user, context=context).data
        assert result['data']['type'] == 'users'
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:31,代码来源:test_serializers.py


示例9: get_related_count

 def get_related_count(self, user, related_field, auth):
     req = make_drf_request_with_version(version='2.0')
     req.query_params['related_counts'] = True
     if auth:
         req.user = auth
     result = UserSerializer(user, context={'request': req}).data
     return result['data']['relationships'][related_field]['links']['related']['meta']['count']
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:7,代码来源:test_serializers.py


示例10: test_field_with_two_kwargs

 def test_field_with_two_kwargs(self):
     req = make_drf_request_with_version(version='2.0')
     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:baylee-d,项目名称:osf.io,代码行数:7,代码来源:test_serializers.py


示例11: test_serializing_log_with_legacy_non_registered_contributor_data

    def test_serializing_log_with_legacy_non_registered_contributor_data(self, fake):
        # Old logs store unregistered contributors in params as dictionaries of the form:
        # {
        #     'nr_email': <email>,
        #     'nr_name': <name>,
        # }
        # This test ensures that the NodeLogSerializer can handle this legacy data.
        project = ProjectFactory()
        user = UserFactory()
        request = make_drf_request_with_version()
        nr_data = {'nr_email': fake.email(), 'nr_name': fake.name()}
        log = project.add_log(
            action=NodeLog.CONTRIB_ADDED,
            auth=Auth(project.creator),
            params={
                'project': project._id,
                'node': project._id,
                'contributors': [user._id, nr_data],
            }
        )
        serialized = NodeLogSerializer(log, context={'request': request}).data
        contributor_data = serialized['data']['attributes']['params']['contributors']
        # contributor_data will have two dicts:
        # the first will be the registered contrib, 2nd will be non-reg contrib
        reg_contributor_data, unreg_contributor_data = contributor_data
        assert reg_contributor_data['id'] == user._id
        assert reg_contributor_data['full_name'] == user.fullname

        assert unreg_contributor_data['id'] is None
        assert unreg_contributor_data['full_name'] == nr_data['nr_name']
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:30,代码来源:test_serializers.py


示例12: test_node_links_bad_version_registration_serializer

 def test_node_links_bad_version_registration_serializer(self):
     req = make_drf_request_with_version(version='2.1')
     data = RegistrationSerializer(
         self.registration,
         context={'request': req}
     ).data['data']
     assert_not_in('node_links', data['attributes'])
开发者ID:leb2dg,项目名称:osf.io,代码行数:7,代码来源:test_serializers.py


示例13: test_null_links_are_omitted

    def test_null_links_are_omitted(self):
        req = make_drf_request_with_version(version='2.0')
        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'])
开发者ID:aaxelb,项目名称:osf.io,代码行数:7,代码来源:test_serializers.py


示例14: test_collection_serialization

    def test_collection_serialization(self):
        collection = CollectionFactory(creator=self.user)
        req = make_drf_request_with_version()
        if req.version >= '2.2':
            created_format = '%Y-%m-%dT%H:%M:%S.%fZ'
            modified_format = '%Y-%m-%dT%H:%M:%S.%fZ'
        else:
            created_format = '%Y-%m-%dT%H:%M:%S.%f' if collection.date_created.microsecond else '%Y-%m-%dT%H:%M:%S'
            modified_format = '%Y-%m-%dT%H:%M:%S.%f' if collection.date_modified.microsecond else '%Y-%m-%dT%H:%M:%S'

        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.strftime(created_format))
        assert_equal(attributes['date_modified'], collection.date_modified.strftime(modified_format))
        assert_equal(attributes['bookmarks'], collection.is_bookmark_collection)

        # 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:adlius,项目名称:osf.io,代码行数:30,代码来源:test_serializers.py


示例15: test_new_date_without_microseconds_formats_to_old_format

 def test_new_date_without_microseconds_formats_to_old_format(self):
     req = make_drf_request_with_version(version='2.0')
     setattr(self.node, 'date_modified', self.new_date_without_microseconds)
     data = NodeSerializer(self.node, context={'request': req}).data['data']
     assert_equal(
         datetime.strftime(self.new_date_without_microseconds, self.old_format_without_microseconds),
         data['attributes']['date_modified']
     )
开发者ID:baylee-d,项目名称:osf.io,代码行数:8,代码来源:test_serializers.py


示例16: test_field_with_two_filters

 def test_field_with_two_filters(self):
     req = make_drf_request_with_version(version='2.0')
     project = factories.ProjectFactory()
     node = factories.NodeFactory(parent=project)
     data = self.BasicNodeSerializer(node, context={'request': req}).data['data']
     field = data['relationships']['field_with_filters']['links']
     assert_in(urllib.quote('filter[target]=hello', safe='?='), field['related']['href'])
     assert_in(urllib.quote('filter[woop]=yea', safe='?='), field['related']['href'])
开发者ID:baylee-d,项目名称:osf.io,代码行数:8,代码来源:test_serializers.py


示例17: test_node_links_withdrawn_registration

    def test_node_links_withdrawn_registration(self):
        factories.WithdrawnRegistrationFactory(
            registration=self.registration)

        req = make_drf_request_with_version(version='2.0')
        data = RegistrationSerializer(
            self.registration,
            context={'request': req}
        ).data['data']
        assert_not_in('node_links', data['relationships'])

        req = make_drf_request_with_version(version='2.1')
        data = RegistrationSerializer(
            self.registration,
            context={'request': req}
        ).data['data']
        assert_not_in('node_links', data['relationships'])
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:17,代码来源:test_serializers.py


示例18: test_new_date_formats_to_new_format

 def test_new_date_formats_to_new_format(self):
     req = make_drf_request_with_version(version='2.2')
     setattr(self.node, 'last_logged', self.new_date)
     data = NodeSerializer(self.node, context={'request': req}).data['data']
     assert_equal(
         datetime.strftime(self.new_date, self.new_format),
         data['attributes']['date_modified']
     )
开发者ID:leb2dg,项目名称:osf.io,代码行数:8,代码来源:test_serializers.py


示例19: test_null_links_are_omitted

    def test_null_links_are_omitted(self):
        req = make_drf_request_with_version(version="2.0")
        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:cslzchen,项目名称:osf.io,代码行数:8,代码来源:test_serializers.py


示例20: get_view_count

    def get_view_count(self, user, related_field, auth):
        req = make_drf_request_with_version(version='2.0')
        if auth:
            req.user = auth
        view_name = UserSerializer().fields[related_field].field.view_name
        resolve_match = resolve(reverse(view_name, kwargs={'version': 'v2', 'user_id': user._id}))
        view = resolve_match.func.view_class(request=req, kwargs={'version': 'v2', 'user_id': user._id})

        return view.get_queryset().count()
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:9,代码来源:test_serializers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.mock_archive函数代码示例发布时间:2022-05-27
下一篇:
Python utils.make_drf_request函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap