def monkey_sender(request, subject, template_name, context, email): self.assertEqual(request, req) self.assertEqual(email, [self.user.email, ]) activation_token = UserActivationTokenGenerator() token = activation_token.generate(self.user) self.assertDictEqual(context, {'token': token, 'user_id': self.user.pk}) self.assertEqual(subject, _("User activation")) self.assertEqual(template_name, 'spirit/user/activation_email.html') self._monkey_sender_called = True
def test_user_activation_token_generator(self): """ Validate if user can be activated """ activation_token = UserActivationTokenGenerator() token = activation_token.generate(self.user) self.assertTrue(activation_token.is_valid(self.user, token)) self.assertFalse(activation_token.is_valid(self.user, "bad token")) # Invalid for different user user2 = test_utils.create_user() self.assertFalse(activation_token.is_valid(user2, token)) # Invalid after login test_utils.login(self) user = test_utils.User.objects.get(pk=self.user.pk) self.assertFalse(activation_token.is_valid(user, token))
def test_user_activation_token_generator(self): """ Validate if user can be activated """ self.user.is_verified = False activation_token = UserActivationTokenGenerator() token = activation_token.generate(self.user) self.assertTrue(activation_token.is_valid(self.user, token)) self.assertFalse(activation_token.is_valid(self.user, "bad token")) # Invalid after verification self.user.is_verified = True self.assertFalse(activation_token.is_valid(self.user, token)) # Invalid for different user user2 = test_utils.create_user() self.assertFalse(activation_token.is_valid(user2, token))