本文整理汇总了Python中accounts.factories.UserFactory.invite_new_user方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.invite_new_user方法的具体用法?Python UserFactory.invite_new_user怎么用?Python UserFactory.invite_new_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.invite_new_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UserModelTest
# 需要导入模块: from accounts.factories import UserFactory [as 别名]
# 或者: from accounts.factories.UserFactory import invite_new_user [as 别名]
class UserModelTest(TestCase):
fixtures = ['group_perms']
def setUp(self):
self.moderator = ModeratorFactory()
self.standard_user = UserFactory(
first_name='Firsto',
last_name='Namo',
)
self.invited_pending = InvitedPendingFactory()
self.requested_pending = RequestedPendingFactory()
def test_string_method(self):
self.assertEqual(self.standard_user.__str__(), 'Firsto Namo')
def test_get_full_name(self):
full_name = self.standard_user.get_full_name()
self.assertEqual(full_name, 'Firsto Namo')
def test_get_short_name(self):
short_name = self.standard_user.get_short_name()
self.assertEqual(short_name, 'Firsto')
def test_is_pending_activation(self):
self.assertFalse(self.standard_user.is_pending_activation())
self.assertTrue(self.invited_pending.is_pending_activation())
def test_is_invited_pending_activation(self):
self.assertFalse(self.standard_user.is_invited_pending_activation())
self.assertTrue(self.invited_pending.is_invited_pending_activation())
def test_is_pending_approval(self):
self.assertFalse(self.standard_user.is_pending_approval())
self.assertTrue(self.requested_pending.is_pending_approval())
def test_moderator_can_invite_new_user(self):
user = self.moderator.invite_new_user(email='standard_u[email protected]',
first_name='standard_user',
last_name='user')
self.assertEqual(user.email,'[email protected]')
self.assertEqual(user.first_name, 'standard_user')
self.assertEqual(user.last_name, 'user')
self.assertEqual(user.registration_method, CustomUser.INVITED)
self.assertEqual(user.moderator, self.moderator)
self.assertEqual(user.moderator_decision, CustomUser.PRE_APPROVED)
self.assertIsNotNone(user.decision_datetime)
self.assertIsNotNone(user.auth_token)
def test_standard_user_user_cannot_invite_new_user(self):
with self.assertRaises(PermissionDenied):
user = self.standard_user.invite_new_user(
email='[email protected]',
first_name='standard_user',
last_name='user'
)
def test_moderator_can_reinvite_user(self):
decision_datetime = self.invited_pending.decision_datetime
auth_token = self.invited_pending.auth_token
self.moderator.reinvite_user(user=self.invited_pending,
email='[email protected]')
self.assertEqual(self.invited_pending.email, '[email protected]')
self.assertNotEqual(self.invited_pending.decision_datetime, decision_datetime)
self.assertNotEqual(self.invited_pending.auth_token, auth_token)
def test_standard_user_user_cannot_reinvite_user(self):
decision_datetime = self.invited_pending.decision_datetime
auth_token = self.invited_pending.auth_token
with self.assertRaises(PermissionDenied):
self.standard_user.reinvite_user(user=self.invited_pending,
email='[email protected]')
def test_moderator_can_approve_user_application(self):
self.moderator.approve_user_application(self.requested_pending)
self.assertEqual(self.requested_pending.moderator, self.moderator)
self.assertEqual(self.requested_pending.moderator_decision, CustomUser.APPROVED)
self.assertIsNotNone(self.requested_pending.decision_datetime)
self.assertIsNotNone(self.requested_pending.auth_token)
def test_standard_user_user_cannot_approve_user_application(self):
with self.assertRaises(PermissionDenied):
self.standard_user.approve_user_application(self.requested_pending)
def test_moderator_can_reject_user_application(self):
self.moderator.reject_user_application(self.requested_pending)
self.assertEqual(self.requested_pending.moderator, self.moderator)
self.assertEqual(self.requested_pending.moderator_decision, CustomUser.REJECTED)
self.assertIsNotNone(self.requested_pending.decision_datetime)
self.assertIsNotNone(self.requested_pending.auth_token)
def test_standard_user_user_cannot_reject_user_application(self):
with self.assertRaises(PermissionDenied):
#.........这里部分代码省略.........