# Path: userprofiles/contrib/accountverification/models.py
# class AccountVerification(models.Model):
#     ACTIVATED = 'ALREADY_ACTIVATED'
# 
#     user = models.ForeignKey(User, unique=True, verbose_name=_('User'))
#     activation_key = models.CharField(_('Activation key'), max_length=40)
# 
#     objects = AccountVerificationManager()
# 
#     def __unicode__(self):
#         return u'Account verification: %s' % self.user
# 
#     def activation_key_expired(self):
#         expiration_date = timedelta(days=up_settings.ACCOUNT_VERIFICATION_DAYS)
#         return (self.activation_key == self.ACTIVATED
#             or (self.user.date_joined + expiration_date <= timezone.now()))
#     activation_key_expired.boolean = True
# 
#     class Meta:
#         app_label = 'userprofiles'
#         verbose_name = _('Account verification')
#         verbose_name_plural = _('Account verifications')
# 
# Path: userprofiles/settings.py
# class Settings(object):
#     def __init__(self, **kwargs):
#     def __getattr__(self, key):
# def validate_settings():


from datetime import timedelta
from django.contrib.auth.models import User
from django.test import TestCase
from userprofiles.contrib.accountverification.models import AccountVerification
from userprofiles.settings import up_settings
            days=up_settings.ACCOUNT_VERIFICATION_DAYS, seconds=1)
        user.save()

        verification = AccountVerification.objects.get(user=user)

        self.assertFalse(
            AccountVerification.objects.activate_user('wrong-pattern-format'))

        self.assertFalse(
            AccountVerification.objects.activate_user('f4a80274f851cb41ef9c20d00426d72fc4874471'))

        self.assertFalse(
            AccountVerification.objects.activate_user(verification.activation_key))

    def test_delete_expired_users(self):
        user = AccountVerification.objects.create_inactive_user(
            self.data['username'], self.data['password'], self.data['email'])

        # Test with inactive user, but not expired
        AccountVerification.objects.delete_expired_users()
        self.assertTrue(User.objects.filter(pk=user.pk).exists())

        # Test with active and not expired user
        user.is_active = True
        user.save()
        AccountVerification.objects.delete_expired_users()
        self.assertTrue(User.objects.filter(pk=user.pk).exists())

        # Test with active but expired user
        user.date_joined = user.date_joined - timedelta(

# Path: userprofiles/contrib/accountverification/models.py
# class AccountVerification(models.Model):
#     ACTIVATED = 'ALREADY_ACTIVATED'
# 
#     user = models.ForeignKey(User, unique=True, verbose_name=_('User'))
#     activation_key = models.CharField(_('Activation key'), max_length=40)
# 
#     objects = AccountVerificationManager()
# 
#     def __unicode__(self):
#         return u'Account verification: %s' % self.user
# 
#     def activation_key_expired(self):
#         expiration_date = timedelta(days=up_settings.ACCOUNT_VERIFICATION_DAYS)
#         return (self.activation_key == self.ACTIVATED
#             or (self.user.date_joined + expiration_date <= timezone.now()))
#     activation_key_expired.boolean = True
# 
#     class Meta:
#         app_label = 'userprofiles'
#         verbose_name = _('Account verification')
#         verbose_name_plural = _('Account verifications')
# 
# Path: userprofiles/settings.py
# class Settings(object):
#     def __init__(self, **kwargs):
#     def __getattr__(self, key):
# def validate_settings():


# Path: userprofiles/contrib/accountverification/tests/test_models.py
from datetime import timedelta
from django.contrib.auth.models import User
from django.test import TestCase
from userprofiles.contrib.accountverification.models import AccountVerification
from userprofiles.settings import up_settings

            days=up_settings.ACCOUNT_VERIFICATION_DAYS, seconds=1)
        user.save()

        verification = AccountVerification.objects.get(user=user)

        self.assertFalse(
            AccountVerification.objects.activate_user('wrong-pattern-format'))

        self.assertFalse(
            AccountVerification.objects.activate_user('f4a80274f851cb41ef9c20d00426d72fc4874471'))

        self.assertFalse(
            AccountVerification.objects.activate_user(verification.activation_key))

    def test_delete_expired_users(self):
        user = AccountVerification.objects.create_inactive_user(
            self.data['username'], self.data['password'], self.data['email'])

        # Test with inactive user, but not expired
        AccountVerification.objects.delete_expired_users()
        self.assertTrue(User.objects.filter(pk=user.pk).exists())

        # Test with active and not expired user
        user.is_active = True
        user.save()
        AccountVerification.objects.delete_expired_users()
        self.assertTrue(User.objects.filter(pk=user.pk).exists())

        # Test with active but expired user
        user.date_joined = user.date_joined - timedelta(

            days=up_settings.ACCOUNT_VERIFICATION_DAYS + 1)