本文整理汇总了Python中tests.factories.RegistrationFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python RegistrationFactory.save方法的具体用法?Python RegistrationFactory.save怎么用?Python RegistrationFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.RegistrationFactory
的用法示例。
在下文中一共展示了RegistrationFactory.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cancelling_registration_approval_deletes_component_registrations
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_cancelling_registration_approval_deletes_component_registrations(self):
component = NodeFactory(
creator=self.user,
parent=self.project,
title='Component'
)
NodeFactory(
creator=self.user,
parent=component,
title='Subcomponent'
)
project_registration = RegistrationFactory(project=self.project)
component_registration = project_registration.nodes[0]
subcomponent_registration = component_registration.nodes[0]
project_registration.require_approval(
self.user
)
project_registration.save()
rejection_token = project_registration.registration_approval.approval_state[self.user._id]['rejection_token']
project_registration.registration_approval.reject(self.user, rejection_token)
assert_equal(project_registration.registration_approval.state, Sanction.REJECTED)
assert_true(project_registration.is_deleted)
assert_true(component_registration.is_deleted)
assert_true(subcomponent_registration.is_deleted)
示例2: test_rejecting_embargo_for_existing_registration_does_not_deleted_component_registrations
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_rejecting_embargo_for_existing_registration_does_not_deleted_component_registrations(self):
component = NodeFactory(
creator=self.user,
parent=self.project,
title='Component'
)
subcomponent = NodeFactory(
creator=self.user,
parent=component,
title='Subcomponent'
)
project_registration = RegistrationFactory(project=self.project)
component_registration = project_registration.nodes[0]
subcomponent_registration = component_registration.nodes[0]
project_registration.embargo_registration(
self.user,
datetime.datetime.utcnow() + datetime.timedelta(days=10),
for_existing_registration=True
)
rejection_token = project_registration.embargo.approval_state[self.user._id]['rejection_token']
project_registration.embargo.disapprove_embargo(self.user, rejection_token)
project_registration.save()
assert_equal(project_registration.embargo.state, Embargo.REJECTED)
assert_false(project_registration.is_deleted)
assert_false(component_registration.is_deleted)
assert_false(subcomponent_registration.is_deleted)
示例3: test_cannot_access_retracted_registrations_list
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_cannot_access_retracted_registrations_list(self):
registration = RegistrationFactory(creator=self.user, project=self.public_project)
retraction = RetractedRegistrationFactory(registration=registration, user=registration.creator)
registration.save()
url = '/{}nodes/{}/registrations/'.format(API_BASE, registration._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 404)
示例4: RegistrationWithChildNodesEmbargoModelTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
class RegistrationWithChildNodesEmbargoModelTestCase(OsfTestCase):
def setUp(self):
super(RegistrationWithChildNodesEmbargoModelTestCase, self).setUp()
self.user = AuthUserFactory()
self.auth = self.user.auth
self.valid_embargo_end_date = datetime.datetime.utcnow() + datetime.timedelta(days=3)
self.project = ProjectFactory(title="Root", is_public=False, creator=self.user)
self.component = NodeFactory(creator=self.user, parent=self.project, title="Component")
self.subproject = ProjectFactory(creator=self.user, parent=self.project, title="Subproject")
self.subproject_component = NodeFactory(creator=self.user, parent=self.subproject, title="Subcomponent")
self.registration = RegistrationFactory(project=self.project)
# Reload the registration; else tests won't catch failures to save
self.registration.reload()
def test_approval_embargoes_descendant_nodes(self):
# Initiate embargo for parent registration
self.registration.embargo_registration(self.user, self.valid_embargo_end_date)
self.registration.save()
assert_true(self.registration.is_pending_embargo)
# Ensure descendant nodes are pending embargo
descendants = self.registration.get_descendants_recursive()
for node in descendants:
assert_true(node.is_pending_embargo)
# Approve parent registration's embargo
approval_token = self.registration.embargo.approval_state[self.user._id]["approval_token"]
self.registration.embargo.approve_embargo(self.user, approval_token)
assert_true(self.registration.embargo.embargo_end_date)
# Ensure descendant nodes are in embargo
descendants = self.registration.get_descendants_recursive()
for node in descendants:
assert_true(node.embargo_end_date)
def test_disapproval_cancels_embargo_on_descendant_nodes(self):
# Initiate embargo on parent registration
self.registration.embargo_registration(self.user, self.valid_embargo_end_date)
self.registration.save()
assert_true(self.registration.is_pending_embargo)
# Ensure descendant nodes are pending embargo
descendants = self.registration.get_descendants_recursive()
for node in descendants:
assert_true(node.is_pending_embargo)
# Disapprove parent registration's embargo
rejection_token = self.registration.embargo.approval_state[self.user._id]["rejection_token"]
self.registration.embargo.disapprove_embargo(self.user, rejection_token)
assert_false(self.registration.is_pending_embargo)
assert_equal(self.registration.embargo.state, Embargo.REJECTED)
# Ensure descendant nodes' embargoes are cancelled
descendants = self.registration.get_descendants_recursive()
for node in descendants:
assert_false(node.is_pending_embargo)
assert_false(node.embargo_end_date)
示例5: test_is_public_node_register_page
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_is_public_node_register_page(self):
self.node.is_public = True
self.node.save()
reg = RegistrationFactory(project=self.node)
reg.is_public = True
reg.save()
url = reg.web_url_for('node_register_page')
res = self.app.get(url, auth=None)
assert_equal(res.status_code, http.OK)
示例6: test_check_draft_state_registered_and_deleted_and_approved
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_check_draft_state_registered_and_deleted_and_approved(self):
reg = RegistrationFactory()
self.draft.registered_node = reg
self.draft.save()
reg.is_deleted = True
reg.save()
with mock.patch('website.project.model.DraftRegistration.is_approved', mock.PropertyMock(return_value=True)):
try:
draft_views.check_draft_state(self.draft)
except HTTPError:
self.fail()
示例7: test_GET_disapprove_with_valid_token_returns_redirect_to_parent
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_GET_disapprove_with_valid_token_returns_redirect_to_parent(self):
project = ProjectFactory(creator=self.user)
registration = RegistrationFactory(project=project)
registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
registration.save()
assert_true(registration.is_pending_embargo)
rejection_token = registration.embargo.approval_state[self.user._id]["rejection_token"]
res = self.app.get(registration.web_url_for("view_project", token=rejection_token), auth=self.user.auth)
registration.embargo.reload()
assert_equal(registration.embargo.state, Embargo.REJECTED)
assert_false(registration.is_pending_embargo)
assert_equal(res.status_code, 302)
示例8: test_draft_with_deleted_registered_node_shows_up_in_draft_list
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_draft_with_deleted_registered_node_shows_up_in_draft_list(self):
reg = RegistrationFactory(project=self.public_project)
self.draft_registration.registered_node = reg
self.draft_registration.save()
reg.is_deleted = True
reg.save()
res = self.app.get(self.url, auth=self.user.auth)
assert_equal(res.status_code, 200)
data = res.json["data"]
assert_equal(len(data), 1)
assert_equal(data[0]["attributes"]["registration_supplement"], self.schema._id)
assert_equal(data[0]["id"], self.draft_registration._id)
assert_equal(data[0]["attributes"]["registration_metadata"], {})
示例9: test_cancelling_embargo_deletes_component_registrations
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_cancelling_embargo_deletes_component_registrations(self):
component = NodeFactory(creator=self.user, parent=self.project, title="Component")
subcomponent = NodeFactory(creator=self.user, parent=component, title="Subcomponent")
project_registration = RegistrationFactory(project=self.project)
component_registration = project_registration.nodes[0]
subcomponent_registration = component_registration.nodes[0]
project_registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
project_registration.save()
rejection_token = project_registration.embargo.approval_state[self.user._id]["rejection_token"]
project_registration.embargo.disapprove_embargo(self.user, rejection_token)
assert_equal(project_registration.embargo.state, Embargo.REJECTED)
assert_true(project_registration.is_deleted)
assert_true(component_registration.is_deleted)
assert_true(subcomponent_registration.is_deleted)
示例10: TestMetadataGeneration
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
class TestMetadataGeneration(OsfTestCase):
def setUp(self):
OsfTestCase.setUp(self)
self.visible_contrib = AuthUserFactory()
visible_contrib2 = AuthUserFactory(given_name=u'ヽ༼ ಠ益ಠ ༽ノ', family_name=u'ლ(´◉❥◉`ლ)')
self.invisible_contrib = AuthUserFactory()
self.node = RegistrationFactory(is_public=True)
self.identifier = Identifier(referent=self.node, category='catid', value='cat:7')
self.node.add_contributor(self.visible_contrib, visible=True)
self.node.add_contributor(self.invisible_contrib, visible=False)
self.node.add_contributor(visible_contrib2, visible=True)
self.node.save()
def test_metadata_for_node_only_includes_visible_contribs(self):
metadata_xml = datacite_metadata_for_node(self.node, doi=self.identifier.value)
# includes visible contrib name
assert_in(u'{}, {}'.format(
self.visible_contrib.family_name, self.visible_contrib.given_name),
metadata_xml)
# doesn't include invisible contrib name
assert_not_in(self.invisible_contrib.family_name, metadata_xml)
assert_in(self.identifier.value, metadata_xml)
def test_metadata_for_node_has_correct_structure(self):
metadata_xml = datacite_metadata_for_node(self.node, doi=self.identifier.value)
root = lxml.etree.fromstring(metadata_xml)
xsi_location = '{http://www.w3.org/2001/XMLSchema-instance}schemaLocation'
expected_location = 'http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd'
assert_equal(root.attrib[xsi_location], expected_location)
identifier = root.find('{%s}identifier' % metadata.NAMESPACE)
assert_equal(identifier.attrib['identifierType'], 'DOI')
assert_equal(identifier.text, self.identifier.value)
creators = root.find('{%s}creators' % metadata.NAMESPACE)
assert_equal(len(creators.getchildren()), len(self.node.visible_contributors))
publisher = root.find('{%s}publisher' % metadata.NAMESPACE)
assert_equal(publisher.text, 'Open Science Framework')
pub_year = root.find('{%s}publicationYear' % metadata.NAMESPACE)
assert_equal(pub_year.text, str(self.node.registered_date.year))
示例11: test_get_node_name
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_get_node_name(self):
user = UserFactory()
auth = Auth(user=user)
another_user = UserFactory()
another_auth = Auth(user=another_user)
# Public (Can View)
public_project = ProjectFactory(is_public=True)
collector = rubeus.NodeFileCollector(node=public_project, auth=another_auth)
node_name = u"{0}: {1}".format(
public_project.project_or_component.capitalize(), sanitize.unescape_entities(public_project.title)
)
assert_equal(collector._get_node_name(public_project), node_name)
# Private (Can't View)
registration_private = RegistrationFactory(creator=user)
registration_private.is_public = False
registration_private.save()
collector = rubeus.NodeFileCollector(node=registration_private, auth=another_auth)
assert_equal(collector._get_node_name(registration_private), u"Private Registration")
content = ProjectFactory(creator=user)
node = ProjectFactory(creator=user)
forked_private = node.fork_node(auth=auth)
forked_private.is_public = False
forked_private.save()
collector = rubeus.NodeFileCollector(node=forked_private, auth=another_auth)
assert_equal(collector._get_node_name(forked_private), u"Private Fork")
pointer_private = node.add_pointer(content, auth=auth)
pointer_private.is_public = False
pointer_private.save()
collector = rubeus.NodeFileCollector(node=pointer_private, auth=another_auth)
assert_equal(collector._get_node_name(pointer_private), u"Private Link")
private_project = ProjectFactory(is_public=False)
collector = rubeus.NodeFileCollector(node=private_project, auth=another_auth)
assert_equal(collector._get_node_name(private_project), u"Private Component")
private_node = NodeFactory(is_public=False)
collector = rubeus.NodeFileCollector(node=private_node, auth=another_auth)
assert_equal(collector._get_node_name(private_node), u"Private Component")
示例12: test_GET_disapprove_with_valid
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_GET_disapprove_with_valid(self):
project = ProjectFactory(creator=self.user)
registration = RegistrationFactory(project=project)
registration.embargo_registration(
self.user,
datetime.datetime.utcnow() + datetime.timedelta(days=10)
)
registration.save()
assert_true(registration.is_pending_embargo)
rejection_token = registration.embargo.approval_state[self.user._id]['rejection_token']
res = self.app.get(
registration.registered_from.web_url_for('view_project', token=rejection_token),
auth=self.user.auth,
)
registration.embargo.reload()
assert_equal(registration.embargo.state, Embargo.REJECTED)
assert_false(registration.is_pending_embargo)
assert_equal(res.status_code, 200)
assert_equal(project.web_url_for('view_project'), res.request.path)
示例13: test_GET_disapprove_with_valid_token_returns_redirect_to_parent
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
def test_GET_disapprove_with_valid_token_returns_redirect_to_parent(self):
project = ProjectFactory(creator=self.user)
registration = RegistrationFactory(project=project)
registration.embargo_registration(
self.user,
datetime.datetime.utcnow() + datetime.timedelta(days=10)
)
registration.save()
assert_true(registration.pending_embargo)
disapproval_token = registration.embargo.approval_state[self.user._id]['disapproval_token']
res = self.app.get(
registration.web_url_for('node_registration_embargo_disapprove', token=disapproval_token),
auth=self.user.auth,
)
registration.embargo.reload()
assert_equal(registration.embargo.state, Embargo.CANCELLED)
assert_false(registration.embargo_end_date)
assert_false(registration.pending_embargo)
assert_equal(res.status_code, 302)
assert_true(project._id in res.location)
示例14: TestInstitutionRegistrationList
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
class TestInstitutionRegistrationList(ApiTestCase):
def setUp(self):
super(TestInstitutionRegistrationList, self).setUp()
self.institution = InstitutionFactory()
self.registration1 = RegistrationFactory(is_public=True, is_registration=True)
self.registration1.primary_institution = self.institution
self.registration1.save()
self.user1 = AuthUserFactory()
self.user2 = AuthUserFactory()
self.registration2 = RegistrationFactory(creator=self.user1, is_public=False, is_registration=True)
self.registration2.primary_institution = self.institution
self.registration2.add_contributor(self.user2, auth=Auth(self.user1))
self.registration2.save()
self.registration3 = RegistrationFactory(creator=self.user2, is_public=False, is_registration=True)
self.registration3.primary_institution = self.institution
self.registration3.save()
self.institution_node_url = '/{0}institutions/{1}/registrations/'.format(API_BASE, self.institution._id)
def test_return_all_public_nodes(self):
res = self.app.get(self.institution_node_url)
assert_equal(res.status_code, 200)
ids = [each['id'] for each in res.json['data']]
assert_in(self.registration1._id, ids)
assert_not_in(self.registration2._id, ids)
assert_not_in(self.registration3._id, ids)
def test_return_private_nodes_with_auth(self):
res = self.app.get(self.institution_node_url, auth=self.user1.auth)
assert_equal(res.status_code, 200)
ids = [each['id'] for each in res.json['data']]
assert_in(self.registration1._id, ids)
assert_in(self.registration2._id, ids)
assert_not_in(self.registration3._id, ids)
def test_return_private_nodes_mixed_auth(self):
res = self.app.get(self.institution_node_url, auth=self.user2.auth)
assert_equal(res.status_code, 200)
ids = [each['id'] for each in res.json['data']]
assert_in(self.registration1._id, ids)
assert_in(self.registration2._id, ids)
assert_in(self.registration3._id, ids)
示例15: TestWithdrawnRegistrations
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import save [as 别名]
class TestWithdrawnRegistrations(NodeCRUDTestCase):
def setUp(self):
super(TestWithdrawnRegistrations, self).setUp()
self.registration = RegistrationFactory(creator=self.user, project=self.public_project)
self.withdrawn_registration = WithdrawnRegistrationFactory(registration=self.registration, user=self.registration.creator)
self.public_pointer_project = ProjectFactory(is_public=True)
self.public_pointer = self.public_project.add_pointer(self.public_pointer_project,
auth=Auth(self.user),
save=True)
self.withdrawn_url = '/{}registrations/{}/'.format(API_BASE, self.registration._id)
self.withdrawn_registration.justification = 'We made a major error.'
self.withdrawn_registration.save()
def test_can_access_withdrawn_contributors(self):
url = '/{}registrations/{}/contributors/'.format(API_BASE, self.registration._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 200)
def test_cannot_access_withdrawn_children(self):
url = '/{}registrations/{}/children/'.format(API_BASE, self.registration._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_cannot_access_withdrawn_comments(self):
self.public_project = ProjectFactory(is_public=True, creator=self.user)
self.public_comment = CommentFactory(node=self.public_project, user=self.user)
url = '/{}registrations/{}/comments/'.format(API_BASE, self.registration._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_can_access_withdrawn_contributor_detail(self):
url = '/{}registrations/{}/contributors/{}/'.format(API_BASE, self.registration._id, self.user._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 200)
def test_cannot_return_a_withdrawn_registration_at_node_detail_endpoint(self):
url = '/{}nodes/{}/'.format(API_BASE, self.registration._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 404)
def test_cannot_delete_a_withdrawn_registration(self):
url = '/{}registrations/{}/'.format(API_BASE, self.registration._id)
res = self.app.delete_json_api(url, auth=self.user.auth, expect_errors=True)
self.registration.reload()
assert_equal(res.status_code, 405)
def test_cannot_access_withdrawn_files_list(self):
url = '/{}registrations/{}/files/'.format(API_BASE, self.registration._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_cannot_access_withdrawn_node_links_detail(self):
url = '/{}registrations/{}/node_links/{}/'.format(API_BASE, self.registration._id, self.public_pointer._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 404)
def test_cannot_access_withdrawn_node_links_list(self):
url = '/{}registrations/{}/node_links/'.format(API_BASE, self.registration._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_cannot_access_withdrawn_node_logs(self):
self.public_project = ProjectFactory(is_public=True, creator=self.user)
url = '/{}registrations/{}/logs/'.format(API_BASE, self.registration._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_cannot_access_withdrawn_registrations_list(self):
self.registration.save()
url = '/{}registrations/{}/registrations/'.format(API_BASE, self.registration._id)
res = self.app.get(url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_withdrawn_registrations_display_limited_fields(self):
registration = self.registration
res = self.app.get(self.withdrawn_url, auth=self.user.auth)
assert_equal(res.status_code, 200)
attributes = res.json['data']['attributes']
expected_attributes = {
'title': registration.title,
'description': registration.description,
'date_created': registration.date_created.isoformat(),
'date_registered': registration.registered_date.isoformat(),
'withdrawal_justification': registration.retraction.justification,
'public': None,
'category': None,
'date_modified': None,
'registration': True,
'fork': None,
'collection': None,
'tags': None,
'withdrawn': True,
'pending_withdrawal': None,
'pending_registration_approval': None,
'pending_embargo_approval': None,
'embargo_end_date': None,
'registered_meta': None,
'current_user_permissions': None,
#.........这里部分代码省略.........