1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2011 Jeremy Kerr <jk@ozlabs.org>
4 # This file is part of the Patchwork package.
6 # Patchwork is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # Patchwork is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Patchwork; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 from django.test import TestCase
22 from django.contrib.auth.models import User
23 from django.core.urlresolvers import reverse
24 from patchwork.models import EmailConfirmation, Person
26 def _confirmation_url(conf):
27 return reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
29 class TestUser(object):
31 email = 'test@example.com'
32 secondary_email = 'test2@example.com'
36 self.password = User.objects.make_random_password()
37 self.user = User.objects.create_user(self.username,
38 self.email, self.password)
40 class InvalidConfirmationTest(TestCase):
42 EmailConfirmation.objects.all().delete()
43 Person.objects.all().delete()
44 self.user = TestUser()
45 self.conf = EmailConfirmation(type = 'userperson',
46 email = self.user.secondary_email,
47 user = self.user.user)
50 def testInactiveConfirmation(self):
51 self.conf.active = False
53 response = self.client.get(_confirmation_url(self.conf))
54 self.assertEquals(response.status_code, 200)
55 self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
56 self.assertEqual(response.context['error'], 'inactive')
57 self.assertEqual(response.context['conf'], self.conf)
59 def testExpiredConfirmation(self):
60 self.conf.date -= self.conf.validity
62 response = self.client.get(_confirmation_url(self.conf))
63 self.assertEquals(response.status_code, 200)
64 self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
65 self.assertEqual(response.context['error'], 'expired')
66 self.assertEqual(response.context['conf'], self.conf)