Merge lp:~roadmr/canonical-identity-provider/invalidatedemailaddress_created_at into lp:canonical-identity-provider/release

Proposed by Daniel Manrique
Status: Merged
Approved by: Daniel Manrique
Approved revision: no longer in the source branch.
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~roadmr/canonical-identity-provider/invalidatedemailaddress_created_at
Merge into: lp:canonical-identity-provider/release
Diff against target: 136 lines (+48/-14)
4 files modified
src/identityprovider/migrations/0012_auto_20180509_2122.py (+21/-0)
src/identityprovider/models/emailaddress.py (+2/-1)
src/identityprovider/tests/test_admin.py (+19/-0)
src/identityprovider/tests/test_models_emailaddress.py (+6/-13)
To merge this branch: bzr merge lp:~roadmr/canonical-identity-provider/invalidatedemailaddress_created_at
Reviewer Review Type Date Requested Status
Maximiliano Bertacchini Approve
Review via email: mp+345441@code.launchpad.net

Commit message

Set InvalidatedEmailAddress date_created by default to now() so they can be created via the admin.

Description of the change

Set InvalidatedEmailAddress date_created by default to now() so they can be created via the admin.

All tests (except the model-level tests I updated) pass, though it may be worth checking the user-level behavior of clicking on an invalidation link still works. I'd be surprised if that wasn't covered by tests but surprises do happen.

To post a comment you must log in.
Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/identityprovider/migrations/0012_auto_20180509_2122.py'
2--- src/identityprovider/migrations/0012_auto_20180509_2122.py 1970-01-01 00:00:00 +0000
3+++ src/identityprovider/migrations/0012_auto_20180509_2122.py 2018-05-11 17:19:00 +0000
4@@ -0,0 +1,21 @@
5+# -*- coding: utf-8 -*-
6+# Generated by Django 1.11.11 on 2018-05-09 21:22
7+from __future__ import unicode_literals
8+
9+from django.db import migrations, models
10+import django.utils.timezone
11+
12+
13+class Migration(migrations.Migration):
14+
15+ dependencies = [
16+ ('identityprovider', '0011_remove_openidrpconfig_ga_snippet'),
17+ ]
18+
19+ operations = [
20+ migrations.AlterField(
21+ model_name='invalidatedemailaddress',
22+ name='date_created',
23+ field=models.DateTimeField(blank=True, default=django.utils.timezone.now, editable=False),
24+ ),
25+ ]
26
27=== modified file 'src/identityprovider/models/emailaddress.py'
28--- src/identityprovider/models/emailaddress.py 2018-02-14 14:05:59 +0000
29+++ src/identityprovider/models/emailaddress.py 2018-05-11 17:19:00 +0000
30@@ -92,7 +92,8 @@
31
32 class InvalidatedEmailAddress(models.Model):
33 email = models.TextField(validators=[validate_email])
34- date_created = models.DateTimeField(blank=True, editable=False)
35+ date_created = models.DateTimeField(
36+ default=now, blank=True, editable=False)
37 date_invalidated = models.DateTimeField(default=now, null=True, blank=True)
38 account = models.ForeignKey(
39 Account, db_column=b'account', blank=True, null=True)
40
41=== modified file 'src/identityprovider/tests/test_admin.py'
42--- src/identityprovider/tests/test_admin.py 2018-02-15 11:27:21 +0000
43+++ src/identityprovider/tests/test_admin.py 2018-05-11 17:19:00 +0000
44@@ -412,6 +412,25 @@
45 model = InvalidatedEmailAddress
46 modeladmin = InvalidatedEmailAddressAdmin
47
48+ def test_add_invalidated_email(self):
49+ self.admin = self.factory.make_account(
50+ is_superuser=True, password="admin007")
51+ assert self.client.login(
52+ username=self.admin.user.email, password="admin007")
53+ self.account = self.factory.make_account()
54+ data = {
55+ 'email': "something@example.com",
56+ 'date_invalidated': now(),
57+ 'account': self.account.id,
58+ }
59+ self.client.post(reverse(
60+ 'admin:identityprovider_invalidatedemailaddress_add'), data)
61+ self.assertEqual(
62+ self.account.invalidatedemailaddress_set.all().count(), 1)
63+ self.assertEqual(
64+ self.account.invalidatedemailaddress_set.first().email,
65+ "something@example.com")
66+
67
68 class ApproxCountQuerySetTestCase(SSOBaseTestCase):
69 def setUp(self):
70
71=== modified file 'src/identityprovider/tests/test_models_emailaddress.py'
72--- src/identityprovider/tests/test_models_emailaddress.py 2018-02-21 16:15:06 +0000
73+++ src/identityprovider/tests/test_models_emailaddress.py 2018-05-11 17:19:00 +0000
74@@ -3,7 +3,6 @@
75 from datetime import timedelta
76
77 from django.core.exceptions import ValidationError
78-from django.db import IntegrityError
79 from django.utils.timezone import now
80 from mock import Mock, patch
81
82@@ -137,36 +136,30 @@
83
84 class InvalidatedEmailAddressTestCase(SSOBaseTestCase):
85
86- def test_date_created_not_default(self):
87- self.assertRaises(
88- IntegrityError,
89- InvalidatedEmailAddress.objects.create, email='foo@foo.com')
90-
91 def test_email_valid(self):
92 for valid in ('a@a.com', 'aaaa.bbbb@foo.com', 'a@foo.net'):
93 email = InvalidatedEmailAddress.objects.create(
94- email=valid, date_created=now())
95+ email=valid)
96 email.full_clean() # no failure
97
98 def test_email_invalid(self):
99 for invalid in ('', '.', '@', '@foo', '@foo.x', 'a@foo.x', 'foo@bar',
100 'a@@a.com'):
101 email = InvalidatedEmailAddress.objects.create(
102- email=invalid, date_created=now())
103+ email=invalid)
104 self.assertRaises(
105 ValidationError, email.full_clean)
106
107 def test_unicode(self):
108 email = u'zaraza♥foo@example.com'
109 invalid = InvalidatedEmailAddress.objects.create(
110- email=email, date_created=now())
111+ email=email)
112 self.assertEqual(email, unicode(invalid))
113
114 def test_date_invalidated(self):
115 some_date = now() + timedelta(days=30)
116 invalid = InvalidatedEmailAddress.objects.create(
117- email='foo@example.com', date_created=now(),
118- date_invalidated=some_date)
119+ email='foo@example.com', date_invalidated=some_date)
120
121 self.assertEqual(invalid.date_invalidated, some_date)
122
123@@ -176,11 +169,11 @@
124 InvalidatedEmailAddress._meta.get_field(
125 'date_invalidated').get_default = mock_date
126 invalid = InvalidatedEmailAddress.objects.create(
127- email='foo@example.com', date_created=now())
128+ email='foo@example.com')
129
130 self.assertEqual(invalid.date_invalidated, mock_date.return_value)
131
132 def test_account_notified(self):
133 invalid = InvalidatedEmailAddress.objects.create(
134- email='foo@example.com', date_created=now())
135+ email='foo@example.com')
136 self.assertFalse(invalid.account_notified)