Merge lp:~canonical-isd-hackers/canonical-identity-provider/speed-up-tests into lp:canonical-identity-provider/release

Proposed by Łukasz Czyżykowski
Status: Merged
Approved by: Ricardo Kirkner
Approved revision: no longer in the source branch.
Merged at revision: 191
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/speed-up-tests
Merge into: lp:canonical-identity-provider/release
Diff against target: 1644 lines (+267/-295)
39 files modified
identityprovider/tests/functional/helpers.py (+2/-2)
identityprovider/tests/test_admin.py (+6/-7)
identityprovider/tests/test_auth.py (+6/-5)
identityprovider/tests/test_backend_base.py (+13/-13)
identityprovider/tests/test_captcha.py (+2/-1)
identityprovider/tests/test_command_cleanup.py (+3/-3)
identityprovider/tests/test_command_populate.py (+4/-3)
identityprovider/tests/test_command_readonly.py (+6/-7)
identityprovider/tests/test_command_sqlcachedflush.py (+3/-2)
identityprovider/tests/test_dbfailover.py (+3/-3)
identityprovider/tests/test_fields.py (+0/-1)
identityprovider/tests/test_forms.py (+11/-10)
identityprovider/tests/test_handlers.py (+3/-3)
identityprovider/tests/test_language_selection.py (+4/-4)
identityprovider/tests/test_loginservice.py (+10/-6)
identityprovider/tests/test_middleware.py (+7/-6)
identityprovider/tests/test_models_account.py (+10/-8)
identityprovider/tests/test_models_api.py (+5/-3)
identityprovider/tests/test_models_authtoken.py (+6/-2)
identityprovider/tests/test_models_emailaddress.py (+4/-4)
identityprovider/tests/test_models_openidmodels.py (+14/-8)
identityprovider/tests/test_models_person.py (+4/-4)
identityprovider/tests/test_models_team.py (+7/-8)
identityprovider/tests/test_readonly.py (+7/-10)
identityprovider/tests/test_static.py (+5/-5)
identityprovider/tests/test_teams.py (+7/-5)
identityprovider/tests/test_utils.py (+8/-7)
identityprovider/tests/test_views_account.py (+7/-5)
identityprovider/tests/test_views_consumer.py (+6/-3)
identityprovider/tests/test_views_i18n.py (+4/-2)
identityprovider/tests/test_views_preflight.py (+4/-4)
identityprovider/tests/test_views_server.py (+17/-16)
identityprovider/tests/test_views_ui.py (+25/-19)
identityprovider/tests/test_views_ui_logout.py (+6/-4)
identityprovider/tests/test_views_utils.py (+5/-5)
identityprovider/tests/test_widgets.py (+2/-2)
identityprovider/tests/test_xrds.py (+6/-4)
identityprovider/tests/utils.py (+20/-89)
payload/__init__.py (+5/-2)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/speed-up-tests
Reviewer Review Type Date Requested Status
Ricardo Kirkner (community) Approve
Review via email: mp+68106@code.launchpad.net

Commit message

Speed up for test suite.

Description of the change

Overview
========
This branch speeds up the test suite. On my machine it goes from 700 seconds down to ~400.

Details
=======
It was mostly accomplished by switching from django.tests.TransactionTestCase to django.tests.TestCase and fixing the cases when that change have broken.

To post a comment you must log in.
Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

