Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
Added tests for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
wunki committed Aug 1, 2010
1 parent b9350d6 commit e89b4dc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ echo "Running test suite with coverage report at the end"
echo -e "( would require coverage python package to be installed )\n"

coverage run setup.py test
coverage report -m userena/*.py
coverage report -m userena/*.py userena/management/commands/*py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
class Command(NoArgsCommand):
"""
Search for users that still haven't verified their e-mail address after
``USERENA_VERIFICATION_DAYS`` and delete them.
``USERENA_ACTIVATION_DAYS`` and delete them.
"""
help = 'Deletes expired users.'
def handle_noargs(self, **options):
users = Account.objects.delete_expired_users()
print "Deleted %(amount)s user(s)." % {'amount': len(users)}
15 changes: 0 additions & 15 deletions userena/management/commands/notifyexpired.py

This file was deleted.

1 change: 1 addition & 0 deletions userena/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from userena.tests.backends import *
from userena.tests.commands import *
from userena.tests.decorators import *
from userena.tests.forms import *
from userena.tests.managers import *
Expand Down
31 changes: 31 additions & 0 deletions userena/tests/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.test import TestCase
from django.core.management import call_command

from userena.models import Account
from userena import settings as userena_settings

import datetime

class CleanExpiredTests(TestCase):
user_info = {'username': 'alice',
'password': 'swordfish',
'email': 'alice@example.com'}

def test_clean_expired(self):
"""
Test if ``clean_expired`` deletes all users which ``activation_key``
is expired.
"""
# Create an account which is expired.
account = Account.objects.create_inactive_user(**self.user_info).account
account.activation_key_created -= datetime.timedelta(days=userena_settings.USERENA_ACTIVATION_DAYS + 1)
account.save()

# There should be one account now
Account.objects.get(user__username=self.user_info['username'])

# Clean it.
call_command('clean_expired')

self.failUnlessEqual(Account.objects.filter(user__username=self.user_info['username']).count(), 0)

0 comments on commit e89b4dc

Please sign in to comment.