本文整理汇总了Python中tests.factories.RegistrationFactory.embargo_registration方法的典型用法代码示例。如果您正苦于以下问题:Python RegistrationFactory.embargo_registration方法的具体用法?Python RegistrationFactory.embargo_registration怎么用?Python RegistrationFactory.embargo_registration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.RegistrationFactory
的用法示例。
在下文中一共展示了RegistrationFactory.embargo_registration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rejecting_embargo_for_existing_registration_does_not_deleted_component_registrations
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [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)
示例2: test_make_child_embargoed_registration_public_asks_all_admins_in_tree
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [as 别名]
def test_make_child_embargoed_registration_public_asks_all_admins_in_tree(self, mock_ask):
# Initiate and approve embargo
node = NodeFactory(creator=self.user)
c1 = AuthUserFactory()
child = NodeFactory(parent=node, creator=c1)
c2 = AuthUserFactory()
NodeFactory(parent=child, creator=c2)
registration = RegistrationFactory(project=node)
registration.embargo_registration(
self.user,
datetime.datetime.utcnow() + datetime.timedelta(days=10)
)
for user_id, embargo_tokens in registration.embargo.approval_state.iteritems():
approval_token = embargo_tokens['approval_token']
registration.embargo.approve_embargo(User.load(user_id), approval_token)
self.registration.save()
res = self.app.post(
registration.api_url_for('project_set_privacy', permissions='public'),
auth=self.user.auth
)
assert_equal(res.status_code, 200)
asked_admins = [(admin._id, n._id) for admin, n in mock_ask.call_args[0][0]]
for admin, node in registration.get_admin_contributors_recursive():
assert_in((admin._id, node._id), asked_admins)
示例3: RegistrationWithChildNodesEmbargoModelTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [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)
示例4: test_GET_disapprove_with_valid_token_returns_redirect_to_parent
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [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)
示例5: test_cancelling_embargo_deletes_component_registrations
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [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)
示例6: test_GET_disapprove_with_valid_token_returns_redirect_to_parent
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [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)
示例7: test_GET_disapprove_with_valid
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [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)
示例8: RegistrationEmbargoApprovalDisapprovalViewsTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [as 别名]
class RegistrationEmbargoApprovalDisapprovalViewsTestCase(OsfTestCase):
def setUp(self):
super(RegistrationEmbargoApprovalDisapprovalViewsTestCase, self).setUp()
self.user = AuthUserFactory()
self.registration = RegistrationFactory(creator=self.user)
# node_registration_embargo_approve tests
def test_GET_from_unauthorized_user_raises_HTTPForbidden(self):
unauthorized_user = AuthUserFactory()
res = self.app.get(
self.registration.web_url_for("view_project", token=DUMMY_TOKEN),
auth=unauthorized_user.auth,
expect_errors=True,
)
assert_equal(res.status_code, 403)
def test_GET_approve_registration_without_embargo_raises_HTTPBad_Request(self):
assert_false(self.registration.is_pending_embargo)
res = self.app.get(
self.registration.web_url_for("view_project", token=DUMMY_TOKEN), auth=self.user.auth, expect_errors=True
)
assert_equal(res.status_code, 400)
def test_GET_approve_with_invalid_token_returns_HTTPBad_Request(self):
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
res = self.app.get(
self.registration.web_url_for("view_project", token=DUMMY_TOKEN), auth=self.user.auth, expect_errors=True
)
assert_equal(res.status_code, 400)
def test_GET_approve_with_wrong_token_returns_HTTPBad_Request(self):
admin2 = UserFactory()
self.registration.contributors.append(admin2)
self.registration.add_permission(admin2, "admin", save=True)
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
wrong_approval_token = self.registration.embargo.approval_state[admin2._id]["approval_token"]
res = self.app.get(
self.registration.web_url_for("view_project", token=wrong_approval_token),
auth=self.user.auth,
expect_errors=True,
)
assert_equal(res.status_code, 400)
def test_GET_approve_with_wrong_admins_token_returns_HTTPBad_Request(self):
admin2 = UserFactory()
self.registration.contributors.append(admin2)
self.registration.add_permission(admin2, "admin", save=True)
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
wrong_approval_token = self.registration.embargo.approval_state[admin2._id]["approval_token"]
res = self.app.get(
self.registration.web_url_for("view_project", token=wrong_approval_token),
auth=self.user.auth,
expect_errors=True,
)
assert_true(self.registration.is_pending_embargo)
assert_equal(res.status_code, 400)
@mock.patch("flask.redirect")
def test_GET_approve_with_valid_token_redirects(self, mock_redirect):
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
approval_token = self.registration.embargo.approval_state[self.user._id]["approval_token"]
self.app.get(self.registration.web_url_for("view_project", token=approval_token), auth=self.user.auth)
self.registration.embargo.reload()
assert_true(self.registration.embargo_end_date)
assert_false(self.registration.is_pending_embargo)
assert_true(mock_redirect.called_with(self.registration.web_url_for("view_project")))
def test_GET_from_unauthorized_user_returns_HTTPForbidden(self):
unauthorized_user = AuthUserFactory()
res = self.app.get(
self.registration.web_url_for("view_project", token=DUMMY_TOKEN),
auth=unauthorized_user.auth,
expect_errors=True,
)
assert_equal(res.status_code, 403)
def test_GET_disapprove_registration_without_embargo_HTTPBad_Request(self):
assert_false(self.registration.is_pending_embargo)
res = self.app.get(
self.registration.web_url_for("view_project", token=DUMMY_TOKEN), auth=self.user.auth, expect_errors=True
)
assert_equal(res.status_code, 400)
def test_GET_disapprove_with_invalid_token_returns_HTTPBad_Request(self):
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
#.........这里部分代码省略.........
示例9: RegistrationEmbargoModelsTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [as 别名]
class RegistrationEmbargoModelsTestCase(OsfTestCase):
def setUp(self):
super(RegistrationEmbargoModelsTestCase, self).setUp()
self.user = UserFactory()
self.project = ProjectFactory(creator=self.user)
self.registration = RegistrationFactory(project=self.project)
self.embargo = EmbargoFactory(user=self.user)
self.valid_embargo_end_date = datetime.datetime.utcnow() + datetime.timedelta(days=3)
# Node#_initiate_embargo tests
def test__initiate_embargo_saves_embargo(self):
initial_count = Embargo.find().count()
self.registration._initiate_embargo(self.user, self.valid_embargo_end_date, for_existing_registration=True)
assert_equal(Embargo.find().count(), initial_count + 1)
def test__initiate_embargo_does_not_create_tokens_for_unregistered_admin(self):
unconfirmed_user = UnconfirmedUserFactory()
self.registration.contributors.append(unconfirmed_user)
self.registration.add_permission(unconfirmed_user, "admin", save=True)
assert_true(self.registration.has_permission(unconfirmed_user, "admin"))
embargo = self.registration._initiate_embargo(
self.user, self.valid_embargo_end_date, for_existing_registration=True
)
assert_true(self.user._id in embargo.approval_state)
assert_false(unconfirmed_user._id in embargo.approval_state)
def test__initiate_embargo_with_save_does_save_embargo(self):
initial_count = Embargo.find().count()
self.registration._initiate_embargo(self.user, self.valid_embargo_end_date, for_existing_registration=True)
assert_equal(Embargo.find().count(), initial_count + 1)
# Backref tests
def test_embargo_initiator_has_backref(self):
self.registration.embargo_registration(self.user, self.valid_embargo_end_date)
self.registration.save()
self.registration.reload()
assert_equal(len(self.user.embargo__embargoed), Embargo.find(Q("initiated_by", "eq", self.user)).count())
# Node#embargo_registration tests
def test_embargo_from_non_admin_raises_PermissionsError(self):
self.registration.remove_permission(self.user, "admin")
self.registration.save()
self.registration.reload()
with assert_raises(PermissionsError):
self.registration.embargo_registration(self.user, self.valid_embargo_end_date)
def test_embargo_end_date_in_past_raises_ValidationValueError(self):
with assert_raises(ValidationValueError):
self.registration.embargo_registration(self.user, datetime.datetime(1999, 1, 1))
def test_embargo_end_date_today_raises_ValidationValueError(self):
with assert_raises(ValidationValueError):
self.registration.embargo_registration(self.user, datetime.datetime.utcnow())
def test_embargo_end_date_in_far_future_raises_ValidationValueError(self):
with assert_raises(ValidationValueError):
self.registration.embargo_registration(self.user, datetime.datetime(2099, 1, 1))
def test_embargo_with_valid_end_date_starts_pending_embargo(self):
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
def test_embargo_public_project_makes_private_pending_embargo(self):
self.registration.is_public = True
assert_true(self.registration.is_public)
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
assert_false(self.registration.is_public)
def test_embargo_non_registration_raises_NodeStateError(self):
self.registration.is_registration = False
self.registration.save()
with assert_raises(NodeStateError):
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
assert_false(self.registration.is_pending_embargo)
# Embargo#approve_embargo tests
def test_invalid_approval_token_raises_InvalidSanctionApprovalToken(self):
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
invalid_approval_token = "not a real token"
with assert_raises(InvalidSanctionApprovalToken):
self.registration.embargo.approve_embargo(self.user, invalid_approval_token)
assert_true(self.registration.is_pending_embargo)
def test_non_admin_approval_token_raises_PermissionsError(self):
non_admin = UserFactory()
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
approval_token = self.registration.embargo.approval_state[self.user._id]["approval_token"]
with assert_raises(PermissionsError):
self.registration.embargo.approve_embargo(non_admin, approval_token)
assert_true(self.registration.is_pending_embargo)
#.........这里部分代码省略.........
示例10: RegistrationWithChildNodesRetractionModelTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [as 别名]
class RegistrationWithChildNodesRetractionModelTestCase(OsfTestCase):
def setUp(self):
super(RegistrationWithChildNodesRetractionModelTestCase, self).setUp()
self.user = AuthUserFactory()
self.auth = self.user.auth
self.project = ProjectFactory(is_public=True, 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, is_public=True)
# Reload the registration; else tests won't catch failures to svae
self.registration.reload()
def test_approval_retracts_descendant_nodes(self):
# Initiate retraction for parent registration
self.registration.retract_registration(self.user)
self.registration.save()
assert_true(self.registration.is_pending_retraction)
# Ensure descendant nodes are pending registration
descendants = self.registration.get_descendants_recursive()
for node in descendants:
node.save()
assert_true(node.is_pending_retraction)
# Approve parent registration's retraction
approval_token = self.registration.retraction.approval_state[self.user._id]['approval_token']
self.registration.retraction.approve_retraction(self.user, approval_token)
assert_true(self.registration.is_retracted)
# Ensure descendant nodes are retracted
descendants = self.registration.get_descendants_recursive()
for node in descendants:
assert_true(node.is_retracted)
def test_disapproval_cancels_retraction_on_descendant_nodes(self):
# Initiate retraction for parent registration
self.registration.retract_registration(self.user)
self.registration.save()
assert_true(self.registration.is_pending_retraction)
# Ensure descendant nodes are pending registration
descendants = self.registration.get_descendants_recursive()
for node in descendants:
node.save()
assert_true(node.is_pending_retraction)
# Disapprove parent registration's retraction
rejection_token = self.registration.retraction.approval_state[self.user._id]['rejection_token']
self.registration.retraction.disapprove_retraction(self.user, rejection_token)
assert_false(self.registration.is_pending_retraction)
assert_false(self.registration.is_retracted)
assert_true(self.registration.retraction.is_rejected)
# Ensure descendant nodes' retractions are cancelled
descendants = self.registration.get_descendants_recursive()
for node in descendants:
assert_false(node.is_pending_retraction)
assert_false(node.is_retracted)
def test_approval_cancels_pending_embargoes_on_descendant_nodes(self):
# Initiate embargo for registration
self.registration.embargo_registration(
self.user,
datetime.datetime.utcnow() + datetime.timedelta(days=10),
for_existing_registration=True
)
self.registration.save()
assert_true(self.registration.is_pending_embargo)
# Initiate retraction for parent registration
self.registration.retract_registration(self.user)
self.registration.save()
assert_true(self.registration.is_pending_retraction)
# Ensure descendant nodes are pending embargo
descendants = self.registration.get_descendants_recursive()
for node in descendants:
assert_true(node.is_pending_retraction)
assert_true(node.is_pending_embargo)
# Approve parent registration's retraction
approval_token = self.registration.retraction.approval_state[self.user._id]['approval_token']
self.registration.retraction.approve_retraction(self.user, approval_token)
assert_true(self.registration.is_retracted)
assert_false(self.registration.is_pending_embargo)
# Ensure descendant nodes are not pending embargo
#.........这里部分代码省略.........
示例11: RegistrationEmbargoModelsTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [as 别名]
class RegistrationEmbargoModelsTestCase(OsfTestCase):
def setUp(self):
super(RegistrationEmbargoModelsTestCase, self).setUp()
self.user = UserFactory()
self.project = ProjectFactory(creator=self.user)
self.registration = RegistrationFactory(project=self.project)
self.embargo = EmbargoFactory(user=self.user)
self.valid_embargo_end_date = datetime.datetime.utcnow() + datetime.timedelta(days=3)
# Node#_initiate_embargo tests
def test__initiate_embargo_saves_embargo(self):
initial_count = Embargo.find().count()
self.registration._initiate_embargo(
self.user,
self.valid_embargo_end_date,
for_existing_registration=True
)
assert_equal(Embargo.find().count(), initial_count + 1)
def test_state_can_be_set_to_complete(self):
embargo = EmbargoFactory()
embargo.state = Embargo.COMPLETED
embargo.save() # should pass validation
assert_equal(embargo.state, Embargo.COMPLETED)
def test__initiate_embargo_does_not_create_tokens_for_unregistered_admin(self):
unconfirmed_user = UnconfirmedUserFactory()
self.registration.contributors.append(unconfirmed_user)
self.registration.add_permission(unconfirmed_user, 'admin', save=True)
assert_true(self.registration.has_permission(unconfirmed_user, 'admin'))
embargo = self.registration._initiate_embargo(
self.user,
self.valid_embargo_end_date,
for_existing_registration=True
)
assert_true(self.user._id in embargo.approval_state)
assert_false(unconfirmed_user._id in embargo.approval_state)
def test__initiate_embargo_adds_admins_on_child_nodes(self):
project_admin = UserFactory()
project_non_admin = UserFactory()
child_admin = UserFactory()
child_non_admin = UserFactory()
grandchild_admin = UserFactory()
project = ProjectFactory(creator=project_admin)
project.add_contributor(project_non_admin, auth=Auth(project.creator), save=True)
child = NodeFactory(creator=child_admin, parent=project)
child.add_contributor(child_non_admin, auth=Auth(project.creator), save=True)
grandchild = NodeFactory(creator=grandchild_admin, parent=child) # noqa
embargo = project._initiate_embargo(
project.creator,
self.valid_embargo_end_date,
for_existing_registration=True
)
assert_in(project_admin._id, embargo.approval_state)
assert_in(child_admin._id, embargo.approval_state)
assert_in(grandchild_admin._id, embargo.approval_state)
assert_not_in(project_non_admin._id, embargo.approval_state)
assert_not_in(child_non_admin._id, embargo.approval_state)
def test__initiate_embargo_with_save_does_save_embargo(self):
initial_count = Embargo.find().count()
self.registration._initiate_embargo(
self.user,
self.valid_embargo_end_date,
for_existing_registration=True,
)
assert_equal(Embargo.find().count(), initial_count + 1)
# Backref tests
def test_embargo_initiator_has_backref(self):
self.registration.embargo_registration(
self.user,
self.valid_embargo_end_date
)
self.registration.save()
self.registration.reload()
assert_equal(len(self.user.embargo__embargoed),
Embargo.find(Q('initiated_by', 'eq', self.user)).count())
# Node#embargo_registration tests
def test_embargo_from_non_admin_raises_PermissionsError(self):
self.registration.remove_permission(self.user, 'admin')
self.registration.save()
self.registration.reload()
with assert_raises(PermissionsError):
self.registration.embargo_registration(self.user, self.valid_embargo_end_date)
def test_embargo_end_date_in_past_raises_ValidationValueError(self):
with assert_raises(ValidationValueError):
self.registration.embargo_registration(
self.user,
datetime.datetime(1999, 1, 1)
)
#.........这里部分代码省略.........
示例12: RegistrationEmbargoViewsTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [as 别名]
#.........这里部分代码省略.........
@mock.patch('framework.celery_tasks.handlers.enqueue_task')
def test_POST_invalid_embargo_end_date_returns_HTTPBad_Request(self, mock_enqueue):
res = self.app.post(
self.project.api_url_for('register_draft_registration', draft_id=self.draft._id),
self.invalid_embargo_date_payload,
content_type='application/json',
auth=self.user.auth,
expect_errors=True
)
assert_equal(res.status_code, 400)
@mock.patch('framework.celery_tasks.handlers.enqueue_task')
def test_valid_POST_embargo_adds_to_parent_projects_log(self, mock_enquque):
initial_project_logs = len(self.project.logs)
self.app.post(
self.project.api_url_for('register_draft_registration', draft_id=self.draft._id),
self.valid_embargo_payload,
content_type='application/json',
auth=self.user.auth
)
self.project.reload()
# Logs: Created, registered, embargo initiated
assert_equal(len(self.project.logs), initial_project_logs + 1)
@mock.patch('website.project.sanctions.TokenApprovableSanction.ask')
def test_embargoed_registration_set_privacy_requests_embargo_termination(self, mock_ask):
# Initiate and approve embargo
for i in range(3):
c = AuthUserFactory()
self.registration.add_contributor(c, [permissions.ADMIN], auth=Auth(self.user))
self.registration.save()
self.registration.embargo_registration(
self.user,
datetime.datetime.utcnow() + datetime.timedelta(days=10)
)
for user_id, embargo_tokens in self.registration.embargo.approval_state.iteritems():
approval_token = embargo_tokens['approval_token']
self.registration.embargo.approve_embargo(User.load(user_id), approval_token)
self.registration.save()
res = self.app.post(
self.registration.api_url_for('project_set_privacy', permissions='public'),
auth=self.user.auth,
)
assert_equal(res.status_code, 200)
for reg in self.registration.node_and_primary_descendants():
reg.reload()
assert_false(reg.is_public)
assert_true(reg.embargo_termination_approval)
assert_true(reg.embargo_termination_approval.is_pending_approval)
def test_cannot_request_termination_on_component_of_embargo(self):
node = ProjectFactory()
child = ProjectFactory(parent=node, creator=node.creator)
with utils.mock_archive(node, embargo=True, autocomplete=True, autoapprove=True) as reg:
with assert_raises(NodeStateError):
reg.nodes[0].request_embargo_termination(Auth(node.creator))
@mock.patch('website.mails.send_mail')
def test_embargoed_registration_set_privacy_sends_mail(self, mock_send_mail):
"""
Integration test for https://github.com/CenterForOpenScience/osf.io/pull/5294#issuecomment-212613668
"""
示例13: TestRetractRegistrations
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [as 别名]
class TestRetractRegistrations(OsfTestCase):
def setUp(self):
super(TestRetractRegistrations, self).setUp()
self.user = UserFactory()
self.registration = RegistrationFactory(creator=self.user)
self.registration.embargo_registration(
self.user,
datetime.utcnow() + timedelta(days=10)
)
self.registration.save()
def test_new_embargo_should_be_unapproved(self):
assert_true(self.registration.is_pending_embargo)
assert_false(self.registration.embargo_end_date)
main(dry_run=False)
assert_true(self.registration.is_pending_embargo)
assert_false(self.registration.embargo_end_date)
def test_should_not_activate_pending_embargo_less_than_48_hours_old(self):
# Embargo#iniation_date is read only
self.registration.embargo._fields['initiation_date'].__set__(
self.registration.embargo,
(datetime.utcnow() - timedelta(hours=47)),
safe=True
)
self.registration.embargo.save()
assert_false(self.registration.embargo_end_date)
main(dry_run=False)
assert_false(self.registration.embargo_end_date)
def test_should_activate_pending_embargo_that_is_48_hours_old(self):
# Embargo#iniation_date is read only
self.registration.embargo._fields['initiation_date'].__set__(
self.registration.embargo,
(datetime.utcnow() - timedelta(hours=48)),
safe=True
)
self.registration.embargo.save()
assert_true(self.registration.is_pending_embargo)
assert_false(self.registration.embargo_end_date)
main(dry_run=False)
assert_false(self.registration.is_pending_embargo)
assert_true(self.registration.embargo_end_date)
def test_should_activate_pending_embargo_more_than_48_hours_old(self):
# Embargo#iniation_date is read only
self.registration.embargo._fields['initiation_date'].__set__(
self.registration.embargo,
(datetime.utcnow() - timedelta(days=365)),
safe=True
)
self.registration.embargo.save()
assert_true(self.registration.is_pending_embargo)
assert_false(self.registration.embargo_end_date)
main(dry_run=False)
assert_false(self.registration.is_pending_embargo)
assert_true(self.registration.embargo_end_date)
def test_embargo_past_end_date_should_be_completed(self):
approval_token = self.registration.embargo.approval_state[self.user._id]['approval_token']
self.registration.embargo.approve_embargo(self.user, approval_token)
self.registration.save()
assert_true(self.registration.embargo_end_date)
assert_false(self.registration.is_pending_embargo)
# Embargo#iniation_date is read only
self.registration.embargo._fields['end_date'].__set__(
self.registration.embargo,
(datetime.utcnow() - timedelta(days=1)),
safe=True
)
self.registration.embargo.save()
assert_false(self.registration.is_public)
main(dry_run=False)
assert_true(self.registration.is_public)
assert_false(self.registration.embargo_end_date)
assert_false(self.registration.is_pending_embargo)
assert_equal(self.registration.embargo.state, 'completed')
def test_embargo_before_end_date_should_not_be_completed(self):
approval_token = self.registration.embargo.approval_state[self.user._id]['approval_token']
self.registration.embargo.approve_embargo(self.user, approval_token)
self.registration.save()
assert_true(self.registration.embargo_end_date)
assert_false(self.registration.is_pending_embargo)
# Embargo#iniation_date is read only
self.registration.embargo._fields['end_date'].__set__(
self.registration.embargo,
(datetime.utcnow() + timedelta(days=1)),
safe=True
)
self.registration.embargo.save()
#.........这里部分代码省略.........
示例14: RegistrationRetractionViewsTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [as 别名]
class RegistrationRetractionViewsTestCase(OsfTestCase):
def setUp(self):
super(RegistrationRetractionViewsTestCase, self).setUp()
self.user = AuthUserFactory()
self.auth = self.user.auth
self.registration = RegistrationFactory(creator=self.user, is_public=True)
self.retraction_post_url = self.registration.api_url_for('node_registration_retraction_post')
self.retraction_get_url = self.registration.web_url_for('node_registration_retraction_get')
self.justification = fake.sentence()
def test_GET_retraction_page_when_pending_retraction_returns_HTTPBad_Request(self):
self.registration.retract_registration(self.user)
self.registration.save()
res = self.app.get(
self.retraction_get_url,
auth=self.auth,
expect_errors=True,
)
assert_equal(res.status_code, 400)
def test_POST_retraction_to_private_registration_returns_HTTPBad_request(self):
self.registration.is_public = False
self.registration.save()
res = self.app.post_json(
self.retraction_post_url,
auth=self.auth,
expect_errors=True,
)
assert_equal(res.status_code, 400)
self.registration.reload()
assert_is_none(self.registration.retraction)
# https://trello.com/c/bYyt6nYT/89-clicking-retract-registration-with-unregistered-users-as-project-admins-gives-500-error
@mock.patch('website.project.views.register.mails.send_mail')
def test_POST_retraction_does_not_send_email_to_unregistered_admins(self, mock_send_mail):
unreg = UnregUserFactory()
self.registration.add_contributor(
unreg,
auth=Auth(self.user),
permissions=('read', 'write', 'admin')
)
self.registration.save()
self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.auth,
)
# Only the creator gets an email; the unreg user does not get emailed
assert_equal(mock_send_mail.call_count, 1)
def test_POST_pending_embargo_returns_HTTPBad_request(self):
self.registration.embargo_registration(
self.user,
(datetime.datetime.utcnow() + datetime.timedelta(days=10)),
for_existing_registration=True
)
self.registration.save()
assert_true(self.registration.pending_embargo)
res = self.app.post_json(
self.retraction_post_url,
auth=self.auth,
expect_errors=True,
)
assert_equal(res.status_code, 400)
self.registration.reload()
assert_is_none(self.registration.retraction)
def test_POST_retraction_by_non_admin_retract_HTTPUnauthorized(self):
res = self.app.post_json(self.retraction_post_url, expect_errors=True)
assert_equals(res.status_code, 401)
self.registration.reload()
assert_is_none(self.registration.retraction)
def test_POST_retraction_without_justification_returns_HTTPOK(self):
res = self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.auth,
)
assert_equal(res.status_code, 200)
self.registration.reload()
assert_false(self.registration.retraction.is_retracted)
assert_equal(self.registration.retraction.state, Retraction.PENDING)
assert_is_none(self.registration.retraction.justification)
def test_valid_POST_retraction_adds_to_parent_projects_log(self):
initial_project_logs = len(self.registration.registered_from.logs)
self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.auth,
)
self.registration.registered_from.reload()
# Logs: Created, registered, retraction initiated
assert_equal(len(self.registration.registered_from.logs), initial_project_logs + 1)
示例15: RegistrationEmbargoViewsTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import embargo_registration [as 别名]
#.........这里部分代码省略.........
assert_false(node.is_public)
@mock.patch("framework.tasks.handlers.enqueue_task")
def test_POST_register_embargo_is_not_public(self, mock_enqueue):
res = self.app.post(
self.project.api_url_for("node_register_template_page_post", template=u"Open-Ended_Registration"),
self.valid_embargo_payload,
content_type="application/json",
auth=self.user.auth,
)
assert_equal(res.status_code, 201)
registration = Node.find().sort("-registered_date")[0]
assert_true(registration.is_registration)
assert_false(registration.is_public)
assert_true(registration.is_pending_embargo_for_existing_registration)
assert_is_not_none(registration.embargo)
# Regression test for https://openscience.atlassian.net/browse/OSF-5071
@mock.patch("framework.tasks.handlers.enqueue_task")
def test_POST_register_embargo_does_not_make_project_or_children_public(self, mock_enqueue):
public_project = ProjectFactory(creator=self.user, is_public=True)
component = NodeFactory(creator=self.user, parent=public_project, title="Component", is_public=True)
subproject = ProjectFactory(creator=self.user, parent=public_project, title="Subproject", is_public=True)
subproject_component = NodeFactory(creator=self.user, parent=subproject, title="Subcomponent", is_public=True)
res = self.app.post(
public_project.api_url_for("node_register_template_page_post", template=u"Open-Ended_Registration"),
self.valid_embargo_payload,
content_type="application/json",
auth=self.user.auth,
)
public_project.reload()
assert_equal(res.status_code, 201)
# Last node directly registered from self.project
registration = Node.load(public_project.node__registrations[-1])
assert_true(registration.is_registration)
assert_false(registration.is_public)
assert_true(registration.is_pending_embargo_for_existing_registration)
assert_is_not_none(registration.embargo)
for node in registration.get_descendants_recursive():
assert_true(node.is_registration)
assert_false(node.is_public)
@mock.patch("framework.tasks.handlers.enqueue_task")
def test_POST_invalid_embargo_end_date_returns_HTTPBad_Request(self, mock_enqueue):
res = self.app.post(
self.project.api_url_for("node_register_template_page_post", template=u"Open-Ended_Registration"),
self.invalid_embargo_date_payload,
content_type="application/json",
auth=self.user.auth,
expect_errors=True,
)
assert_equal(res.status_code, 400)
@mock.patch("framework.tasks.handlers.enqueue_task")
def test_valid_POST_embargo_adds_to_parent_projects_log(self, mock_enquque):
initial_project_logs = len(self.project.logs)
res = self.app.post(
self.project.api_url_for("node_register_template_page_post", template=u"Open-Ended_Registration"),
self.valid_embargo_payload,
content_type="application/json",
auth=self.user.auth,
)
self.project.reload()
# Logs: Created, registered, embargo initiated
assert_equal(len(self.project.logs), initial_project_logs + 1)
def test_non_contributor_GET_approval_returns_HTTPError(self):
non_contributor = AuthUserFactory()
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
approval_token = self.registration.embargo.approval_state[self.user._id]["approval_token"]
approval_url = self.registration.web_url_for("view_project", token=approval_token)
res = self.app.get(approval_url, auth=non_contributor.auth, expect_errors=True)
assert_equal(http.FORBIDDEN, res.status_code)
assert_true(self.registration.is_pending_embargo)
assert_false(self.registration.embargo_end_date)
def test_non_contributor_GET_disapproval_returns_HTTPError(self):
non_contributor = AuthUserFactory()
self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
self.registration.save()
assert_true(self.registration.is_pending_embargo)
rejection_token = self.registration.embargo.approval_state[self.user._id]["rejection_token"]
approval_url = self.registration.web_url_for("view_project", token=rejection_token)
res = self.app.get(approval_url, auth=non_contributor.auth, expect_errors=True)
assert_equal(http.FORBIDDEN, res.status_code)
assert_true(self.registration.is_pending_embargo)
assert_false(self.registration.embargo_end_date)