本文整理汇总了Python中osf_tests.factories.NodeFactory.fork_node方法的典型用法代码示例。如果您正苦于以下问题:Python NodeFactory.fork_node方法的具体用法?Python NodeFactory.fork_node怎么用?Python NodeFactory.fork_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osf_tests.factories.NodeFactory
的用法示例。
在下文中一共展示了NodeFactory.fork_node方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_node_serializer
# 需要导入模块: from osf_tests.factories import NodeFactory [as 别名]
# 或者: from osf_tests.factories.NodeFactory import fork_node [as 别名]
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)
示例2: test_node_serializer
# 需要导入模块: from osf_tests.factories import NodeFactory [as 别名]
# 或者: from osf_tests.factories.NodeFactory import fork_node [as 别名]
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 set(attributes['tags']) == set(node.tags.values_list('name', flat=True))
assert not attributes['current_user_can_comment']
assert attributes['category'] == node.category
assert attributes['registration'] == node.is_registration
assert attributes['fork'] == node.is_fork
assert attributes['collection'] == node.is_collection
assert attributes['analytics_key'] == node.keenio_read_key
assert attributes['wiki_enabled'] == node.has_addon('wiki')
# Relationships
relationships = data['relationships']
assert 'region' in 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
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)