Source

django-confirmation / confirmation / tests / tests.py

Full commit
import datetime

from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django.test import Client, TestCase
from django.conf import settings

import confirmation
from confirmation.views import confirmation_verify
from confirmation.models import Confirmation


ACTIVATION_TYPE = 1

class RegistrationTest(TestCase):

    def setUp(self):
        confirmation.settings.CONFIRMATION_RAISE_404 = False
        confirmation.settings.CONFIRMATION_DAYS_LIMIT = 30
        self.user = User.objects.create_user("test", "email@admin.com")
        self.client = Client()
        self.url = reverse('confirmation')

    def test_create_confirmation(self):
        Confirmation.objects.create(self.user, ACTIVATION_TYPE, "Please activate your account")
        self.failUnlessEqual(Confirmation.objects.count(), 1)

    def test_delete_confirmation(self):
        Confirmation.objects.create(self.user, ACTIVATION_TYPE, "Please activate your account")
        confirm = Confirmation.objects.all()[0]
        response = self.client.get("%s?key=%s&type=%s" % (self.url, confirm.key, ACTIVATION_TYPE))
        self.failUnlessEqual(Confirmation.objects.count(), 0)

    def test_redirect_confirmation(self):
        confirm = Confirmation.objects.create(self.user, ACTIVATION_TYPE, "Please activate your account", "/")
        response = self.client.get("%s?key=%s&type=%s" % (self.url, confirm.key, ACTIVATION_TYPE))
        self.failUnlessEqual(response.status_code, 302)
        
    def test_old_confirmation(self):
        confirm = Confirmation.objects.create(self.user, ACTIVATION_TYPE, "Please activate your account")
        confirm.date = datetime.datetime(2008, 9, 1, 20, 25)
        confirm.save()
        response = self.client.get("%s?key=%s&type=%s" % (self.url, confirm.key, ACTIVATION_TYPE))
        self.failUnlessEqual(Confirmation.objects.count(), 1)