Exemple #1
0
 def setUp(self):
     self.moderator = ModeratorFactory()
     self.standard_user = UserFactory(
         full_name='Firsto Namo',
     )
     self.invited_pending = InvitedPendingFactory()
     self.requested_pending = RequestedPendingFactory()
Exemple #2
0
    def setUp(self):
        self.moderator = ModeratorFactory()
        self.another_moderator = ModeratorFactory()

        self.invited_user = InvitedPendingFactory(
            email='*****@*****.**',
            moderator=self.moderator,
        )

        self.user_invited_by_another_moderator = InvitedPendingFactory(
            moderator=self.another_moderator, )

        self.requested_user = RequestedPendingFactory(
            moderator=self.moderator, )
Exemple #3
0
class UserModelTest(TestCase):
    fixtures = ['group_perms']

    def setUp(self):
        self.moderator = ModeratorFactory()
        self.standard_user = UserFactory(
            full_name='Firsto 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='*****@*****.**',
                                              full_name='standard_user user')

        self.assertEqual(user.email, '*****@*****.**')
        self.assertEqual(user.full_name, 'standard_user 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):
            self.standard_user.invite_new_user(
                email='*****@*****.**',
                full_name='standard_user 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='*****@*****.**')

        self.assertEqual(self.invited_pending.email, '*****@*****.**')
        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):
        with self.assertRaises(PermissionDenied):
            self.standard_user.reinvite_user(user=self.invited_pending,
                                             email='*****@*****.**')

    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):
            self.standard_user.reject_user_application(self.requested_pending)
Exemple #4
0
def impl(context):
    context.pending_user = RequestedPendingFactory(
        full_name='Pending Approval', email='*****@*****.**')