Nice refactoring.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identityprovider/tests/functional/helpers.py'
2--- identityprovider/tests/functional/helpers.py 2011-05-31 15:19:26 +0000
3+++ identityprovider/tests/functional/helpers.py 2011-07-19 13:59:31 +0000
4@@ -5,7 +5,7 @@
5 from wsgi_intercept.zope_testbrowser import WSGI_Browser
6
7 from identityprovider.models.openidmodels import OpenIDRPConfig
8-from identityprovider.tests.utils import SQLCachedTestCase
9+from identityprovider.tests.utils import SSOBaseTestCase
10
11
12 class DuplicateIdError(Exception):
13@@ -28,7 +28,7 @@
14 'Found %d elements with id %r' % (len(elements_with_id), id))
15
16
17-class FunctionalTestCase(SQLCachedTestCase):
18+class FunctionalTestCase(SSOBaseTestCase):
19 functional = True
20 fixtures = ['test']
21 urls = 'identityprovider.tests.functional.urls'
22
23=== modified file 'identityprovider/tests/test_admin.py'
24--- identityprovider/tests/test_admin.py 2011-06-29 21:29:09 +0000
25+++ identityprovider/tests/test_admin.py 2011-07-19 13:59:31 +0000
26@@ -13,13 +13,12 @@
27 from identityprovider.models.const import EmailStatus
28 from identityprovider.utils import validate_launchpad_password
29
30-from utils import BasicAccountTestCase
31-
32-
33-class AdminTestCase(BasicAccountTestCase):
34-
35- fixtures = ['admin.json', 'test.json']
36- pgsql_functions = ['generate_openid_identifier']
37+from .utils import SSOBaseTestCase
38+
39+
40+class AdminTestCase(SSOBaseTestCase):
41+
42+ fixtures = ['admin', 'test']
43
44 def setUp(self):
45 self.disable_csrf()
46
47=== modified file 'identityprovider/tests/test_auth.py'
48--- identityprovider/tests/test_auth.py 2011-05-30 15:35:36 +0000
49+++ identityprovider/tests/test_auth.py 2011-07-19 13:59:31 +0000
50@@ -13,15 +13,15 @@
51 from identityprovider.models.account import Account
52 from identityprovider.models.const import AccountStatus, EmailStatus
53 from identityprovider.models.emailaddress import EmailAddress
54-from identityprovider.tests.utils import BasicAccountTestCase
55 from identityprovider.auth import (
56 LaunchpadBackend,
57 SSOOAuthAuthentication,
58 oauth_authenticate,
59 )
60-
61-
62-class LaunchpadBackendTestCase(BasicAccountTestCase):
63+from .utils import SSOBaseTestCase
64+
65+
66+class LaunchpadBackendTestCase(SSOBaseTestCase):
67
68 fixtures = ["test"]
69
70@@ -153,7 +153,8 @@
71 self.assertFalse(response)
72
73
74-class SSOOAuthAuthenticationTestCase(BasicAccountTestCase):
75+class SSOOAuthAuthenticationTestCase(SSOBaseTestCase):
76+
77 def setUp(self):
78 self.auth = SSOOAuthAuthentication()
79 # create a valid request
80
81=== modified file 'identityprovider/tests/test_backend_base.py'
82--- identityprovider/tests/test_backend_base.py 2011-05-11 15:29:56 +0000
83+++ identityprovider/tests/test_backend_base.py 2011-07-19 13:59:31 +0000
84@@ -10,8 +10,9 @@
85 DatabaseWrapper as PostgresDatabaseWrapper)
86 from django.test import TestCase
87
88-from identityprovider.backend.base import (AuthUserCache, CursorReadOnlyWrapper,
89- DatabaseError, DatabaseWrapper, BaseCache, DjangoSessionCache)
90+from identityprovider.backend.base import (
91+ AuthUserCache, CursorReadOnlyWrapper, DatabaseError, DatabaseWrapper,
92+ BaseCache, DjangoSessionCache)
93 from identityprovider.readonly import ReadOnlyManager
94 from identityprovider.utils import is_django_13
95 from identityprovider.tests.mockdb import MockCursor
96@@ -56,18 +57,17 @@
97
98 class DjangoSessionCacheTestCase(TestCase):
99
100- def test_update(self):
101- mock = MockCursor("value")
102- match = re.match(
103- CursorReadOnlyWrapper.command_patterns['update'],
104- 'UPDATE "t" SET "session_data" = %s, "expire_date" = %s '
105- 'WHERE "django_session"."session_key" = %s'
106- )
107- django_session_cache = DjangoSessionCache()
108- django_session_cache.update(match, ["a", "b", "c"], mock)
109+ def test_update(self):
110+ mock = MockCursor("value")
111+ match = re.match(
112+ CursorReadOnlyWrapper.command_patterns['update'],
113+ 'UPDATE "t" SET "session_data" = %s, "expire_date" = %s '
114+ 'WHERE "django_session"."session_key" = %s')
115+ django_session_cache = DjangoSessionCache()
116+ django_session_cache.update(match, ["a", "b", "c"], mock)
117
118- value = cache.get(django_session_cache.cache_key("c"))
119- self.assertEquals(value, "[['c', 'a', 'b']]")
120+ value = cache.get(django_session_cache.cache_key("c"))
121+ self.assertEquals(value, "[['c', 'a', 'b']]")
122
123
124 class CursorReadOnlyWrapperTestCase(TestCase):
125
126=== modified file 'identityprovider/tests/test_captcha.py'
127--- identityprovider/tests/test_captcha.py 2011-06-23 08:23:12 +0000
128+++ identityprovider/tests/test_captcha.py 2011-07-19 13:59:31 +0000
129@@ -17,7 +17,8 @@
130
131 def __enter__(self):
132 for setting, new_value in self.kwargs.items():
133- self.old_settings[setting] = getattr(settings, setting, self.marker)
134+ old_value = getattr(settings, setting, self.marker)
135+ self.old_settings[setting] = old_value
136 setattr(settings, setting, new_value)
137
138 def __exit__(self, exc_type, exc_val, exc_tb):
139
140=== modified file 'identityprovider/tests/test_command_cleanup.py'
141--- identityprovider/tests/test_command_cleanup.py 2011-06-15 16:36:56 +0000
142+++ identityprovider/tests/test_command_cleanup.py 2011-07-19 13:59:31 +0000
143@@ -16,9 +16,9 @@
144 class CleanupCommandTestCase(TestCase):
145 def tearDown(self):
146 cursor = connection.cursor()
147- cursor.execute("""TRUNCATE lp_openididentifier, account, accountpassword,
148- emailaddress, lp_person, django_session, openidnonce,
149- openidassociation CASCADE""")
150+ cursor.execute("""TRUNCATE lp_openididentifier, account,
151+ accountpassword, emailaddress, lp_person, django_session,
152+ openidnonce, openidassociation CASCADE""")
153 connection.connection.commit()
154
155 setUp = tearDown
156
157=== modified file 'identityprovider/tests/test_command_populate.py'
158--- identityprovider/tests/test_command_populate.py 2010-12-20 18:21:33 +0000
159+++ identityprovider/tests/test_command_populate.py 2011-07-19 13:59:31 +0000
160@@ -6,12 +6,13 @@
161 from identityprovider.models import (Account, AccountPassword, EmailAddress,
162 Person, LPOpenIdIdentifier, OpenIDAssociation, OpenIDNonce)
163
164+
165 class PopulateCommandTestCase(TestCase):
166 def tearDown(self):
167 cursor = connection.cursor()
168- cursor.execute("""TRUNCATE lp_openididentifier, account, accountpassword,
169- emailaddress, lp_person, django_session, openidnonce,
170- openidassociation CASCADE""")
171+ cursor.execute("""TRUNCATE lp_openididentifier, account,
172+ accountpassword, emailaddress, lp_person, django_session,
173+ openidnonce, openidassociation CASCADE""")
174 connection.connection.commit()
175
176 setUp = tearDown
177
178=== modified file 'identityprovider/tests/test_command_readonly.py'
179--- identityprovider/tests/test_command_readonly.py 2010-07-12 13:41:07 +0000
180+++ identityprovider/tests/test_command_readonly.py 2011-07-19 13:59:31 +0000
181@@ -14,11 +14,11 @@
182 remove_wsgi_intercept)
183
184 from identityprovider.readonly import ReadOnlyManager
185-from identityprovider.tests.utils import SQLCachedTestCase
186-
187-
188-class ReadonlyCommandTestCase(SQLCachedTestCase):
189- pgsql_functions = ['generate_openid_identifier']
190+
191+from .utils import SSOBaseTestCase
192+
193+
194+class ReadonlyCommandTestCase(SSOBaseTestCase):
195
196 def setUp(self):
197 self.rm = ReadOnlyManager()
198@@ -34,8 +34,7 @@
199 {'SERVER_ID': 'otherhost',
200 'HOST': 'localhost',
201 'PORT': '8001',
202- }
203- ]
204+ }]
205 self._APP_SERVERS = settings.APP_SERVERS
206 settings.APP_SERVERS = self.servers
207 self._DBFAILOVER_FLAG_DIR = getattr(settings, 'DBFAILOVER_FLAG_DIR',
208
209=== modified file 'identityprovider/tests/test_command_sqlcachedflush.py'
210--- identityprovider/tests/test_command_sqlcachedflush.py 2010-05-27 22:46:47 +0000
211+++ identityprovider/tests/test_command_sqlcachedflush.py 2011-07-19 13:59:31 +0000
212@@ -8,7 +8,7 @@
213 from django.conf import settings
214 from django.core.management import call_command
215
216-from identityprovider.tests.utils import SQLCachedTestCase
217+from identityprovider.tests.utils import SSOBaseTestCase
218
219
220 class Alarm(Exception):
221@@ -19,7 +19,8 @@
222 raise Alarm
223
224
225-class SQLCachedFlushCommandTestCase(SQLCachedTestCase):
226+class SQLCachedFlushCommandTestCase(SSOBaseTestCase):
227+
228 def setUp(self):
229 # set alarm handler
230 self.old_signal = signal.signal(signal.SIGALRM, alarm_handler)
231
232=== modified file 'identityprovider/tests/test_dbfailover.py'
233--- identityprovider/tests/test_dbfailover.py 2011-05-24 20:00:24 +0000
234+++ identityprovider/tests/test_dbfailover.py 2011-07-19 13:59:31 +0000
235@@ -9,11 +9,12 @@
236 from django.conf import settings
237 from django.db import connection
238
239-from identityprovider.tests.utils import SQLCachedTestCase
240 from identityprovider.branding import current_brand
241 from identityprovider.tests import mockdb
242+from identityprovider.tests.utils import SSOBaseTestCase
243 from identityprovider.readonly import ReadOnlyManager
244
245+
246 test_db_connections = [
247 {
248 'DATABASE_ID': 'testmaster',
249@@ -34,8 +35,7 @@
250 ]
251
252
253-class FailoverTestCase(SQLCachedTestCase):
254- pgsql_functions = ['generate_openid_identifier']
255+class FailoverTestCase(SSOBaseTestCase):
256
257 def __init__(self, methodName='runTest'):
258 super(FailoverTestCase, self).__init__(methodName)
259
260=== modified file 'identityprovider/tests/test_fields.py'
261--- identityprovider/tests/test_fields.py 2011-05-24 19:28:51 +0000
262+++ identityprovider/tests/test_fields.py 2011-07-19 13:59:31 +0000
263@@ -121,7 +121,6 @@
264 forms.ValidationError, otp_field.clean, otp)
265
266
267-
268 class OneTimePaswordFieldWithMockServerTestCase(WSGIInterceptedTestCase):
269
270 def setUp(self):
271
272=== modified file 'identityprovider/tests/test_forms.py'
273--- identityprovider/tests/test_forms.py 2011-07-11 21:05:24 +0000
274+++ identityprovider/tests/test_forms.py 2011-07-19 13:59:31 +0000
275@@ -19,10 +19,12 @@
276 from identityprovider.api10.forms import WebserviceCreateAccountForm
277 from identityprovider.models.openidmodels import OpenIDRPConfig
278
279-from utils import BasicAccountTestCase, SQLCachedTestCase
280-
281-
282-class EditAccountFormTest(BasicAccountTestCase):
283+from .utils import SSOBaseTestCase
284+
285+
286+class EditAccountFormTest(SSOBaseTestCase):
287+
288+ fixtures = ["test"]
289
290 def test_initial_displayname(self):
291 account = Account.objects.get(openid_identifier='name12_oid')
292@@ -79,7 +81,7 @@
293 self.assertEqual(0, len(form.non_field_errors()))
294
295
296-class WebServiceCreateAccountFormTest(SQLCachedTestCase):
297+class WebServiceCreateAccountFormTest(SSOBaseTestCase):
298
299 def setUp(self):
300 self.old_dcv = settings.DISABLE_CAPTCHA_VERIFICATION
301@@ -125,7 +127,7 @@
302 self.assertEqual(form.cleaned_data['validate_redirect_to'], None)
303
304
305-class ResetPasswordFormTest(SQLCachedTestCase):
306+class ResetPasswordFormTest(SSOBaseTestCase):
307
308 def test_nonascii_password(self):
309 data = {'password': 'Ñandú'}
310@@ -135,8 +137,7 @@
311 'Invalid characters in password')
312
313
314-class SRegRequestFormTest(SQLCachedTestCase):
315- pgsql_functions = ['generate_openid_identifier']
316+class SRegRequestFormTest(SSOBaseTestCase):
317
318 def _get_request_with_post_args(self, args={}):
319 request = HttpRequest()
320@@ -269,7 +270,7 @@
321 self.assertTrue(form.check_test('email'))
322
323
324-class TeamsRequestFormTest(BasicAccountTestCase):
325+class TeamsRequestFormTest(SSOBaseTestCase):
326
327 fixtures = ["test"]
328
329@@ -381,7 +382,7 @@
330 self.assertFalse(form2.check_test('ubuntu-team'))
331
332
333-class TokenForrmTest(SQLCachedTestCase):
334+class TokenForrmTest(SSOBaseTestCase):
335
336 def test_confirmation_code_error(self):
337 data = {'confirmation_code': 'BOGUS', 'email': 'fake@example.com'}
338
339=== modified file 'identityprovider/tests/test_handlers.py'
340--- identityprovider/tests/test_handlers.py 2011-07-11 14:33:55 +0000
341+++ identityprovider/tests/test_handlers.py 2011-07-19 13:59:31 +0000
342@@ -3,7 +3,7 @@
343 from django.utils import simplejson
344 from mock import patch
345
346-from identityprovider.tests.utils import SQLCachedTestCase
347+from identityprovider.tests.utils import SSOBaseTestCase
348 from identityprovider.models import (
349 Account,
350 APIUser,
351@@ -31,7 +31,7 @@
352 self.data = data
353 self.environ = {'REMOTE_ADDR': '127.0.0.1'}
354
355-class RegistrationHandlerTestCase(SQLCachedTestCase):
356+class RegistrationHandlerTestCase(SSOBaseTestCase):
357
358 fixtures = ["test"]
359 pgsql_functions = ["generate_openid_identifier"]
360@@ -237,7 +237,7 @@
361 displayname='', password='the_password')
362
363
364-class AuthenticationTestCase(SQLCachedTestCase):
365+class AuthenticationTestCase(SSOBaseTestCase):
366
367 fixtures = ["test"]
368
369
370=== modified file 'identityprovider/tests/test_language_selection.py'
371--- identityprovider/tests/test_language_selection.py 2010-05-13 12:50:22 +0000
372+++ identityprovider/tests/test_language_selection.py 2011-07-19 13:59:31 +0000
373@@ -1,7 +1,7 @@
374-from identityprovider.tests.utils import BasicAccountTestCase
375-
376-
377-class SelectLanguagePageTestCase(BasicAccountTestCase):
378+from identityprovider.tests.utils import SSOBaseTestCase
379+
380+
381+class SelectLanguagePageTestCase(SSOBaseTestCase):
382
383 def setUp(self):
384 self.client.login(username='mark@example.com', password='test')
385
386=== modified file 'identityprovider/tests/test_loginservice.py'
387--- identityprovider/tests/test_loginservice.py 2010-10-01 11:50:37 +0000
388+++ identityprovider/tests/test_loginservice.py 2011-07-19 13:59:31 +0000
389@@ -5,10 +5,11 @@
390
391 from identityprovider.branding import current_brand
392 from identityprovider.models.authtoken import AuthToken
393-from utils import BasicAccountTestCase, SQLCachedTestCase
394-
395-
396-class LoginTest(SQLCachedTestCase):
397+
398+from .utils import SSOBaseTestCase
399+
400+
401+class LoginTest(SSOBaseTestCase):
402
403 def test_loginform_password_did_not_match_error(self):
404 r = self.client.post('/+login', {'email': "mark@example.com",
405@@ -25,7 +26,7 @@
406 self.assertFormError(r, 'form', 'password', "Required field.")
407
408
409-class NewAccountTest(BasicAccountTestCase):
410+class NewAccountTest(SSOBaseTestCase):
411
412 def test_newaccount_existing(self):
413 query = {
414@@ -38,7 +39,9 @@
415 self.assertEquals(len(mail.outbox), 0)
416
417
418-class ForgottenPasswordTest(BasicAccountTestCase):
419+class ForgottenPasswordTest(SSOBaseTestCase):
420+
421+ fixtures = ["test"]
422
423 def test_forgottenpass_nonexisting(self):
424 query = {
425@@ -70,3 +73,4 @@
426 mail.outbox = []
427
428 AuthToken.objects.all().delete()
429+
430
431=== modified file 'identityprovider/tests/test_middleware.py'
432--- identityprovider/tests/test_middleware.py 2011-07-08 13:37:36 +0000
433+++ identityprovider/tests/test_middleware.py 2011-07-19 13:59:31 +0000
434@@ -7,18 +7,20 @@
435
436 import django
437 from django.conf import settings
438+from django.test import TestCase
439 from django.contrib.auth.models import User, AnonymousUser
440
441-from openid.message import (IDENTIFIER_SELECT, OPENID1_URL_LIMIT, OPENID2_NS)
442+from openid.message import IDENTIFIER_SELECT, OPENID1_URL_LIMIT, OPENID2_NS
443
444-from identityprovider.tests.utils import (BasicAccountTestCase, MockRequest,
445- TestCase)
446+from identityprovider.tests.utils import MockRequest, TestCase
447 from identityprovider.models import Account, EmailAddress, OpenIDRPConfig
448 from identityprovider.middleware.exception import LogExceptionMiddleware
449 from identityprovider.middleware.useraccount import (
450 UserAccountConversionMiddleware)
451 from identityprovider.utils import is_django_13
452
453+from .utils import SSOBaseTestCase
454+
455
456 def _extract_csrf_token(response):
457 csrf_field = re.search('<input [^>]*name=[\'"]csrfmiddlewaretoken[\'"]'
458@@ -27,8 +29,7 @@
459 csrf_field.group()).group(1)
460
461
462-
463-class UserAccountConversionMiddlewareTestCase(BasicAccountTestCase):
464+class UserAccountConversionMiddlewareTestCase(SSOBaseTestCase):
465
466 fixtures = ['test']
467
468@@ -156,7 +157,7 @@
469
470 # The CSRF middleware requires a session cookie in order to activate.
471 # The tests perform a login in order to acquire this session cookie.
472-class CSRFMiddlewareTestCase(BasicAccountTestCase):
473+class CSRFMiddlewareTestCase(SSOBaseTestCase):
474
475 fixtures = ['test']
476
477
478=== modified file 'identityprovider/tests/test_models_account.py'
479--- identityprovider/tests/test_models_account.py 2011-07-15 12:29:59 +0000
480+++ identityprovider/tests/test_models_account.py 2011-07-19 13:59:31 +0000
481@@ -2,12 +2,13 @@
482 # GNU Affero General Public License version 3 (see the file LICENSE).
483
484 from datetime import datetime, timedelta
485+
486 from django.conf import settings
487 from django.contrib.auth.models import User
488+from django.test import TestCase
489
490 from oauth_backend.models import Consumer
491
492-from identityprovider.tests.utils import BasicAccountTestCase
493 from identityprovider.models.account import (Account, AccountPassword,
494 AccountStatus)
495 from identityprovider.models import account as a
496@@ -16,6 +17,8 @@
497 from identityprovider.readonly import ReadOnlyManager
498 from identityprovider.utils import encrypt_launchpad_password, generate_salt
499
500+from .utils import SSOBaseTestCase
501+
502
503 class MockBackend(object):
504
505@@ -29,7 +32,7 @@
506 return self.value
507
508
509-class AccountTestCase(BasicAccountTestCase):
510+class AccountTestCase(SSOBaseTestCase):
511
512 fixtures = ["test"]
513
514@@ -331,23 +334,22 @@
515 self.assertEqual(sites_count, 1)
516
517
518-class AccountPasswordTestCase(BasicAccountTestCase):
519+class AccountPasswordTestCase(TestCase):
520+
521 def test_unicode(self):
522 account = Account(openid_identifier='oid', displayname='displayname')
523 password = AccountPassword(account=account, password='password')
524 self.assertEqual(unicode(password), u'Password for displayname')
525
526
527-class CreateOAuthTokenForAccountTestCase(BasicAccountTestCase):
528+class CreateOAuthTokenForAccountTestCase(SSOBaseTestCase):
529
530 def setUp(self):
531 self.account = Account.objects.create_account(
532- 'test', 'test-oauth@example.com', 'password'
533- )
534+ 'test', 'test-oauth@example.com', 'password')
535 self.user = User.objects.create_user(
536 self.account.openid_identifier,
537- 'test@example.com', 'password'
538- )
539+ 'test@example.com', 'password')
540
541 def test_when_account_has_associated_consumer(self):
542 consumer, _ = Consumer.objects.get_or_create(user=self.user)
543
544=== modified file 'identityprovider/tests/test_models_api.py'
545--- identityprovider/tests/test_models_api.py 2011-02-20 23:49:21 +0000
546+++ identityprovider/tests/test_models_api.py 2011-07-19 13:59:31 +0000
547@@ -5,11 +5,13 @@
548 from identityprovider.models.emailaddress import EmailAddress
549 from identityprovider.models.const import EmailStatus
550 from identityprovider.models.api import APIUser
551-from identityprovider.tests.utils import SQLCachedTestCase
552 from identityprovider.utils import encrypt_launchpad_password, generate_salt
553
554-
555-class APIUserTestCase(SQLCachedTestCase):
556+from .utils import SSOBaseTestCase
557+
558+
559+class APIUserTestCase(SSOBaseTestCase):
560+
561 def setUp(self):
562 super(APIUserTestCase, self).setUp()
563
564
565=== modified file 'identityprovider/tests/test_models_authtoken.py'
566--- identityprovider/tests/test_models_authtoken.py 2011-07-12 21:42:47 +0000
567+++ identityprovider/tests/test_models_authtoken.py 2011-07-19 13:59:31 +0000
568@@ -9,13 +9,14 @@
569 patch,
570 )
571
572-from identityprovider.tests.utils import BasicAccountTestCase
573 from identityprovider.models.account import Account
574 from identityprovider.models import authtoken
575 from identityprovider.models.authtoken import (AuthToken, AuthTokenFactory,
576 send_validation_email_request, create_unique_token_for_table, valid_email)
577 from identityprovider.models.const import EmailStatus, LoginTokenType
578
579+from .utils import SSOBaseTestCase
580+
581
582 class MockRenderToString(object):
583
584@@ -30,7 +31,10 @@
585 return self.return_value
586
587
588-class AuthTokenTestCase(BasicAccountTestCase):
589+class AuthTokenTestCase(SSOBaseTestCase):
590+
591+ fixtures = ["test"]
592+
593 def setUp(self):
594 def mock_send_email(self, from_name, subject, message):
595 self.message = message
596
597=== modified file 'identityprovider/tests/test_models_emailaddress.py'
598--- identityprovider/tests/test_models_emailaddress.py 2010-05-07 20:29:41 +0000
599+++ identityprovider/tests/test_models_emailaddress.py 2011-07-19 13:59:31 +0000
600@@ -1,8 +1,8 @@
601 from identityprovider.models import Account, EmailAddress, Person
602-from identityprovider.tests.utils import BasicAccountTestCase
603-
604-
605-class EmailAddressTestCase(BasicAccountTestCase):
606+from identityprovider.tests.utils import SSOBaseTestCase
607+
608+
609+class EmailAddressTestCase(SSOBaseTestCase):
610 fixtures = ['test']
611
612 def test_emailaddress_with_account_and_person(self):
613
614=== modified file 'identityprovider/tests/test_models_openidmodels.py'
615--- identityprovider/tests/test_models_openidmodels.py 2011-06-29 21:29:09 +0000
616+++ identityprovider/tests/test_models_openidmodels.py 2011-07-19 13:59:31 +0000
617@@ -12,11 +12,11 @@
618 from identityprovider.models.openidmodels import (DjangoOpenIDStore,
619 OpenIDAssociation, OpenIDAuthorization, OpenIDNonce, OpenIDRPConfig,
620 OpenIDRPSummary)
621+from identityprovider.tests.utils import SSOBaseTestCase
622 from identityprovider.readonly import ReadOnlyManager
623-from identityprovider.tests.utils import BasicAccountTestCase
624-
625-
626-class DjangoOpenIDStoreTestCase(BasicAccountTestCase):
627+
628+
629+class DjangoOpenIDStoreTestCase(SSOBaseTestCase):
630
631 def setUp(self):
632 self.server_url = 'http://server.example.com'
633@@ -117,7 +117,7 @@
634 self.assertEqual(OpenIDAssociation.objects.all().count(), 0)
635
636
637-class OpenIDRPConfigTestCase(BasicAccountTestCase):
638+class OpenIDRPConfigTestCase(SSOBaseTestCase):
639
640 def setUp(self):
641 self.rp_config = OpenIDRPConfig()
642@@ -138,7 +138,7 @@
643 self.assertEqual(unicode(self.rp_config), u'MyOpenIDRPConfig')
644
645
646-class OpenIDAssociationTestCase(BasicAccountTestCase):
647+class OpenIDAssociationTestCase(SSOBaseTestCase):
648 fixtures = ['multiple_associations']
649
650 def test_create_association(self):
651@@ -151,7 +151,10 @@
652 issued=time(), lifetime=1000, assoc_type='HMAC-SHA1')
653
654
655-class OpenIDAuthorizationTestCase(BasicAccountTestCase):
656+class OpenIDAuthorizationTestCase(SSOBaseTestCase):
657+
658+ fixtures = ["test"]
659+
660 def setUp(self):
661 self.account = Account.objects.get_by_email('test@canonical.com')
662 self.trust_root = 'http://openid.launchpad.dev'
663@@ -218,7 +221,10 @@
664 self.trust_root, 'client'))
665
666
667-class OpenIDRPSummaryTestCase(BasicAccountTestCase):
668+class OpenIDRPSummaryTestCase(SSOBaseTestCase):
669+
670+ fixtures = ["test"]
671+
672 approved_data = {
673 'test1': {'one': [1, 2], 'two': [2, 3]},
674 'test2': {'three': [3, 4], 'four': [4, 5]}}
675
676=== modified file 'identityprovider/tests/test_models_person.py'
677--- identityprovider/tests/test_models_person.py 2010-12-20 16:19:03 +0000
678+++ identityprovider/tests/test_models_person.py 2011-07-19 13:59:31 +0000
679@@ -7,10 +7,10 @@
680 AccountStatus)
681 from identityprovider.models.person import Person
682 from identityprovider.models.team import TeamParticipation
683-from identityprovider.tests.utils import SQLCachedTestCase
684-
685-
686-class PersonTestCase(SQLCachedTestCase):
687+from identityprovider.tests.utils import SSOBaseTestCase
688+
689+
690+class PersonTestCase(SSOBaseTestCase):
691
692 pgsql_functions = ['generate_openid_identifier']
693
694
695=== modified file 'identityprovider/tests/test_models_team.py'
696--- identityprovider/tests/test_models_team.py 2011-07-01 19:47:04 +0000
697+++ identityprovider/tests/test_models_team.py 2011-07-19 13:59:31 +0000
698@@ -11,13 +11,12 @@
699 TeamMembership,
700 TeamParticipation,
701 )
702-from identityprovider.tests.utils import (
703- BasicAccountTestCase,
704- SQLCachedTestCase,
705-)
706-
707-
708-class TeamParticipationTestCase(SQLCachedTestCase):
709+
710+from .utils import SSOBaseTestCase
711+
712+
713+class TeamParticipationTestCase(SSOBaseTestCase):
714+
715 def test_unicode(self):
716 team = Person.objects.create(displayname='Team', name='team')
717 person = Person.objects.create(displayname='Person', name='person')
718@@ -25,7 +24,7 @@
719 self.assertEqual(unicode(tp), u'Person in Team')
720
721
722-class TeamMembershipTest(BasicAccountTestCase):
723+class TeamMembershipTest(SSOBaseTestCase):
724
725 fixtures = ["test"]
726
727
728=== modified file 'identityprovider/tests/test_readonly.py'
729--- identityprovider/tests/test_readonly.py 2011-07-08 13:37:36 +0000
730+++ identityprovider/tests/test_readonly.py 2011-07-19 13:59:31 +0000
731@@ -14,14 +14,14 @@
732 from django.utils import simplejson
733
734 from identityprovider.readonly import ReadOnlyManager
735-from identityprovider.tests.utils import SQLCachedTestCase, BasicAccountTestCase
736 from identityprovider import models
737 from identityprovider.backend.base import DatabaseError
738 from identityprovider.views.readonly import (_remote_req, get_server_atts,
739 update_server)
740-
741-
742-class InReadOnlyTestCase(SQLCachedTestCase):
743+from identityprovider.tests.utils import SSOBaseTestCase
744+
745+
746+class InReadOnlyTestCase(SSOBaseTestCase):
747
748 def setUp(self):
749 self.rm = ReadOnlyManager()
750@@ -72,7 +72,7 @@
751 settings.DATABASE_ID = old_DATABASE_ID
752
753
754-class RemoteRequestTest(SQLCachedTestCase):
755+class RemoteRequestTest(SSOBaseTestCase):
756 msg = 'hello'
757 host = 'myhost'
758 scheme = 'https'
759@@ -130,7 +130,7 @@
760 self.restore_orig_urlopen()
761
762
763-class ReadOnlyBackUp(SQLCachedTestCase):
764+class ReadOnlyBackUp(SSOBaseTestCase):
765 """A base TestCase for backing up and restoring our readonly settings"""
766 pgsql_functions = ['generate_openid_identifier']
767
768@@ -338,8 +338,7 @@
769 self.assertTrue(data['readonly'])
770
771
772-class ReadOnlyViewsTestCase(ReadOnlyBackUp, BasicAccountTestCase):
773- pgsql_functions = ['generate_openid_identifier']
774+class ReadOnlyViewsTestCase(ReadOnlyBackUp):
775
776 def login_with_staff(self):
777 user = User.objects.create(username='admin')
778@@ -528,8 +527,6 @@
779
780 class ReadOnlyViews(InReadOnlyTestCase):
781
782- pgsql_functions = ['generate_openid_identifier']
783-
784 def test_new_account_is_rendered_using_read_only_template(self):
785 settings.READ_ONLY_MODE = True
786 r = self.client.get('/+new_account')
787
788=== modified file 'identityprovider/tests/test_static.py'
789--- identityprovider/tests/test_static.py 2010-10-27 18:18:48 +0000
790+++ identityprovider/tests/test_static.py 2011-07-19 13:59:31 +0000
791@@ -7,15 +7,14 @@
792
793 import identityprovider.branding
794 import identityprovider.context_processors
795-from identityprovider.tests.utils import BasicAccountTestCase, SQLCachedTestCase
796+from identityprovider.tests.utils import SSOBaseTestCase
797
798
799 class DummyRequest(object):
800 META = {}
801
802
803-class BrandingTestCase(SQLCachedTestCase):
804- pgsql_functions = ['generate_openid_identifier']
805+class BrandingTestCase(SSOBaseTestCase):
806
807 def setUp(self):
808 self.BRAND = settings.BRAND
809@@ -52,8 +51,9 @@
810 self.assertContains(response, 'recognised by Launchpad')
811
812
813-class StaticPageTestCase(BasicAccountTestCase):
814- pgsql_functions = ['generate_openid_identifier']
815+class StaticPageTestCase(SSOBaseTestCase):
816+
817+ fixtures = ["test"]
818
819 def setUp(self):
820 self.brand = settings.BRAND
821
822=== modified file 'identityprovider/tests/test_teams.py'
823--- identityprovider/tests/test_teams.py 2010-05-18 19:37:59 +0000
824+++ identityprovider/tests/test_teams.py 2011-07-19 13:59:31 +0000
825@@ -7,11 +7,12 @@
826
827 from identityprovider.teams import (supportsTeams, getTeamsNS, ns_uri,
828 TeamsNamespaceError, TeamsRequest, TeamsResponse)
829-from identityprovider.tests.utils import SQLCachedTestCase
830+from identityprovider.tests.utils import SSOBaseTestCase
831 from identityprovider.views import server
832
833
834-class TeamsTestCase(SQLCachedTestCase):
835+class TeamsTestCase(SSOBaseTestCase):
836+
837 def test_supportsTeams(self):
838 endpoint = OpenIDServiceEndpoint()
839 endpoint.type_uris.append(ns_uri)
840@@ -24,7 +25,7 @@
841 self.assertFalse(r)
842
843
844-class GetTeamsNSTestCase(SQLCachedTestCase):
845+class GetTeamsNSTestCase(SSOBaseTestCase):
846 def setUp(self):
847 super(GetTeamsNSTestCase, self).setUp()
848
849@@ -49,7 +50,7 @@
850 self.assertRaises(TeamsNamespaceError, getTeamsNS, message)
851
852
853-class TeamsRequestTestCase(SQLCachedTestCase):
854+class TeamsRequestTestCase(SSOBaseTestCase):
855 def setUp(self):
856 super(TeamsRequestTestCase, self).setUp()
857
858@@ -129,7 +130,8 @@
859 self.assertEqual(req.getExtensionArgs(), expected)
860
861
862-class TeamsResponseTestCase(SQLCachedTestCase):
863+class TeamsResponseTestCase(SSOBaseTestCase):
864+
865 def test_init(self):
866 resp = TeamsResponse()
867 self.assertEqual(resp.is_member, [])
868
869=== modified file 'identityprovider/tests/test_utils.py'
870--- identityprovider/tests/test_utils.py 2010-12-20 17:14:26 +0000
871+++ identityprovider/tests/test_utils.py 2011-07-19 13:59:31 +0000
872@@ -5,8 +5,7 @@
873 from unittest import TestCase
874 from django.utils.translation import ugettext as _
875
876-from identityprovider.tests.utils import (BasicAccountTestCase,
877- LPAccountTestCase, SQLCachedTestCase)
878+from identityprovider.tests.utils import (SSOBaseTestCase, LPAccountTestCase)
879 from identityprovider.models.person import Person
880 from identityprovider.models.account import LPOpenIdIdentifier
881 from identityprovider.models.emailaddress import EmailAddress
882@@ -16,7 +15,7 @@
883 PersonAndAccountNotFoundException, http_request_with_timeout)
884
885
886-class CanonicalUrlTestCase(SQLCachedTestCase):
887+class CanonicalUrlTestCase(SSOBaseTestCase):
888
889 def test_when_object_is_not_person(self):
890 self.assertTrue(canonical_url(None) is None)
891@@ -30,7 +29,7 @@
892 self.assertEquals(url, "https://launchpad.net/~test/TEST")
893
894
895-class GetPersonAndAccountByEmailTestCase(BasicAccountTestCase):
896+class GetPersonAndAccountByEmailTestCase(SSOBaseTestCase):
897
898 fixtures = ["test"]
899
900@@ -47,6 +46,8 @@
901
902 class LPGetPersonAndAccountByEmailTestCase(LPAccountTestCase):
903
904+ fixtures = ["test"]
905+
906 def test_person_does_not_exist(self):
907 LPOpenIdIdentifier.objects.all().delete()
908
909@@ -55,13 +56,13 @@
910 self.assertEquals(None, person)
911
912
913-class PasswordPolicyCompliantTestCase(SQLCachedTestCase):
914+class PasswordPolicyCompliantTestCase(SSOBaseTestCase):
915
916 def test_when_password_is_to_short(self):
917 self.assertFalse(password_policy_compliant('a'))
918
919
920-class PoliteFormErrorsTestCase(SQLCachedTestCase):
921+class PoliteFormErrorsTestCase(SSOBaseTestCase):
922
923 def test_polite_errors(self):
924 text = _("Enter a valid e-mail address.")
925@@ -72,7 +73,7 @@
926 self.assertTrue(errors['email'][0] != text)
927
928
929-class ValidateLaunchpadPasswordTestCase(SQLCachedTestCase):
930+class ValidateLaunchpadPasswordTestCase(SSOBaseTestCase):
931
932 def test_when_there_is_binascii_error_is_raised(self):
933 self.assertFalse(validate_launchpad_password('a', 'b'))
934
935=== modified file 'identityprovider/tests/test_views_account.py'
936--- identityprovider/tests/test_views_account.py 2011-01-10 15:02:53 +0000
937+++ identityprovider/tests/test_views_account.py 2011-07-19 13:59:31 +0000
938@@ -11,10 +11,10 @@
939 from identityprovider.models.const import AccountStatus, EmailStatus
940 from identityprovider.utils import validate_launchpad_password
941
942-from utils import BasicAccountTestCase, AuthenticatedTestCase
943-
944-
945-class AccountViewsUnauthenticatedTestCase(BasicAccountTestCase):
946+from utils import SSOBaseTestCase, AuthenticatedTestCase
947+
948+
949+class AccountViewsUnauthenticatedTestCase(SSOBaseTestCase):
950
951 def test_index_unauthenticated(self):
952 r = self.client.get('/+edit')
953@@ -180,7 +180,9 @@
954 'raw_orequest content')
955
956
957-class ApplicationsTestCase(BasicAccountTestCase):
958+class ApplicationsTestCase(SSOBaseTestCase):
959+
960+ fixtures = ["test"]
961
962 def setUp(self):
963 self.client.login(username="mark@example.com", password="test")
964
965=== modified file 'identityprovider/tests/test_views_consumer.py'
966--- identityprovider/tests/test_views_consumer.py 2010-11-25 00:19:08 +0000
967+++ identityprovider/tests/test_views_consumer.py 2011-07-19 13:59:31 +0000
968@@ -12,16 +12,18 @@
969 from openid.yadis.constants import YADIS_CONTENT_TYPE
970 from urllib import quote_plus
971
972+
973 # need to override fetcher before consumer module gets imported
974 class MockFetcher(fetchers.Urllib2Fetcher):
975+
976 called = False
977+
978 def fetch(self, url, body=None, headers=None):
979 MockFetcher.called = True
980 return super(MockFetcher, self).fetch(url, body, headers)
981
982 fetchers.Urllib2Fetcher = MockFetcher
983-from identityprovider.tests.utils import (SQLCachedTestCase,
984- OpenIDProviderTestCase)
985+from identityprovider.tests.utils import SSOBaseTestCase
986 from identityprovider.views import server
987 from identityprovider.views.consumer import (SREG_DONT_REQUEST, SREG_OPTIONAL,
988 SREG_REQUIRED, getBaseURL, normalDict, getOpenIDStore, getConsumer,
989@@ -99,7 +101,8 @@
990 self.assertTrue(fullname in response.content)
991
992
993-class ConsumerTestCase(OpenIDProviderTestCase):
994+class ConsumerTestCase(SSOBaseTestCase):
995+
996 def setUp(self):
997 super(ConsumerTestCase, self).setUp()
998
999
1000=== modified file 'identityprovider/tests/test_views_i18n.py'
1001--- identityprovider/tests/test_views_i18n.py 2010-05-17 12:35:48 +0000
1002+++ identityprovider/tests/test_views_i18n.py 2011-07-19 13:59:31 +0000
1003@@ -1,8 +1,10 @@
1004-from identityprovider.tests.utils import BasicAccountTestCase
1005+from identityprovider.tests.utils import SSOBaseTestCase
1006 from identityprovider.models.account import Account
1007
1008
1009-class SetLanguageTestCase(BasicAccountTestCase):
1010+class SetLanguageTestCase(SSOBaseTestCase):
1011+
1012+ fixtures = ["test"]
1013
1014 def setUp(self):
1015 self.disable_csrf()
1016
1017=== modified file 'identityprovider/tests/test_views_preflight.py'
1018--- identityprovider/tests/test_views_preflight.py 2011-03-04 17:09:45 +0000
1019+++ identityprovider/tests/test_views_preflight.py 2011-07-19 13:59:31 +0000
1020@@ -1,10 +1,10 @@
1021 from django.conf import settings
1022
1023 from identityprovider.models.account import Account
1024-from identityprovider.tests.utils import BasicAccountTestCase
1025-
1026-
1027-class PreflightViewAccessTestCase(BasicAccountTestCase):
1028+from identityprovider.tests.utils import SSOBaseTestCase
1029+
1030+
1031+class PreflightViewAccessTestCase(SSOBaseTestCase):
1032
1033 fixtures = ["test"]
1034 URL = '/preflight/'
1035
1036=== modified file 'identityprovider/tests/test_views_server.py'
1037--- identityprovider/tests/test_views_server.py 2011-07-12 13:40:12 +0000
1038+++ identityprovider/tests/test_views_server.py 2011-07-19 13:59:31 +0000
1039@@ -29,8 +29,8 @@
1040 from identityprovider.models.authtoken import create_token
1041
1042 from identityprovider.views import server
1043-from identityprovider.tests.utils import (SQLCachedTestCase,
1044- BasicAccountTestCase, AuthenticatedTestCase, OpenIDProviderTestCase)
1045+
1046+from .utils import SSOBaseTestCase, AuthenticatedTestCase
1047
1048
1049 class DummyORequest(object):
1050@@ -61,7 +61,7 @@
1051 self.META = {}
1052
1053
1054-class HandleOpenIDErrorTestCase(OpenIDProviderTestCase):
1055+class HandleOpenIDErrorTestCase(SSOBaseTestCase):
1056
1057 # tests for the _handle_openid_error method
1058
1059@@ -84,7 +84,7 @@
1060 self.assertTrue(error_msg in r.content)
1061
1062
1063-class ProcessOpenIDRequestTestCase(OpenIDProviderTestCase):
1064+class ProcessOpenIDRequestTestCase(SSOBaseTestCase):
1065
1066 # tests for the _process_openid_request method
1067
1068@@ -94,7 +94,7 @@
1069 self.assertTemplateUsed(r, 'server_info.html')
1070
1071
1072-class HandleUserResponseTestCase(OpenIDProviderTestCase):
1073+class HandleUserResponseTestCase(SSOBaseTestCase):
1074 fixtures = ['test']
1075
1076 def setUp(self):
1077@@ -223,7 +223,7 @@
1078 self.assertEqual('de', self.client.session['django_language'])
1079
1080
1081-class ValidOpenIDTestCase(OpenIDProviderTestCase):
1082+class ValidOpenIDTestCase(SSOBaseTestCase):
1083
1084 def test_is_valid_openid_idselect(self):
1085 valid = server._is_valid_openid_for_this_site(IDENTIFIER_SELECT)
1086@@ -283,8 +283,7 @@
1087 self.assertFalse(valid)
1088
1089
1090-class DecideTestCase(AuthenticatedTestCase, OpenIDProviderTestCase):
1091- fixtures = ['test']
1092+class DecideTestCase(AuthenticatedTestCase):
1093
1094 def _prepare_openid_token(self, param_overrides=None):
1095 request = {'openid.mode': 'checkid_setup',
1096@@ -617,7 +616,7 @@
1097 settings.OPENID_PREAUTHORIZATION_ACL = old_OPENID_PREAUTHORIZATION_ACL
1098
1099
1100-class CancelTestCase(AuthenticatedTestCase, OpenIDProviderTestCase):
1101+class CancelTestCase(AuthenticatedTestCase):
1102 def setUp(self):
1103 super(CancelTestCase, self).setUp(disableCSRF=True)
1104
1105@@ -670,7 +669,7 @@
1106 self.assertEqual(query['openid.mode'], 'cancel')
1107
1108
1109-class XRDSTestCase(OpenIDProviderTestCase):
1110+class XRDSTestCase(SSOBaseTestCase):
1111 fixtures = ['test']
1112
1113 def assert_xrds_document(self, response, template=None):
1114@@ -792,7 +791,7 @@
1115 self.assertTrue(r)
1116
1117
1118-class ShouldReauthenticateTestCase(SQLCachedTestCase):
1119+class ShouldReauthenticateTestCase(SSOBaseTestCase):
1120 fixtures = ['test']
1121
1122 def setUp(self):
1123@@ -864,7 +863,7 @@
1124 self.assertFalse(r)
1125
1126
1127-class UntrustedRPTest(OpenIDProviderTestCase):
1128+class UntrustedRPTest(SSOBaseTestCase):
1129 fixtures = ['test']
1130
1131 def setUp(self):
1132@@ -905,7 +904,10 @@
1133 self.assertTemplateUsed(r, 'untrusted.html')
1134
1135
1136-class TestSregFields(BasicAccountTestCase):
1137+class TestSregFields(SSOBaseTestCase):
1138+
1139+ fixtures = ["test"]
1140+
1141 def setUp(self):
1142 super(TestSregFields, self).setUp()
1143
1144@@ -933,10 +935,9 @@
1145 self.request.user = self.account
1146
1147
1148-class MarkupTestCase(SQLCachedTestCase):
1149+class MarkupTestCase(SSOBaseTestCase):
1150
1151 fixtures = ["test"]
1152- pgsql_functions = ["generate_openid_identifier"]
1153
1154 def test_untrusted_rp_properly_shows_markup(self):
1155 self.client.login(username='mark@example.com', password='test')
1156@@ -950,7 +951,7 @@
1157 self.assertContains(r, '<em>not</em>')
1158
1159
1160-class ApprovedDataTest(OpenIDProviderTestCase):
1161+class ApprovedDataTest(SSOBaseTestCase):
1162 fixtures = ['test']
1163
1164 def _get_openid_request(self, with_sreg=True, with_teams=True):
1165
1166=== modified file 'identityprovider/tests/test_views_ui.py'
1167--- identityprovider/tests/test_views_ui.py 2011-07-15 19:24:52 +0000
1168+++ identityprovider/tests/test_views_ui.py 2011-07-19 13:59:31 +0000
1169@@ -28,12 +28,13 @@
1170 from identityprovider.models.captcha import Captcha
1171 from identityprovider.models.const import AccountStatus, LoginTokenType
1172 from identityprovider.tests.utils import (
1173- BasicAccountTestCase,
1174- LPAccountTestCase, SQLCachedTestCase,
1175+ LPAccountTestCase,
1176 MockHandler,
1177 )
1178 from identityprovider.utils import is_django_13
1179
1180+from .utils import SSOBaseTestCase
1181+
1182
1183 def _post_new_account(client, email='person@example.com', token=None, follow=False):
1184 if token is None:
1185@@ -47,17 +48,14 @@
1186 'passwordconfirm': 'Testing123'}, follow=follow)
1187
1188
1189-class UIViewsHelperTestCase(SQLCachedTestCase):
1190-
1191+class UIViewsHelperTestCase(SSOBaseTestCase):
1192
1193 def test_is_safe_redirect_url_return_false(self):
1194 self.assertFalse(ui._is_safe_redirect_url('non-existing'))
1195
1196-
1197 def test_is_safe_redirect_url_with_params(self):
1198 self.assertFalse(ui._is_safe_redirect_url('non-existing?q=some_value'))
1199
1200-
1201 @patch('identityprovider.views.ui.resolve')
1202 def test_is_safe_redirect_url_404(self, mock_resolve):
1203 mock_resolve.side_effect = Resolver404()
1204@@ -65,19 +63,17 @@
1205 self.assertFalse(ui._is_safe_redirect_url('non-existing'))
1206
1207
1208-
1209-class SpanishUIViewsTestCase(BasicAccountTestCase):
1210-
1211+class SpanishUIViewsTestCase(SSOBaseTestCase):
1212+
1213+ fixtures = ["test"]
1214
1215 def setUp(self):
1216 self.language_code = settings.LANGUAGE_CODE
1217 settings.LANGUAGE_CODE = 'es'
1218
1219-
1220 def tearDown(self):
1221 settings.LANGUAGE_CODE = self.language_code
1222
1223-
1224 def test_new_account_in_spanish(self):
1225 account = Account.objects.get_by_email('mark@example.com')
1226 account.status = AccountStatus.ACTIVE
1227@@ -89,8 +85,9 @@
1228 self.assertEqual(len(mail.outbox), 1)
1229
1230
1231+class UIViewsTestCase(SSOBaseTestCase):
1232
1233-class UIViewsTestCase(BasicAccountTestCase):
1234+ fixtures = ["test"]
1235
1236 def setUp(self):
1237 logging.disable(logging.WARNING)
1238@@ -169,7 +166,7 @@
1239 'Your account has been deactivated')
1240
1241 def test_login_without_next_with_token(self):
1242- token = 'a'*16
1243+ token = 'a' * 16
1244 r = self.client.post("/%s/+login" % token,
1245 {'email': 'mark@example.com', 'password': 'test'})
1246 self.assertEqual(r.status_code, 302)
1247@@ -335,7 +332,7 @@
1248
1249 def test_confirm_account_redirect_to_decide_token_error(self):
1250 # get a valid session
1251- token1 = 'a'*16
1252+ token1 = 'a' * 16
1253 r = _post_new_account(self.client, token=token1)
1254 self.assertRedirects(r, '/%s/+email-sent' % token1)
1255
1256@@ -373,7 +370,8 @@
1257 session.save()
1258
1259 # create rpconfig
1260- rpconfig = OpenIDRPConfig.objects.create(trust_root='http://localhost/')
1261+ rpconfig = OpenIDRPConfig.objects.create(
1262+ trust_root='http://localhost/')
1263
1264 # claim token
1265 r = self.client.post(self._token_url('+newaccount'),
1266@@ -452,7 +450,6 @@
1267
1268 self.assertEqual(len(mail.outbox), 0)
1269
1270-
1271 def test_forgot_password_invalid_form(self):
1272 r = self.client.post('/+forgot_password')
1273 self.assertEqual(r.status_code, 200)
1274@@ -776,6 +773,9 @@
1275
1276
1277 class UIViewsLPModelTestCase(LPAccountTestCase):
1278+
1279+ fixtures = ["test"]
1280+
1281 def test_new_account_when_person_does_not_exist(self):
1282 # create email address with broken foreign key
1283 email = EmailAddress.objects.get(email__iexact='mark@example.com')
1284@@ -793,7 +793,9 @@
1285 email.save()
1286
1287
1288-class CaptchaVerificationTestCase(BasicAccountTestCase):
1289+class CaptchaVerificationTestCase(SSOBaseTestCase):
1290+
1291+ fixtures = ["test"]
1292
1293 def setUp(self):
1294 self.client = Client(REMOTE_ADDR='127.0.0.1')
1295@@ -814,7 +816,9 @@
1296 self.assertContains(r, msg)
1297
1298
1299-class LanguagesTestCase(BasicAccountTestCase):
1300+class LanguagesTestCase(SSOBaseTestCase):
1301+
1302+ fixtures = ["test"]
1303
1304 def test_preffered_lang_is_preserved_after_logout(self):
1305 account = Account.objects.get_by_email("mark@example.com")
1306@@ -841,7 +845,9 @@
1307 self.reset_csrf()
1308
1309
1310-class CookiesTestCase(BasicAccountTestCase):
1311+class CookiesTestCase(SSOBaseTestCase):
1312+
1313+ fixtures = ["test"]
1314
1315 def setUp(self):
1316 super(CookiesTestCase, self).setUp()
1317
1318=== modified file 'identityprovider/tests/test_views_ui_logout.py'
1319--- identityprovider/tests/test_views_ui_logout.py 2011-05-11 13:02:21 +0000
1320+++ identityprovider/tests/test_views_ui_logout.py 2011-07-19 13:59:31 +0000
1321@@ -54,7 +54,7 @@
1322 displayname="Example",
1323 creation_rationale=AccountCreationRationale.UNKNOWN)
1324
1325- def test_get_return_to_root_url_without_referer_and_url_is_recognized(self):
1326+ def test_get_return_to_root_url(self):
1327 trust_root = 'http://example.com/'
1328 self.create_openid_rp_config(trust_root)
1329 return_to = self.view.get_return_to_url(trust_root, None)
1330@@ -83,7 +83,8 @@
1331 def test_get_return_to_url_when_tricky_trust(self):
1332 trust_root = 'http://%.example.com/r'
1333 self.create_openid_rp_config(trust_root)
1334- return_to = self.view.get_return_to_url('http://launchpad.net/?sneaky=.example.com/r', None)
1335+ return_to = self.view.get_return_to_url(
1336+ 'http://launchpad.net/?sneaky=.example.com/r', None)
1337 self.assertTrue(return_to is None)
1338
1339 def test_get_return_to_url_when_tricky_return(self):
1340@@ -155,12 +156,13 @@
1341 site_name = self.view.get_site_name('http://notvalid.com/')
1342 self.assertTrue(site_name is None)
1343
1344-
1345 def sites_with_active_sessions(self):
1346 return []
1347
1348 def test_call(self):
1349- """Sanity check test, make sure that all code in __call__ is runable."""
1350+ """
1351+ Sanity check test, make sure that all code in __call__ is runable.
1352+ """
1353 self.user = self
1354 self.session = SessionStore()
1355 self.GET = {}
1356
1357=== modified file 'identityprovider/tests/test_views_utils.py'
1358--- identityprovider/tests/test_views_utils.py 2010-04-21 15:29:24 +0000
1359+++ identityprovider/tests/test_views_utils.py 2011-07-19 13:59:31 +0000
1360@@ -3,10 +3,10 @@
1361
1362 from identityprovider.models import OpenIDRPConfig
1363 from identityprovider.views import utils
1364-from identityprovider.tests.utils import SQLCachedTestCase
1365-
1366-
1367-class RedirectionURLForTokenTestCase(SQLCachedTestCase):
1368+from identityprovider.tests.utils import SSOBaseTestCase
1369+
1370+
1371+class RedirectionURLForTokenTestCase(SSOBaseTestCase):
1372
1373 def test_if_token_is_none(self):
1374 url = utils.redirection_url_for_token(None)
1375@@ -18,7 +18,7 @@
1376 self.assertEquals(url, "/ABCDEFGH/")
1377
1378
1379-class GetRPConfigTestCase(SQLCachedTestCase):
1380+class GetRPConfigTestCase(SSOBaseTestCase):
1381 trust_root1 = 'http://launchpad.dev/'
1382 trust_root2 = 'http://launchpad.dev'
1383
1384
1385=== modified file 'identityprovider/tests/test_widgets.py'
1386--- identityprovider/tests/test_widgets.py 2010-12-20 17:45:04 +0000
1387+++ identityprovider/tests/test_widgets.py 2011-07-19 13:59:31 +0000
1388@@ -7,7 +7,7 @@
1389
1390 from identityprovider.models import Account
1391 from identityprovider.models.account import LPOpenIdIdentifier
1392-from identityprovider.tests.utils import SQLCachedTestCase
1393+from identityprovider.tests.utils import SSOBaseTestCase
1394 from identityprovider.widgets import (CommaSeparatedWidget, ROAwareSelect,
1395 ROAwareTextInput, StatusWidget, ReadOnlyDateTimeWidget, LPUsernameWidget)
1396
1397@@ -139,7 +139,7 @@
1398 self.assertEqual(r, '2010-01-01 00:00:00')
1399
1400
1401-class LPUsernameWidgetTestCase(SQLCachedTestCase):
1402+class LPUsernameWidgetTestCase(SSOBaseTestCase):
1403
1404 fixtures = ['test']
1405
1406
1407=== modified file 'identityprovider/tests/test_xrds.py'
1408--- identityprovider/tests/test_xrds.py 2010-04-21 15:29:24 +0000
1409+++ identityprovider/tests/test_xrds.py 2011-07-19 13:59:31 +0000
1410@@ -1,10 +1,12 @@
1411 # Copyright 2010 Canonical Ltd. This software is licensed under the
1412 # GNU Affero General Public License version 3 (see the file LICENSE).
1413
1414-from utils import BasicAccountTestCase
1415-
1416-
1417-class XRDSTest(BasicAccountTestCase):
1418+from .utils import SSOBaseTestCase
1419+
1420+
1421+class XRDSTest(SSOBaseTestCase):
1422+
1423+ fixtures = ["test"]
1424
1425 def test_id_html(self):
1426 r = self.client.get('/+id/mark_oid')
1427
1428=== modified file 'identityprovider/tests/utils.py'
1429--- identityprovider/tests/utils.py 2011-06-29 19:47:22 +0000
1430+++ identityprovider/tests/utils.py 2011-07-19 13:59:31 +0000
1431@@ -24,26 +24,15 @@
1432 from identityprovider import decorators
1433
1434
1435-def create_pgsql_functions(functions):
1436- cursor = connection.cursor()
1437- cursor.execute(PGSQL_FUNCTIONS['__init__'])
1438- for function in functions:
1439- cursor.execute(PGSQL_FUNCTIONS[function])
1440- cursor.execute("COMMIT")
1441-
1442-
1443-class SQLCachedTestCase(TransactionTestCase):
1444- def _pre_setup(self):
1445- super(SQLCachedTestCase, self)._pre_setup()
1446- functions = getattr(self, 'pgsql_functions', [])
1447- create_pgsql_functions(functions)
1448-
1449-
1450-class BasicAccountTestCase(SQLCachedTestCase):
1451- """ This SQLCachedTestCase subclass has some initial fixtures
1452- and functions set for basic tests. """
1453- fixtures = ['test']
1454- pgsql_functions = ['generate_openid_identifier']
1455+class SSOBaseTestCase(TestCase):
1456+
1457+ def get_query(self, response):
1458+ query_start = response['Location'].find('?')
1459+ query_str = response['Location'][query_start + 1:]
1460+ query_items = map(tuple,
1461+ [item.split('=') for item in query_str.split('&')])
1462+ query = dict(query_items)
1463+ return query
1464
1465 def reset_csrf(self):
1466 settings.MIDDLEWARE_CLASSES = self._MIDDLEWARE_CLASSES
1467@@ -54,7 +43,7 @@
1468 if not 'csrf' in x.lower())
1469
1470
1471-class LPAccountTestCase(BasicAccountTestCase):
1472+class LPAccountTestCase(TransactionTestCase):
1473
1474 def setUp(self):
1475 super(LPAccountTestCase, self).setUp()
1476@@ -67,7 +56,6 @@
1477 'emailaddress_person_fkey')
1478 cursor.execute("BEGIN")
1479
1480-
1481 def tearDown(self):
1482 # enable person constraint
1483 cursor = connection.cursor()
1484@@ -76,11 +64,12 @@
1485 'emailaddress_person_fkey FOREIGN KEY (person) '
1486 'REFERENCES lp_person(id) DEFERRABLE INITIALLY '
1487 'DEFERRED')
1488-
1489 super(LPAccountTestCase, self).tearDown()
1490
1491
1492-class AuthenticatedTestCase(BasicAccountTestCase):
1493+class AuthenticatedTestCase(SSOBaseTestCase):
1494+
1495+ fixtures = ["test"]
1496
1497 def setUp(self, disableCSRF=False):
1498 # We allow classes that inherit this one to disable CSRF when needed,
1499@@ -102,20 +91,6 @@
1500 settings.MIDDLEWARE_CLASSES = self.old_middlewares
1501
1502
1503-class OpenIDProviderTestCase(SQLCachedTestCase):
1504- pgsql_functions = ['generate_openid_identifier']
1505-
1506- def get_query(self, response):
1507- query_start = response['Location'].find('?')
1508- query_str = response['Location'][query_start+1:]
1509- query_items = map(tuple,
1510- [item.split('=') for item in query_str.split('&')])
1511- query = dict(query_items)
1512- return query
1513-
1514-
1515-
1516-
1517 def make_identifier_select_endpoint(protocol_uri):
1518 """Create an endpoint for use in OpenID identifier select mode.
1519
1520@@ -197,6 +172,7 @@
1521 "A class that simulates writing to /dev/null."
1522 def write(self, s):
1523 pass
1524+
1525 def flush(self):
1526 pass
1527
1528@@ -245,52 +221,6 @@
1529 return len(result.failures) + len(result.errors)
1530
1531
1532-PGSQL_FUNCTIONS = {
1533- '__init__': '''
1534-DROP LANGUAGE IF EXISTS plpythonu CASCADE;
1535-CREATE LANGUAGE plpythonu;
1536-''',
1537- 'generate_openid_identifier': '''
1538-CREATE OR REPLACE FUNCTION generate_openid_identifier()
1539- RETURNS text AS
1540-$BODY$
1541- from random import choice
1542-
1543- # Non display confusing characters.
1544- chars = '34678bcdefhkmnprstwxyzABCDEFGHJKLMNPQRTWXY'
1545-
1546- # Character length of tokens. Can be increased, decreased or even made
1547- # random - Launchpad does not care. 7 means it takes 40 bytes to store
1548- # a null-terminated Launchpad identity URL on the current domain name.
1549- length=7
1550-
1551- loop_count = 0
1552- while loop_count < 20000:
1553- # Generate a random openid_identifier
1554- oid = ''.join(choice(chars) for count in range(length))
1555-
1556- # Check if the oid is already in the db, although this is pretty
1557- # unlikely
1558- rv = plpy.execute("""
1559- SELECT COUNT(*) AS num FROM Account WHERE openid_identifier = '%%s'
1560- """ %% oid, 1)
1561- if rv[0]['num'] == 0:
1562- return oid
1563- loop_count += 1
1564- if loop_count == 1:
1565- plpy.warning(
1566- 'Clash generating unique openid_identifier. '
1567- 'Increase length if you see this warning too much.')
1568- plpy.error(
1569- "Unable to generate unique openid_identifier. "
1570- "Need to increase length of tokens.")
1571-$BODY$
1572- LANGUAGE 'plpythonu' VOLATILE
1573- COST 100;
1574-''',
1575-}
1576-
1577-
1578 class MockHandler(urllib2.HTTPHandler):
1579
1580 def set_next_response(self, msg):
1581@@ -311,7 +241,8 @@
1582 from datetime import date
1583 from identityprovider.models.person import Person
1584 from identityprovider.models.account import (Account, LPOpenIdIdentifier)
1585- from identityprovider.models.team import (TeamMembership, TeamParticipation)
1586+ from identityprovider.models.team import (
1587+ TeamMembership, TeamParticipation)
1588
1589 memberships = TeamMembership.get_team_memberships_for_user([teamname],
1590 account, True)
1591@@ -333,14 +264,15 @@
1592 try:
1593 t = Person.objects.get(name=teamname)
1594 except Person.DoesNotExist:
1595- t = Person.objects.create(displayname="Team %s" % teamname, teamowner=p,
1596- name=teamname)
1597+ t = Person.objects.create(displayname="Team %s" % teamname,
1598+ teamowner=p, name=teamname)
1599
1600 now = date.today()
1601- exp = date(day=now.day, month=now.month, year=now.year+1)
1602+ exp = date(day=now.day, month=now.month, year=(now.year + 1))
1603 TeamMembership.objects.create(person=p, date_expires=exp, team=t, status=1)
1604 TeamParticipation.objects.create(team=t, person=p)
1605
1606+
1607 def get_unique_username():
1608 from identityprovider.models.person import Person
1609 i = 0
1610@@ -352,4 +284,3 @@
1611 except Person.DoesNotExist:
1612 break
1613 return username
1614-
1615
1616=== modified file 'payload/__init__.py'
1617--- payload/__init__.py 2011-07-12 14:27:59 +0000
1618+++ payload/__init__.py 2011-07-19 13:59:31 +0000
1619@@ -31,7 +31,8 @@
1620
1621 # translations
1622 APPS = ["identityprovider"]
1623-TRANSLATIONS_BRANCH = 'lp:~canonical-isd-hackers/canonical-identity-provider/translations'
1624+TRANSLATIONS_BRANCH = (
1625+ 'lp:~canonical-isd-hackers/canonical-identity-provider/translations')
1626
1627
1628 # fab targets
1629@@ -65,7 +66,7 @@
1630
1631
1632 # development
1633-def test(functional=False, coverage=False):
1634+def test(functional=False, coverage=False, extra=''):
1635 """Run the test suite."""
1636 hudson = env.get('hudson', False)
1637
1638@@ -79,6 +80,8 @@
1639 # add support for cobertura
1640 cmd.append('--with-xcoverage --cover-package=identityprovider')
1641 cmd.append('--with-xunit')
1642+ # So you can add things like --stop
1643+ cmd.append(extra)
1644 virtualenv(' '.join(cmd), capture=False)
1645
1646