Merge lp:~canonical-isd-hackers/canonical-identity-provider/644975-openididentifier into lp:canonical-identity-provider/release
- 644975-openididentifier
- Merge into trunk
Proposed by
Łukasz Czyżykowski
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Łukasz Czyżykowski | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 121 | ||||
Proposed branch: | lp:~canonical-isd-hackers/canonical-identity-provider/644975-openididentifier | ||||
Merge into: | lp:canonical-identity-provider/release | ||||
Diff against target: |
656 lines (+106/-122) 15 files modified
identityprovider/fixtures/test.json (+13/-37) identityprovider/management/commands/populate.py (+10/-8) identityprovider/models/account.py (+26/-19) identityprovider/models/person.py (+13/-9) identityprovider/tests/test_admin.py (+5/-3) identityprovider/tests/test_command_cleanup.py (+1/-1) identityprovider/tests/test_command_populate.py (+4/-4) identityprovider/tests/test_middleware.py (+5/-5) identityprovider/tests/test_models_account.py (+3/-8) identityprovider/tests/test_models_person.py (+6/-4) identityprovider/tests/test_utils.py (+3/-10) identityprovider/tests/test_views_server.py (+9/-6) identityprovider/tests/test_widgets.py (+5/-4) identityprovider/tests/utils.py (+1/-1) identityprovider/webservice/models.py (+2/-3) |
||||
To merge this branch: | bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/644975-openididentifier | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Anthony Lenton (community) | Approve | ||
Review via email: mp+44261@code.launchpad.net |
Commit message
Updated code to use new lp_OpenIdIdentifier table.
Description of the change
Updated code to use new lp_OpenIdIdentifier table. For that to work updated code, test suite and fixtures.
To post a comment you must log in.
Revision history for this message
Anthony Lenton (elachuni) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'identityprovider/fixtures/test.json' |
2 | --- identityprovider/fixtures/test.json 2010-05-07 20:29:41 +0000 |
3 | +++ identityprovider/fixtures/test.json 2010-12-20 18:58:30 +0000 |
4 | @@ -14,6 +14,11 @@ |
5 | } |
6 | }, |
7 | { |
8 | + "pk": "mark_oid", |
9 | + "model": "identityprovider.lpopenididentifier", |
10 | + "fields": {"lp_account": 1, "date_created": "2005-06-06 08:59:51"} |
11 | + }, |
12 | + { |
13 | "pk": 12, |
14 | "model": "identityprovider.account", |
15 | "fields": { |
16 | @@ -56,6 +61,12 @@ |
17 | } |
18 | }, |
19 | { |
20 | + "pk": "cCGE3LA", |
21 | + "model": "identityprovider.lpopenididentifier", |
22 | + "fields": {"lp_account": 10, "date_created": "2005-06-06 08:59:51"} |
23 | + }, |
24 | + |
25 | + { |
26 | "pk": 243611, |
27 | "model": "identityprovider.account", |
28 | "fields": { |
29 | @@ -100,7 +111,7 @@ |
30 | "model": "identityprovider.emailaddress", |
31 | "fields": { |
32 | "status": 4, |
33 | - "lp_person": null, |
34 | + "lp_person": 1, |
35 | "account": 1, |
36 | "email": "mark@example.com", |
37 | "date_created": "2006-10-16 18:31:43" |
38 | @@ -185,13 +196,6 @@ |
39 | }, |
40 | { |
41 | "pk": 1, |
42 | - "model": "identityprovider.lpaccount", |
43 | - "fields": { |
44 | - "openid_identifier": "mark_oid" |
45 | - } |
46 | - }, |
47 | - { |
48 | - "pk": 1, |
49 | "model": "identityprovider.person", |
50 | "fields": { |
51 | "displayname": "Mark Shuttleworth", |
52 | @@ -234,13 +238,6 @@ |
53 | }, |
54 | { |
55 | "pk": 12, |
56 | - "model": "identityprovider.lpaccount", |
57 | - "fields": { |
58 | - "openid_identifier": "name12_oid" |
59 | - } |
60 | - }, |
61 | - { |
62 | - "pk": 12, |
63 | "model": "identityprovider.person", |
64 | "fields": { |
65 | "displayname": "Sample Person", |
66 | @@ -283,13 +280,6 @@ |
67 | }, |
68 | { |
69 | "pk": 66, |
70 | - "model": "identityprovider.lpaccount", |
71 | - "fields": { |
72 | - "openid_identifier": "matsubara_oid" |
73 | - } |
74 | - }, |
75 | - { |
76 | - "pk": 66, |
77 | "model": "identityprovider.person", |
78 | "fields": { |
79 | "displayname": "Diogo Matsubara", |
80 | @@ -373,13 +363,6 @@ |
81 | }, |
82 | { |
83 | "pk": 243610, |
84 | - "model": "identityprovider.lpaccount", |
85 | - "fields": { |
86 | - "openid_identifier": "cCGE3LA" |
87 | - } |
88 | - }, |
89 | - { |
90 | - "pk": 243610, |
91 | "model": "identityprovider.person", |
92 | "fields": { |
93 | "displayname": "Gold Member", |
94 | @@ -417,14 +400,7 @@ |
95 | "mailing_list_receive_duplicates": true, |
96 | "visibility": 1, |
97 | "verbose_bugnotifications": false, |
98 | - "lp_account": 243610 |
99 | - } |
100 | - }, |
101 | - { |
102 | - "pk": 243611, |
103 | - "model": "identityprovider.lpaccount", |
104 | - "fields": { |
105 | - "openid_identifier": "MGWJnTL" |
106 | + "lp_account": 10 |
107 | } |
108 | }, |
109 | { |
110 | |
111 | === modified file 'identityprovider/management/commands/populate.py' |
112 | --- identityprovider/management/commands/populate.py 2010-10-11 20:35:49 +0000 |
113 | +++ identityprovider/management/commands/populate.py 2010-12-20 18:58:30 +0000 |
114 | @@ -101,7 +101,9 @@ |
115 | self.nicks = [] |
116 | self.translation_table = (lowercase * 10)[:256] |
117 | |
118 | - self.populate_table('lp_account', self.gen_lp_account, naccounts) |
119 | + self.populate_table('lp_openididentifier', |
120 | + self.gen_lp_openididentifier, naccounts, |
121 | + numeric_id=False) |
122 | self.populate_table('lp_person', self.gen_lp_person, naccounts) |
123 | self.populate_table('account', self.gen_account, naccounts) |
124 | self.populate_table('accountpassword', self.gen_accountpassword, |
125 | @@ -169,14 +171,14 @@ |
126 | password = encrypt_launchpad_password(plaintext) |
127 | return [str(id), str(account_id), password] |
128 | |
129 | - def gen_lp_account(self, id): |
130 | - """ Returns a sequence representing an LPAccount. |
131 | + def gen_lp_openididentifier(self, id): |
132 | + """ Returns a sequence representing an LPOpenIdIdentfier. |
133 | |
134 | - Currently (id, openid) |
135 | + Currently (id, openid, date_created) |
136 | """ |
137 | openid = self.random_string(size=10) |
138 | self.openids.append(openid) |
139 | - return [str(id), openid] |
140 | + return [openid, str(id), self.random_date()] |
141 | |
142 | def gen_lp_person(self, id): |
143 | """ Returns a sequence representing a Person. |
144 | @@ -190,7 +192,7 @@ |
145 | renewal_policy, personal_standing, personal_standing_reason, |
146 | mail_resumption_date, mailing_list_auto_subscribe_policy, |
147 | mailing_list_receive_duplicates, visibility, |
148 | - verbose_bugnotifications, lp_account) |
149 | + verbose_bugnotifications) |
150 | """ |
151 | displayname = self.random_string(12) |
152 | nick = self.random_string(8) + str(id) |
153 | @@ -198,7 +200,7 @@ |
154 | datecreated = self.random_date() |
155 | account_id = (id - self.ranges['lp_person'][0] + |
156 | self.ranges['lp_account'][0]) |
157 | - return [str(id), displayname, 'NULL', '', nick, |
158 | + return [str(account_id), displayname, 'NULL', '', nick, |
159 | 'NULL', '', '0', '0', |
160 | '1', 'NULL', datecreated, '', |
161 | '', '', '', '', 'NULL', '', |
162 | @@ -206,7 +208,7 @@ |
163 | str(AccountCreationRationale.USER_CREATED), '', 'NULL', 'NULL', |
164 | '10', '0', '', |
165 | 'NULL', '1', 't', '1', |
166 | - 'f', str(account_id)] |
167 | + 'f'] |
168 | |
169 | def gen_emailaddress(self, id): |
170 | """ Returns a sequence representing an EmailAddress. |
171 | |
172 | === modified file 'identityprovider/models/account.py' |
173 | --- identityprovider/models/account.py 2010-11-11 16:13:52 +0000 |
174 | +++ identityprovider/models/account.py 2010-12-20 18:58:30 +0000 |
175 | @@ -1,7 +1,7 @@ |
176 | # Copyright 2010 Canonical Ltd. This software is licensed under the |
177 | # GNU Affero General Public License version 3 (see the file LICENSE). |
178 | |
179 | -import datetime |
180 | +from datetime import date, datetime, timedelta |
181 | |
182 | from django.conf import settings |
183 | from django.contrib.auth import get_backends |
184 | @@ -20,8 +20,8 @@ |
185 | 'Account', |
186 | 'AccountPassword', |
187 | 'DisplaynameField', |
188 | - 'LPAccount', |
189 | 'PasswordField', |
190 | + 'LPOpenIdIdentifier' |
191 | ) |
192 | |
193 | |
194 | @@ -71,14 +71,14 @@ |
195 | |
196 | |
197 | class Account(models.Model): |
198 | - date_created = models.DateTimeField(default=datetime.datetime.utcnow, |
199 | + date_created = models.DateTimeField(default=datetime.utcnow, |
200 | editable=False) |
201 | creation_rationale = \ |
202 | models.IntegerField( |
203 | choices=AccountCreationRationale._get_choices()) |
204 | |
205 | status = models.IntegerField(choices=AccountStatus._get_choices()) |
206 | - date_status_set = models.DateTimeField(default=datetime.datetime.utcnow) |
207 | + date_status_set = models.DateTimeField(default=datetime.utcnow) |
208 | displayname = DisplaynameField() |
209 | openid_identifier = models.TextField(default=generate_openid_identifier) |
210 | status_comment = models.TextField(blank=True, null=True) |
211 | @@ -122,8 +122,8 @@ |
212 | Current rule of thumb is to return all sites accessed within previous |
213 | 24 hours. |
214 | """ |
215 | - max_date_last_used = (datetime.datetime.now() - |
216 | - datetime.timedelta(hours=age_hours)) |
217 | + max_date_last_used = (datetime.now() - |
218 | + timedelta(hours=age_hours)) |
219 | sites = self.openidrpsummary_set.filter( |
220 | date_last_used__gte=max_date_last_used) |
221 | return sites.order_by('-date_last_used') |
222 | @@ -157,10 +157,15 @@ |
223 | @property |
224 | def person(self): |
225 | if not hasattr(self, '_person'): |
226 | - lpaccounts = LPAccount.objects.filter( |
227 | - openid_identifier=self.openid_identifier) |
228 | - if len(lpaccounts) > 0: |
229 | - persons = lpaccounts[0].person_set.all() |
230 | + open_ids = LPOpenIdIdentifier.objects.filter( |
231 | + identifier=self.openid_identifier) |
232 | + if len(open_ids) > 0: |
233 | + # Look up Person object with the same lp_account id as it's in |
234 | + # lp_OpenIdIdentifier table |
235 | + lp_account = open_ids[0].lp_account |
236 | + # Importing it here to prevent cyclic import issue |
237 | + from .person import Person |
238 | + persons = Person.objects.filter(lp_account=lp_account) |
239 | if len(persons) > 0: |
240 | self._person = persons[0] |
241 | return getattr(self, '_person', None) |
242 | @@ -293,17 +298,19 @@ |
243 | return _("Password for %s") % unicode(self.account) |
244 | |
245 | |
246 | -class LPAccount(models.Model): |
247 | - """ A projected ghost of an account in LP. Only the openid_identifier is |
248 | - replicated over. |
249 | - """ |
250 | - openid_identifier = models.TextField(unique=True) |
251 | +class LPOpenIdIdentifier(models.Model): |
252 | + """ |
253 | + Mapping between Launchpad accounts and OpenID identifiers |
254 | + """ |
255 | + identifier = models.TextField(unique=True, primary_key=True) |
256 | + lp_account = models.IntegerField(null=False, db_column='account') |
257 | + date_created = models.DateTimeField(null=False, default=date.today) |
258 | |
259 | class Meta: |
260 | app_label = 'identityprovider' |
261 | - db_table = u'lp_account' |
262 | - verbose_name = _('LP account') |
263 | - verbose_name_plural = _('LP accounts') |
264 | + db_table = u'lp_openididentifier' |
265 | + verbose_name = _("LP OpenID Identifier") |
266 | + verbose_name_plural = _("LP OpenID Identifiers") |
267 | |
268 | def __unicode__(self): |
269 | - return _("LP account for %s") % unicode(self.openid_identifier) |
270 | + return _("LP OpenID Idetifier for %s") % unicode(self.account) |
271 | |
272 | === modified file 'identityprovider/models/person.py' |
273 | --- identityprovider/models/person.py 2010-05-21 13:38:16 +0000 |
274 | +++ identityprovider/models/person.py 2010-12-20 18:58:30 +0000 |
275 | @@ -3,8 +3,9 @@ |
276 | |
277 | from django.db import models |
278 | |
279 | -from identityprovider.models import (LPAccount, Account, Country, Language, |
280 | - LibraryFileAlias) |
281 | +from identityprovider.models import ( |
282 | + Account, Country, Language, LibraryFileAlias, LPOpenIdIdentifier, |
283 | +) |
284 | from identityprovider.models.const import AccountCreationRationale |
285 | |
286 | __all__ = ( |
287 | @@ -63,8 +64,7 @@ |
288 | mailing_list_receive_duplicates = models.BooleanField(default=True) |
289 | visibility = models.IntegerField(default=1) |
290 | verbose_bugnotifications = models.BooleanField(default=False) |
291 | - lp_account = models.ForeignKey(LPAccount, db_column='account', |
292 | - null=True, blank=True) |
293 | + lp_account = models.IntegerField(null=True, db_column='account') |
294 | |
295 | class Meta: |
296 | app_label = 'identityprovider' |
297 | @@ -83,7 +83,7 @@ |
298 | except Person.DoesNotExist: |
299 | return False |
300 | try: |
301 | - tp = TeamParticipation.objects.get(team=team, person=self) |
302 | + TeamParticipation.objects.get(team=team, person=self) |
303 | return True |
304 | except TeamParticipation.DoesNotExist: |
305 | if self.id == team.teamowner.id: |
306 | @@ -93,10 +93,14 @@ |
307 | @property |
308 | def account(self): |
309 | if self.lp_account is not None: |
310 | - accounts = Account.objects.filter( |
311 | - openid_identifier=self.lp_account.openid_identifier) |
312 | - if len(accounts) > 0: |
313 | - return accounts[0] |
314 | + open_ids = LPOpenIdIdentifier.objects.filter( |
315 | + lp_account=self.lp_account) |
316 | + if len(open_ids) > 0: |
317 | + openid_identifier = open_ids[0].identifier |
318 | + accounts = Account.objects.filter( |
319 | + openid_identifier=openid_identifier) |
320 | + if len(accounts) > 0: |
321 | + return accounts[0] |
322 | |
323 | def is_team(self): |
324 | return self.teamowner is not None |
325 | |
326 | === modified file 'identityprovider/tests/test_admin.py' |
327 | --- identityprovider/tests/test_admin.py 2010-10-14 13:52:06 +0000 |
328 | +++ identityprovider/tests/test_admin.py 2010-12-20 18:58:30 +0000 |
329 | @@ -6,8 +6,10 @@ |
330 | |
331 | from identityprovider.admin import (AccountPasswordInline, |
332 | EmailAddressInline) |
333 | -from identityprovider.models import (Account, AccountPassword, EmailAddress, |
334 | - OpenIDRPConfig, APIUser, Person, LPAccount) |
335 | +from identityprovider.models import (EmailAddress, |
336 | + OpenIDRPConfig, APIUser, Person) |
337 | +from identityprovider.models.account import (Account, AccountPassword, |
338 | + LPOpenIdIdentifier) |
339 | from identityprovider.models.const import EmailStatus |
340 | from identityprovider.utils import validate_launchpad_password |
341 | |
342 | @@ -29,7 +31,7 @@ |
343 | for model in (Account, OpenIDRPConfig, APIUser, EmailAddress): |
344 | self.assertRaises(AlreadyRegistered, admin.site.register, model) |
345 | |
346 | - for model in (AccountPassword, Person, LPAccount): |
347 | + for model in (AccountPassword, Person, LPOpenIdIdentifier): |
348 | self.assertRaises(NotRegistered, admin.site.unregister, model) |
349 | |
350 | def test_openidrpconfig_allowed_sreg_checkboxes(self): |
351 | |
352 | === modified file 'identityprovider/tests/test_command_cleanup.py' |
353 | --- identityprovider/tests/test_command_cleanup.py 2010-11-02 19:44:09 +0000 |
354 | +++ identityprovider/tests/test_command_cleanup.py 2010-12-20 18:58:30 +0000 |
355 | @@ -12,7 +12,7 @@ |
356 | class CleanupCommandTestCase(TestCase): |
357 | def tearDown(self): |
358 | cursor = connection.cursor() |
359 | - cursor.execute("""TRUNCATE lp_account, account, accountpassword, |
360 | + cursor.execute("""TRUNCATE lp_openididentifier, account, accountpassword, |
361 | emailaddress, lp_person, django_session, openidnonce, |
362 | openidassociation CASCADE""") |
363 | connection.connection.commit() |
364 | |
365 | === modified file 'identityprovider/tests/test_command_populate.py' |
366 | --- identityprovider/tests/test_command_populate.py 2010-10-13 19:26:09 +0000 |
367 | +++ identityprovider/tests/test_command_populate.py 2010-12-20 18:58:30 +0000 |
368 | @@ -4,12 +4,12 @@ |
369 | from django.test import TestCase |
370 | |
371 | from identityprovider.models import (Account, AccountPassword, EmailAddress, |
372 | - Person, LPAccount, OpenIDAssociation, OpenIDNonce) |
373 | + Person, LPOpenIdIdentifier, OpenIDAssociation, OpenIDNonce) |
374 | |
375 | class PopulateCommandTestCase(TestCase): |
376 | def tearDown(self): |
377 | cursor = connection.cursor() |
378 | - cursor.execute("""TRUNCATE lp_account, account, accountpassword, |
379 | + cursor.execute("""TRUNCATE lp_openididentifier, account, accountpassword, |
380 | emailaddress, lp_person, django_session, openidnonce, |
381 | openidassociation CASCADE""") |
382 | connection.connection.commit() |
383 | @@ -18,7 +18,7 @@ |
384 | |
385 | def check_populate_populates_correctly(self, naccounts=0, nsessions=0, |
386 | nnonces=0, nassociations=0): |
387 | - self.assertEqual(0, LPAccount.objects.count()) |
388 | + self.assertEqual(0, LPOpenIdIdentifier.objects.count()) |
389 | self.assertEqual(0, Account.objects.count()) |
390 | self.assertEqual(0, AccountPassword.objects.count()) |
391 | self.assertEqual(0, EmailAddress.objects.count()) |
392 | @@ -30,7 +30,7 @@ |
393 | call_command('populate', accounts=naccounts, sessions=nsessions, |
394 | nonces=nnonces, associations=nassociations, verbosity=0) |
395 | |
396 | - self.assertEqual(naccounts, LPAccount.objects.count()) |
397 | + self.assertEqual(naccounts, LPOpenIdIdentifier.objects.count()) |
398 | self.assertEqual(naccounts, Account.objects.count()) |
399 | self.assertEqual(naccounts, AccountPassword.objects.count()) |
400 | self.assertEqual(naccounts, EmailAddress.objects.count()) |
401 | |
402 | === modified file 'identityprovider/tests/test_middleware.py' |
403 | --- identityprovider/tests/test_middleware.py 2010-11-23 12:27:53 +0000 |
404 | +++ identityprovider/tests/test_middleware.py 2010-12-20 18:58:30 +0000 |
405 | @@ -1,21 +1,17 @@ |
406 | # Copyright 2010 Canonical Ltd. This software is licensed under the |
407 | # GNU Affero General Public License version 3 (see the file LICENSE). |
408 | |
409 | -import functools |
410 | import logging |
411 | import re |
412 | import sys |
413 | -from urlparse import urlsplit |
414 | |
415 | from django.conf import settings |
416 | from django.contrib.auth.models import User, AnonymousUser |
417 | -from django.http import QueryDict |
418 | -import django.test.client |
419 | |
420 | from openid.message import (IDENTIFIER_SELECT, OPENID1_URL_LIMIT, OPENID2_NS) |
421 | |
422 | from identityprovider.tests.utils import (BasicAccountTestCase, MockRequest, |
423 | - OpenIDProviderTestCase, TestCase) |
424 | + TestCase) |
425 | from identityprovider.models import Account, EmailAddress, OpenIDRPConfig |
426 | from identityprovider.middleware.exception import LogExceptionMiddleware |
427 | from identityprovider.middleware.useraccount import ( |
428 | @@ -32,6 +28,8 @@ |
429 | |
430 | class UserAccountConversionMiddlewareTestCase(BasicAccountTestCase): |
431 | |
432 | + fixtures = ['test'] |
433 | + |
434 | def setUp(self): |
435 | email = EmailAddress.objects.get(email__iexact='test@canonical.com') |
436 | self.account = email.account |
437 | @@ -158,6 +156,8 @@ |
438 | # The tests perform a login in order to acquire this session cookie. |
439 | class CSRFMiddlewareTestCase(BasicAccountTestCase): |
440 | |
441 | + fixtures = ['test'] |
442 | + |
443 | def _land(self, client=None): |
444 | client = client or self.client |
445 | r = client.get('/') |
446 | |
447 | === modified file 'identityprovider/tests/test_models_account.py' |
448 | --- identityprovider/tests/test_models_account.py 2010-10-01 12:14:43 +0000 |
449 | +++ identityprovider/tests/test_models_account.py 2010-12-20 18:58:30 +0000 |
450 | @@ -6,7 +6,7 @@ |
451 | from django.contrib.auth.models import User |
452 | from identityprovider.tests.utils import BasicAccountTestCase |
453 | from identityprovider.models.account import (Account, AccountPassword, |
454 | - AccountStatus, LPAccount) |
455 | + AccountStatus) |
456 | from identityprovider.models import account as a |
457 | from identityprovider.models.emailaddress import EmailAddress |
458 | from identityprovider.models.const import AccountCreationRationale, EmailStatus |
459 | @@ -161,7 +161,8 @@ |
460 | return account, get_backends |
461 | |
462 | def get_new_account(self): |
463 | - return Account(openid_identifier='non-existing-identifier') |
464 | + return Account.objects.create_account( |
465 | + 'test account', 'test-email@example.com', 'password') |
466 | |
467 | def get_existing_account(self): |
468 | return Account.objects.get_by_email('test@canonical.com') |
469 | @@ -321,9 +322,3 @@ |
470 | password = AccountPassword(account=account, password='password') |
471 | self.assertEqual(unicode(password), u'Password for displayname') |
472 | |
473 | - |
474 | -class LPAccountTestCase(BasicAccountTestCase): |
475 | - def test_unicode(self): |
476 | - account = LPAccount(openid_identifier='oid') |
477 | - self.assertEqual(unicode(account), u'LP account for oid') |
478 | - |
479 | |
480 | === modified file 'identityprovider/tests/test_models_person.py' |
481 | --- identityprovider/tests/test_models_person.py 2010-05-21 13:42:36 +0000 |
482 | +++ identityprovider/tests/test_models_person.py 2010-12-20 18:58:30 +0000 |
483 | @@ -1,8 +1,8 @@ |
484 | # Copyright 2010 Canonical Ltd. This software is licensed under the |
485 | # GNU Affero General Public License version 3 (see the file LICENSE). |
486 | - |
487 | - |
488 | -from identityprovider.models.account import Account, LPAccount |
489 | +from random import randint |
490 | + |
491 | +from identityprovider.models.account import Account, LPOpenIdIdentifier |
492 | from identityprovider.models.const import (AccountCreationRationale, |
493 | AccountStatus) |
494 | from identityprovider.models.person import Person |
495 | @@ -11,10 +11,12 @@ |
496 | |
497 | |
498 | class PersonTestCase(SQLCachedTestCase): |
499 | + |
500 | pgsql_functions = ['generate_openid_identifier'] |
501 | |
502 | def setUp(self): |
503 | - lp_account = LPAccount.objects.create(openid_identifier='oid') |
504 | + lp_account = randint(100, 10000) |
505 | + LPOpenIdIdentifier.objects.create(identifier='oid', lp_account=lp_account) |
506 | self.person1 = Person.objects.create(displayname='Person', |
507 | name='person', lp_account=lp_account) |
508 | self.person2 = Person.objects.create(displayname='Other', name='other') |
509 | |
510 | === modified file 'identityprovider/tests/test_utils.py' |
511 | --- identityprovider/tests/test_utils.py 2010-08-03 12:56:27 +0000 |
512 | +++ identityprovider/tests/test_utils.py 2010-12-20 18:58:30 +0000 |
513 | @@ -3,12 +3,12 @@ |
514 | import urllib2 |
515 | |
516 | from unittest import TestCase |
517 | -from cStringIO import StringIO |
518 | from django.utils.translation import ugettext as _ |
519 | |
520 | from identityprovider.tests.utils import (BasicAccountTestCase, |
521 | LPAccountTestCase, SQLCachedTestCase) |
522 | from identityprovider.models.person import Person |
523 | +from identityprovider.models.account import LPOpenIdIdentifier |
524 | from identityprovider.models.emailaddress import EmailAddress |
525 | from identityprovider.utils import (canonical_url, |
526 | get_person_and_account_by_email, password_policy_compliant, |
527 | @@ -46,21 +46,14 @@ |
528 | |
529 | |
530 | class LPGetPersonAndAccountByEmailTestCase(LPAccountTestCase): |
531 | + |
532 | def test_person_does_not_exist(self): |
533 | - # create email address with broken foreign key |
534 | - email = EmailAddress.objects.get(email__iexact='mark@example.com') |
535 | - lp_person_id = email.lp_person_id |
536 | - email.lp_person_id = 0 |
537 | - email.save() |
538 | + LPOpenIdIdentifier.objects.all().delete() |
539 | |
540 | # test method |
541 | person, account = get_person_and_account_by_email('mark@example.com') |
542 | self.assertEquals(None, person) |
543 | |
544 | - # restore model integrity |
545 | - email.lp_person_id = lp_person_id |
546 | - email.save() |
547 | - |
548 | |
549 | class PasswordPolicyCompliantTestCase(SQLCachedTestCase): |
550 | |
551 | |
552 | === modified file 'identityprovider/tests/test_views_server.py' |
553 | --- identityprovider/tests/test_views_server.py 2010-09-15 13:41:44 +0000 |
554 | +++ identityprovider/tests/test_views_server.py 2010-12-20 18:58:30 +0000 |
555 | @@ -3,7 +3,8 @@ |
556 | |
557 | import datetime |
558 | import urlparse |
559 | -from copy import deepcopy |
560 | + |
561 | +from random import randint |
562 | from django.conf import settings |
563 | from django.contrib.auth.models import AnonymousUser |
564 | from django.test import TestCase |
565 | @@ -12,13 +13,13 @@ |
566 | |
567 | from openid.message import (Message, IDENTIFIER_SELECT, OPENID1_URL_LIMIT, |
568 | OPENID2_NS) |
569 | -from openid.server.server import Server, ProtocolError |
570 | from openid.yadis.constants import YADIS_HEADER_NAME |
571 | from urllib import quote, quote_plus |
572 | |
573 | import identityprovider.signed as signed |
574 | -from identityprovider.models import (Account, LPAccount, OpenIDAuthorization, |
575 | +from identityprovider.models import (Account, OpenIDAuthorization, |
576 | OpenIDRPConfig, Person) |
577 | +from identityprovider.models.account import LPOpenIdIdentifier |
578 | from identityprovider.models.const import (AccountStatus, EmailStatus, |
579 | AccountCreationRationale) |
580 | from identityprovider.models.person import PersonLocation |
581 | @@ -807,9 +808,11 @@ |
582 | status=AccountStatus.ACTIVE, |
583 | displayname='User') |
584 | self.account.save() |
585 | - lp_account = LPAccount( |
586 | - openid_identifier=self.account.openid_identifier) |
587 | - lp_account.save() |
588 | + |
589 | + lp_account = randint(1, 9999) |
590 | + LPOpenIdIdentifier.objects.create( |
591 | + identifier=self.account.openid_identifier, |
592 | + lp_account=lp_account) |
593 | person = Person(lp_account=lp_account) |
594 | person.save() |
595 | now = datetime.datetime.now() |
596 | |
597 | === modified file 'identityprovider/tests/test_widgets.py' |
598 | --- identityprovider/tests/test_widgets.py 2010-07-18 03:58:26 +0000 |
599 | +++ identityprovider/tests/test_widgets.py 2010-12-20 18:58:30 +0000 |
600 | @@ -5,7 +5,8 @@ |
601 | from django.conf import settings |
602 | from unittest import TestCase |
603 | |
604 | -from identityprovider.models import Account, LPAccount |
605 | +from identityprovider.models import Account |
606 | +from identityprovider.models.account import LPOpenIdIdentifier |
607 | from identityprovider.tests.utils import SQLCachedTestCase |
608 | from identityprovider.widgets import (CommaSeparatedWidget, ROAwareSelect, |
609 | ROAwareTextInput, StatusWidget, ReadOnlyDateTimeWidget, LPUsernameWidget) |
610 | @@ -139,7 +140,7 @@ |
611 | |
612 | |
613 | class LPUsernameWidgetTestCase(SQLCachedTestCase): |
614 | - pgsql_functions = ['generate_openid_identifier'] |
615 | + |
616 | fixtures = ['test'] |
617 | |
618 | def setUp(self): |
619 | @@ -158,7 +159,7 @@ |
620 | |
621 | def test_render_account_no_person(self): |
622 | # unlink person |
623 | - LPAccount.objects.filter( |
624 | - openid_identifier=self.widget.account.openid_identifier).delete() |
625 | + LPOpenIdIdentifier.objects.filter( |
626 | + identifier=self.widget.account.openid_identifier).delete() |
627 | r = self.widget.render('test', None) |
628 | self.assertEqual(r, '') |
629 | |
630 | === modified file 'identityprovider/tests/utils.py' |
631 | --- identityprovider/tests/utils.py 2010-10-27 14:46:02 +0000 |
632 | +++ identityprovider/tests/utils.py 2010-12-20 18:58:30 +0000 |
633 | @@ -53,7 +53,7 @@ |
634 | class BasicAccountTestCase(SQLCachedTestCase): |
635 | """ This SQLCachedTestCase subclass has some initial fixtures |
636 | and functions set for basic tests. """ |
637 | - fixtures = ['lp_account', 'lp_accountpassword', 'lp_emailaddress_noperson'] |
638 | + fixtures = ['test'] |
639 | pgsql_functions = ['generate_openid_identifier'] |
640 | |
641 | def reset_csrf(self): |
642 | |
643 | === modified file 'identityprovider/webservice/models.py' |
644 | --- identityprovider/webservice/models.py 2010-11-09 16:43:27 +0000 |
645 | +++ identityprovider/webservice/models.py 2010-12-20 18:58:30 +0000 |
646 | @@ -85,9 +85,8 @@ |
647 | if preferred_email is not None: |
648 | preferred_email = preferred_email.email |
649 | |
650 | - people = Person.objects.filter(lp_account=user) |
651 | - if people.count() == 1: |
652 | - username = people[0].name |
653 | + if user.person: |
654 | + username = user.person.name |
655 | else: |
656 | username = user.openid_identifier |
657 |