本文整理汇总了Python中tests.factories.RegistrationFactory._initiate_approval方法的典型用法代码示例。如果您正苦于以下问题:Python RegistrationFactory._initiate_approval方法的具体用法?Python RegistrationFactory._initiate_approval怎么用?Python RegistrationFactory._initiate_approval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.RegistrationFactory
的用法示例。
在下文中一共展示了RegistrationFactory._initiate_approval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__initiate_approval_adds_admins_on_child_nodes
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import _initiate_approval [as 别名]
def test__initiate_approval_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
registration = RegistrationFactory(project=project)
approval = registration._initiate_approval(registration.creator)
assert_in(project_admin._id, approval.approval_state)
assert_in(child_admin._id, approval.approval_state)
assert_in(grandchild_admin._id, approval.approval_state)
assert_not_in(project_non_admin._id, approval.approval_state)
assert_not_in(child_non_admin._id, approval.approval_state)
示例2: RegistrationApprovalModelTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import _initiate_approval [as 别名]
class RegistrationApprovalModelTestCase(OsfTestCase):
def setUp(self):
super(RegistrationApprovalModelTestCase, 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)
def test__require_approval_saves_approval(self):
initial_count = RegistrationApproval.find().count()
self.registration._initiate_approval(
self.user
)
assert_equal(RegistrationApproval.find().count(), initial_count + 1)
def test__initiate_approval_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'))
approval = self.registration._initiate_approval(
self.user
)
assert_true(self.user._id in approval.approval_state)
assert_false(unconfirmed_user._id in approval.approval_state)
def test_require_approval_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.require_approval(self.user)
def test_require_approval_non_registration_raises_NodeStateError(self):
self.registration.is_registration = False
self.registration.save()
with assert_raises(NodeStateError):
self.registration.require_approval(
self.user,
)
assert_false(self.registration.is_pending_registration)
def test_invalid_approval_token_raises_InvalidSanctionApprovalToken(self):
self.registration.require_approval(
self.user
)
self.registration.save()
assert_true(self.registration.is_pending_registration)
invalid_approval_token = 'not a real token'
with assert_raises(InvalidSanctionApprovalToken):
self.registration.registration_approval.approve(self.user, invalid_approval_token)
assert_true(self.registration.is_pending_registration)
def test_non_admin_approval_token_raises_PermissionsError(self):
non_admin = UserFactory()
self.registration.require_approval(
self.user,
)
self.registration.save()
assert_true(self.registration.is_pending_registration)
approval_token = self.registration.registration_approval.approval_state[self.user._id]['approval_token']
with assert_raises(PermissionsError):
self.registration.registration_approval.approve(non_admin, approval_token)
assert_true(self.registration.is_pending_registration)
def test_approval_adds_to_parent_projects_log(self):
initial_project_logs = len(self.registration.registered_from.logs)
self.registration.require_approval(
self.user
)
self.registration.save()
approval_token = self.registration.registration_approval.approval_state[self.user._id]['approval_token']
self.registration.registration_approval.approve(self.user, approval_token)
# adds initiated, approved, and registered logs
assert_equal(len(self.registration.registered_from.logs), initial_project_logs + 3)
def test_one_approval_with_two_admins_stays_pending(self):
admin2 = UserFactory()
self.registration.contributors.append(admin2)
self.registration.add_permission(admin2, 'admin', save=True)
self.registration.require_approval(
self.user
)
self.registration.save()
# First admin approves
approval_token = self.registration.registration_approval.approval_state[self.user._id]['approval_token']
self.registration.registration_approval.approve(self.user, approval_token)
assert_true(self.registration.is_pending_registration)
num_of_approvals = sum([val['has_approved'] for val in self.registration.registration_approval.approval_state.values()])
assert_equal(num_of_approvals, 1)
# Second admin approves
approval_token = self.registration.registration_approval.approval_state[admin2._id]['approval_token']
self.registration.registration_approval.approve(admin2, approval_token)
#.........这里部分代码省略.........