-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathtest_expiry.py
More file actions
101 lines (79 loc) · 3.18 KB
/
test_expiry.py
File metadata and controls
101 lines (79 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Patchwork - automated patch tracking system
# Copyright (C) 2014 Jeremy Kerr <jk@ozlabs.org>
#
# SPDX-License-Identifier: GPL-2.0-or-later
import datetime
from django.contrib.auth.models import User
from django.test import TestCase
from django.utils import timezone as tz_utils
from patchwork.models import EmailConfirmation
from patchwork.models import Patch
from patchwork.models import Person
from patchwork.notifications import expire_notifications
from patchwork.tests.utils import create_patch
from patchwork.tests.utils import create_user
class TestRegistrationExpiry(TestCase):
def register(self, date):
user = create_user()
user.is_active = False
user.date_joined = user.last_login = date
user.save()
conf = EmailConfirmation(
type='registration', user=user, email=user.email
)
conf.date = date
conf.save()
return (user, conf)
def test_old_registration_expiry(self):
date = (
tz_utils.now() - EmailConfirmation.validity
) - datetime.timedelta(hours=1)
user, conf = self.register(date)
expire_notifications()
self.assertFalse(User.objects.filter(pk=user.pk).exists())
self.assertFalse(EmailConfirmation.objects.filter(pk=conf.pk).exists())
def test_recent_registration_expiry(self):
date = (
tz_utils.now() - EmailConfirmation.validity
) + datetime.timedelta(hours=1)
user, conf = self.register(date)
expire_notifications()
self.assertTrue(User.objects.filter(pk=user.pk).exists())
self.assertTrue(EmailConfirmation.objects.filter(pk=conf.pk).exists())
def test_inactive_registration_expiry(self):
user, conf = self.register(tz_utils.now())
# confirm registration
conf.user.is_active = True
conf.user.save()
conf.deactivate()
expire_notifications()
self.assertTrue(User.objects.filter(pk=user.pk).exists())
self.assertFalse(EmailConfirmation.objects.filter(pk=conf.pk).exists())
def test_patch_submitter_expiry(self):
# someone submits a patch...
patch = create_patch()
submitter = patch.submitter
# ... then starts registration...
date = (
tz_utils.now() - EmailConfirmation.validity
) - datetime.timedelta(hours=1)
user = create_user(link_person=False, email=submitter.email)
user.is_active = False
user.date_joined = user.last_login = date
user.save()
conf = EmailConfirmation(
type='registration', user=user, email=user.email
)
conf.date = date
conf.save()
# ... which expires
expire_notifications()
# we should see no matching user
self.assertFalse(
User.objects.filter(email=patch.submitter.email).exists()
)
# but the patch and person should still be present
self.assertTrue(Person.objects.filter(pk=submitter.pk).exists())
self.assertTrue(Patch.objects.filter(pk=patch.pk).exists())
# and there should be no user associated with the person
self.assertEqual(Person.objects.get(pk=submitter.pk).user, None)