本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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']
示例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)
示例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()
示例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'])
示例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)
示例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'])
示例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
示例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'
示例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']
示例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'])
示例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']
示例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'])
示例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'])
示例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)
示例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']
)