]> git.ozlabs.org Git - patchwork/blob - patchwork/tests/test_confirm.py
trivial: Remove dead imports from 'tests'
[patchwork] / patchwork / tests / test_confirm.py
1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2011 Jeremy Kerr <jk@ozlabs.org>
3 #
4 # This file is part of the Patchwork package.
5 #
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.
10 #
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.
15 #
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
19
20 from django.test import TestCase
21 from django.contrib.auth.models import User
22 from django.core.urlresolvers import reverse
23 from patchwork.models import EmailConfirmation, Person
24
25 def _confirmation_url(conf):
26     return reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
27
28 class TestUser(object):
29     username = 'testuser'
30     email = 'test@example.com'
31     secondary_email = 'test2@example.com'
32     password = None
33
34     def __init__(self):
35         self.password = User.objects.make_random_password()
36         self.user = User.objects.create_user(self.username,
37                             self.email, self.password)
38
39 class InvalidConfirmationTest(TestCase):
40     def setUp(self):
41         EmailConfirmation.objects.all().delete()
42         Person.objects.all().delete()
43         self.user = TestUser()
44         self.conf = EmailConfirmation(type = 'userperson',
45                                       email = self.user.secondary_email,
46                                       user = self.user.user)
47         self.conf.save()
48
49     def testInactiveConfirmation(self):
50         self.conf.active = False
51         self.conf.save()
52         response = self.client.get(_confirmation_url(self.conf))
53         self.assertEquals(response.status_code, 200)
54         self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
55         self.assertEqual(response.context['error'], 'inactive')
56         self.assertEqual(response.context['conf'], self.conf)
57
58     def testExpiredConfirmation(self):
59         self.conf.date -= self.conf.validity
60         self.conf.save()
61         response = self.client.get(_confirmation_url(self.conf))
62         self.assertEquals(response.status_code, 200)
63         self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
64         self.assertEqual(response.context['error'], 'expired')
65         self.assertEqual(response.context['conf'], self.conf)
66