本文整理匯總了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):
#.........這裏部分代碼省略.........