本文整理汇总了Python中tests.utils.mock_archive函数的典型用法代码示例。如果您正苦于以下问题:Python mock_archive函数的具体用法?Python mock_archive怎么用?Python mock_archive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock_archive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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'
示例2: test_archive_success
def test_archive_success(self):
node = factories.NodeFactory(creator=self.user)
file_trees, selected_files, node_index = generate_file_tree([node])
data = generate_metadata(
file_trees,
selected_files,
node_index
)
schema = generate_schema_from_data(data)
with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
with mock.patch.object(StorageAddonBase, '_get_file_tree', mock.Mock(return_value=file_trees[node._id])):
job = factories.ArchiveJobFactory()
archive_success(registration._id, job._id)
for key, question in registration.registered_meta[schema._id].items():
target = None
if isinstance(question.get('value'), dict):
target = [v for v in question['value'].values() if 'extra' in v and 'sha256' in v['extra'][0]][0]
elif 'extra' in question and 'hashes' in question['extra'][0]:
target = question
if target:
assert_in(registration._id, target['extra'][0]['viewUrl'])
assert_not_in(node._id, target['extra'][0]['viewUrl'])
del selected_files[target['extra'][0]['sha256']]
else:
# check non-file questions are unmodified
assert_equal(data[key]['value'], question['value'])
assert_false(selected_files)
示例3: test_archive_failure_different_name_same_sha
def test_archive_failure_different_name_same_sha(self):
file_tree = file_tree_factory(0, 0, 0)
fake_file = file_factory()
fake_file2 = file_factory(sha256=fake_file['extra']['hashes']['sha256'])
file_tree['children'] = [fake_file2]
node = factories.NodeFactory(creator=self.user)
data = {
('q_' + fake_file['name']): {
'value': fake.word(),
'extra': [{
'sha256': fake_file['extra']['hashes']['sha256'],
'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
node._id,
fake_file['path']
),
'selectedFileName': fake_file['name'],
'nodeId': node._id
}]
}
}
schema = generate_schema_from_data(data)
draft = factories.DraftRegistrationFactory(branched_from=node, registration_schema=schema, registered_metadata=data)
with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
with mock.patch.object(BaseStorageAddon, '_get_file_tree', mock.Mock(return_value=file_tree)):
job = factories.ArchiveJobFactory(initiator=registration.creator)
draft.registered_node = registration
draft.save()
with assert_raises(ArchivedFileNotFound):
archive_success(registration._id, job._id)
示例4: test_archive_success_different_name_same_sha
def test_archive_success_different_name_same_sha(self):
file_tree = file_tree_factory(0, 0, 0)
fake_file = file_factory()
fake_file2 = file_factory(sha256=fake_file['extra']['hashes']['sha256'])
file_tree['children'] = [fake_file, fake_file2]
node = factories.NodeFactory(creator=self.user)
data = {
('q_' + fake_file['name']): {
'value': fake.word(),
'extra': [{
'sha256': fake_file['extra']['hashes']['sha256'],
'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
node._id,
fake_file['path']
),
'selectedFileName': fake_file['name'],
'nodeId': node._id
}]
}
}
schema = generate_schema_from_data(data)
with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
with mock.patch.object(StorageAddonBase, '_get_file_tree', mock.Mock(return_value=file_tree)):
job = factories.ArchiveJobFactory()
archive_success(registration._id, job._id)
for key, question in registration.registered_meta[schema._id].items():
assert_equal(question['extra'][0]['selectedFileName'], fake_file['name'])
示例5: test_archive_success_same_file_in_component
def test_archive_success_same_file_in_component(self):
file_tree = file_tree_factory(3, 3, 3)
selected = select_files_from_tree(file_tree).values()[0]
child_file_tree = file_tree_factory(0, 0, 0)
child_file_tree['children'] = [selected]
node = factories.NodeFactory(creator=self.user)
child = factories.NodeFactory(creator=self.user, parent=node)
data = {
('q_' + selected['name']): {
'value': fake.word(),
'extra': [{
'sha256': selected['extra']['hashes']['sha256'],
'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
child._id,
selected['path']
),
'selectedFileName': selected['name'],
'nodeId': child._id
}]
}
}
schema = generate_schema_from_data(data)
with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
with mock.patch.object(StorageAddonBase, '_get_file_tree', mock.Mock(return_value=file_tree)):
job = factories.ArchiveJobFactory()
archive_success(registration._id, job._id)
child_reg = registration.nodes[0]
for key, question in registration.registered_meta[schema._id].items():
assert_in(child_reg._id, question['extra'][0]['viewUrl'])
示例6: test_archive_success_with_deeply_nested_schema
def test_archive_success_with_deeply_nested_schema(self):
node = factories.NodeFactory(creator=self.user)
file_trees, selected_files, node_index = generate_file_tree([node])
data = {
('q_' + selected_file['name']): {
'value': fake.word(),
'extra': [{
'selectedFileName': selected_file['name'],
'nodeId': node._id,
'sha256': sha256,
'viewUrl': '/project/{0}/files/osfstorage{1}'.format(node._id, selected_file['path'])
}]
}
for sha256, selected_file in selected_files.items()
}
schema = generate_schema_from_data(data)
with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
with mock.patch.object(BaseStorageAddon, '_get_file_tree', mock.Mock(return_value=file_trees[node._id])):
job = factories.ArchiveJobFactory(initiator=registration.creator)
archive_success(registration._id, job._id)
registration.reload()
for key, question in registration.registered_meta[schema._id].items():
target = None
if isinstance(question['value'], dict):
target = [v for v in question['value'].values() if 'extra' in v and 'sha256' in v['extra'][0]][0]
elif 'extra' in question and 'sha256' in question['extra'][0]:
target = question
if target:
assert_in(registration._id, target['extra'][0]['viewUrl'])
assert_not_in(node._id, target['extra'][0]['viewUrl'])
del selected_files[target['extra'][0]['sha256']]
else:
# check non-file questions are unmodified
assert_equal(data[key]['value'], question['value'])
assert_false(selected_files)
示例7: test_archive_success_escaped_file_names
def test_archive_success_escaped_file_names(self):
file_tree = file_tree_factory(0, 0, 0)
fake_file = file_factory(name='>and&and<')
fake_file_name = strip_html(fake_file['name'])
file_tree['children'] = [fake_file]
node = factories.NodeFactory(creator=self.user)
data = {
('q_' + fake_file_name): {
'value': fake.word(),
'extra': [{
'sha256': fake_file['extra']['hashes']['sha256'],
'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
node._id,
fake_file['path']
),
'selectedFileName': fake_file_name,
'nodeId': node._id
}]
}
}
schema = generate_schema_from_data(data)
draft = factories.DraftRegistrationFactory(branched_from=node, registration_schema=schema, registered_metadata=data)
with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
with mock.patch.object(BaseStorageAddon, '_get_file_tree', mock.Mock(return_value=file_tree)):
job = factories.ArchiveJobFactory(initiator=registration.creator)
archive_success(registration._id, job._id)
registration.reload()
for key, question in registration.registered_meta[schema._id].items():
assert_equal(question['extra'][0]['selectedFileName'], fake_file_name)
示例8: test_cannot_request_termination_on_component_of_embargo
def test_cannot_request_termination_on_component_of_embargo(self):
node = ProjectFactory()
ProjectFactory(parent=node, creator=node.creator) # child project
with utils.mock_archive(node, embargo=True, autocomplete=True, autoapprove=True) as reg:
with assert_raises(NodeStateError):
reg._nodes.first().request_embargo_termination(Auth(node.creator))
示例9: test_is_pending_registration_searches_parents
def test_is_pending_registration_searches_parents(self):
user = factories.AuthUserFactory()
node = factories.NodeFactory(creator=user)
child = factories.NodeFactory(creator=user, parent=node)
factories.NodeFactory(creator=user, parent=child)
with mock_archive(node) as registration:
sub_reg = registration.nodes[0].nodes[0]
assert_true(sub_reg.is_pending_registration)
示例10: test_embargo_end_date_searches_parents
def test_embargo_end_date_searches_parents(self):
user = factories.AuthUserFactory()
node = factories.NodeFactory(creator=user)
child = factories.NodeFactory(creator=user, parent=node)
factories.NodeFactory(creator=user, parent=child)
with mock_archive(node, embargo=True) as registration:
sub_reg = registration.nodes[0].nodes[0]
assert_equal(sub_reg.embargo_end_date, registration.embargo_end_date)
示例11: test_is_embargoed_searches_parents
def test_is_embargoed_searches_parents(self):
user = factories.AuthUserFactory()
node = factories.NodeFactory(creator=user)
child = factories.NodeFactory(creator=user, parent=node)
factories.NodeFactory(creator=user, parent=child)
with mock_archive(node, embargo=True, autoapprove=True) as registration:
sub_reg = registration.nodes[0].nodes[0]
assert_true(sub_reg.is_embargoed)
示例12: test_migrate_registration_extra
def test_migrate_registration_extra(self):
with utils.mock_archive(
self.node,
schema=self.prereg_schema,
data=self.data,
autocomplete=True,
autoapprove=True
) as reg:
migrate()
reg.reload()
data = reg.registered_meta[self.prereg_schema._id]
assert_true(
isinstance(data['uploader']['extra'], list)
)
assert_true(
isinstance(
data['nested']['value']['uploader']['extra'],
list
)
)
assert_true(
isinstance(
data['nested']['value']['question']['extra'],
list
)
)
assert_equal(
self.data['uploader']['extra'],
data['uploader']['extra'][0]
)
assert_equal(
self.data['nested']['value']['uploader']['extra'],
data['nested']['value']['uploader']['extra'][0]
)
assert_equal(
self.data['nested']['value']['question']['value'],
data['nested']['value']['question']['value']
)
assert_equal(
self.data['nested']['value']['other'],
data['nested']['value']['other']
)
assert_equal(
self.data['other'],
data['other']
)
assert_true(
data['bad']['extra'][0].get('data', False)
)
assert_true(
isinstance(data['bad']['extra'][0]['data'], dict)
)
assert_equal(
data['bad']['extra'][0]['data']['name'], 'file.txt'
)
assert_equal(
data['bad']['extra'][0]['data']['sha256'], '2413fb3709b05939f04cf2e92f7d0897fc2596f9ad0b8a9ea855c7bfebaae892'
)
示例13: test_sanction_searches_parents
def test_sanction_searches_parents(self):
user = factories.AuthUserFactory()
node = factories.NodeFactory(creator=user)
child = factories.NodeFactory(creator=user, parent=node)
factories.NodeFactory(creator=user, parent=child)
with mock_archive(node) as registration:
approval = registration.registration_approval
sub_reg = registration.nodes[0].nodes[0]
assert_equal(sub_reg.sanction, approval)
示例14: test_is_registration_approved_searches_parents
def test_is_registration_approved_searches_parents(self):
user = factories.AuthUserFactory()
node = factories.NodeFactory(creator=user)
child = factories.NodeFactory(creator=user, parent=node)
factories.NodeFactory(creator=user, parent=child)
with mock_archive(node) as registration:
with mock.patch('website.project.sanctions.Sanction.is_approved', mock.Mock(return_value=True)):
sub_reg = registration.nodes[0].nodes[0]
assert_true(sub_reg.is_registration_approved)
示例15: setUp
def setUp(self):
super(TestNodeEmbargoTerminations, self).setUp()
self.user = factories.AuthUserFactory()
self.node = factories.ProjectFactory(creator=self.user)
with mock_archive(self.node, embargo=True, autoapprove=True) as registration:
self.registration = registration
self.not_embargoed = factories.RegistrationFactory()