def test_activation(self): """ Test that user activation actually activates the user and properly resets the activation key, and fails for an already-active or expired user, or an invalid key. """ # Activating a valid user returns the user. self.failUnlessEqual(RegistrationProfile.activate_user( self.sample_user.activation_key).pk, self.sample_user.pk) # The activated user must now be active. self.failUnless(User.objects.get(pk=self.sample_user.pk).is_active) # The activation key must now be reset to the "already activated" constant. self.failUnlessEqual( RegistrationProfile.objects.get(pk=self.sample_user.pk).activation_key, RegistrationProfile.ACTIVATED) # Activating an expired user returns False. self.failIf(RegistrationProfile.activate_user( self.expired_user.activation_key)) # Activating from a key that isn't a SHA1 hash returns False. self.failIf(RegistrationProfile.activate_user('foo')) # Activating from a key that doesn't exist returns False. self.failIf(RegistrationProfile.activate_user( sha.new('foo').hexdigest()))
def setUp(self): self.sample_user = RegistrationProfile.create_inactive_user( username='******', password='******', email='*****@*****.**') self.expired_user = RegistrationProfile.create_inactive_user( username='******', password='******', email='*****@*****.**') self.expired_user.date_joined -= datetime.timedelta( days=settings.ACCOUNT_ACTIVATION_DAYS + 1) self.expired_user.save()
def test_expired_user_deletion(self): """ Test that ``RegistrationProfile.objects.delete_expired_users()`` deletes only inactive users whose activation window has expired. """ RegistrationProfile.delete_expired_users() self.assertEqual(RegistrationProfile.objects.count(), 1)
def test_account_expiration_condition(self): """ Test that ``RegistrationProfile.activation_key_expired()`` returns ``True`` for expired users and for active users, and ``False`` otherwise. """ # Unexpired user returns False. self.failIf(self.sample_user.activation_key_expired()) # Expired user returns True. self.failUnless(self.expired_user.activation_key_expired()) # Activated user returns True. activated_user = RegistrationProfile.activate_user(self.sample_user.activation_key) self.failUnless(activated_user.activation_key_expired())
def handle_noargs(self, **options): RegistrationProfile.delete_expired_users()