1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2014 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
22 from django.test import TestCase
23 from django.contrib.auth.models import User
24 from patchwork.models import EmailConfirmation, Person, Patch
25 from patchwork.tests.utils import create_user, defaults
26 from patchwork.utils import do_expiry
28 class TestRegistrationExpiry(TestCase):
30 def register(self, date):
32 user.is_active = False
33 user.date_joined = user.last_login = date
36 conf = EmailConfirmation(type='registration', user=user,
43 def testOldRegistrationExpiry(self):
44 date = ((datetime.datetime.now() - EmailConfirmation.validity) -
45 datetime.timedelta(hours = 1))
46 (user, conf) = self.register(date)
50 self.assertFalse(User.objects.filter(pk = user.pk).exists())
51 self.assertFalse(EmailConfirmation.objects.filter(pk = conf.pk)
55 def testRecentRegistrationExpiry(self):
56 date = ((datetime.datetime.now() - EmailConfirmation.validity) +
57 datetime.timedelta(hours = 1))
58 (user, conf) = self.register(date)
62 self.assertTrue(User.objects.filter(pk = user.pk).exists())
63 self.assertTrue(EmailConfirmation.objects.filter(pk = conf.pk)
66 def testInactiveRegistrationExpiry(self):
67 (user, conf) = self.register(datetime.datetime.now())
69 # confirm registration
70 conf.user.is_active = True
76 self.assertTrue(User.objects.filter(pk = user.pk).exists())
77 self.assertFalse(EmailConfirmation.objects.filter(pk = conf.pk)
80 def testPatchSubmitterExpiry(self):
81 defaults.project.save()
82 defaults.patch_author_person.save()
84 # someone submits a patch...
85 patch = Patch(project = defaults.project,
86 msgid = 'test@example.com', name = 'test patch',
87 submitter = defaults.patch_author_person,
88 content = defaults.patch)
91 # ... then starts registration...
92 date = ((datetime.datetime.now() - EmailConfirmation.validity) -
93 datetime.timedelta(hours = 1))
95 user = User.objects.create_user(userid,
96 defaults.patch_author_person.email, userid)
97 user.is_active = False
98 user.date_joined = user.last_login = date
101 self.assertEqual(user.email, patch.submitter.email)
103 conf = EmailConfirmation(type='registration', user=user,
111 # we should see no matching user
112 self.assertFalse(User.objects.filter(email = patch.submitter.email)
114 # but the patch and person should still be present
115 self.assertTrue(Person.objects.filter(
116 pk = defaults.patch_author_person.pk).exists())
117 self.assertTrue(Patch.objects.filter(pk = patch.pk).exists())
119 # and there should be no user associated with the person
120 self.assertEqual(Person.objects.get(pk =
121 defaults.patch_author_person.pk).user, None)