]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/tests/test_confirm.py
tox: Add tox.ini file
[patchwork] / apps / 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 import unittest
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
25
26 def _confirmation_url(conf):
27     return reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
28
29 class TestUser(object):
30     username = 'testuser'
31     email = 'test@example.com'
32     secondary_email = 'test2@example.com'
33     password = None
34
35     def __init__(self):
36         self.password = User.objects.make_random_password()
37         self.user = User.objects.create_user(self.username,
38                             self.email, self.password)
39
40 class InvalidConfirmationTest(TestCase):
41     def setUp(self):
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)
48         self.conf.save()
49
50     def testInactiveConfirmation(self):
51         self.conf.active = False
52         self.conf.save()
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)
58
59     def testExpiredConfirmation(self):
60         self.conf.date -= self.conf.validity
61         self.conf.save()
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)
67