Пример #1
0
 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()))
Пример #2
0
    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())