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):
29 fixtures = ['default_states']
31 def register(self, date):
33 user.is_active = False
34 user.date_joined = user.last_login = date
37 conf = EmailConfirmation(type='registration', user=user,
44 def testOldRegistrationExpiry(self):
45 date = ((datetime.datetime.now() - EmailConfirmation.validity) -
46 datetime.timedelta(hours = 1))
47 (user, conf) = self.register(date)
51 self.assertFalse(User.objects.filter(pk = user.pk).exists())
52 self.assertFalse(EmailConfirmation.objects.filter(pk = conf.pk)
56 def testRecentRegistrationExpiry(self):
57 date = ((datetime.datetime.now() - EmailConfirmation.validity) +
58 datetime.timedelta(hours = 1))
59 (user, conf) = self.register(date)
63 self.assertTrue(User.objects.filter(pk = user.pk).exists())
64 self.assertTrue(EmailConfirmation.objects.filter(pk = conf.pk)
67 def testInactiveRegistrationExpiry(self):
68 (user, conf) = self.register(datetime.datetime.now())
70 # confirm registration
71 conf.user.is_active = True
77 self.assertTrue(User.objects.filter(pk = user.pk).exists())
78 self.assertFalse(EmailConfirmation.objects.filter(pk = conf.pk)
81 def testPatchSubmitterExpiry(self):
82 defaults.project.save()
83 defaults.patch_author_person.save()
85 # someone submits a patch...
86 patch = Patch(project = defaults.project,
87 msgid = 'test@example.com', name = 'test patch',
88 submitter = defaults.patch_author_person,
89 content = defaults.patch)
92 # ... then starts registration...
93 date = ((datetime.datetime.now() - EmailConfirmation.validity) -
94 datetime.timedelta(hours = 1))
96 user = User.objects.create_user(userid,
97 defaults.patch_author_person.email, userid)
98 user.is_active = False
99 user.date_joined = user.last_login = date
102 self.assertEqual(user.email, patch.submitter.email)
104 conf = EmailConfirmation(type='registration', user=user,
112 # we should see no matching user
113 self.assertFalse(User.objects.filter(email = patch.submitter.email)
115 # but the patch and person should still be present
116 self.assertTrue(Person.objects.filter(
117 pk = defaults.patch_author_person.pk).exists())
118 self.assertTrue(Patch.objects.filter(pk = patch.pk).exists())
120 # and there should be no user associated with the person
121 self.assertEqual(Person.objects.get(pk =
122 defaults.patch_author_person.pk).user, None)