Merge lp:~canonical-isd-hackers/canonical-identity-provider/fix-api-email-error into lp:canonical-identity-provider/release

Proposed by Łukasz Czyżykowski
Status: Merged
Approved by: Stuart Metcalfe
Approved revision: no longer in the source branch.
Merged at revision: 80
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/fix-api-email-error
Merge into: lp:canonical-identity-provider/release
Diff against target: 53 lines (+26/-1)
2 files modified
identityprovider/tests/test_models_api.py (+25/-0)
identityprovider/webservice/models.py (+1/-1)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/fix-api-email-error
Reviewer Review Type Date Requested Status
Stuart Metcalfe (community) Approve
Review via email: mp+36307@code.launchpad.net

Commit message

Fixed inconsistency for API error returned when email is already registered.

Description of the change

This branch fixes inconsistency for "email already registered" error not being returned in the list (as all other are).

With fix there's test case to check that behaviour.

Because that particular error is not showed in doctest there's no need to update them.

To post a comment you must log in.
Revision history for this message
Stuart Metcalfe (stuartmetcalfe) wrote :

Looks good to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identityprovider/tests/test_models_api.py'
2--- identityprovider/tests/test_models_api.py 2010-05-19 20:52:44 +0000
3+++ identityprovider/tests/test_models_api.py 2010-09-22 14:39:48 +0000
4@@ -1,7 +1,12 @@
5 # Copyright 2010 Canonical Ltd. This software is licensed under the
6 # GNU Affero General Public License version 3 (see the file LICENSE).
7+from django.test import TestCase
8
9+from identityprovider.models.emailaddress import EmailAddress
10+from identityprovider.models.const import EmailStatus
11 from identityprovider.models.api import APIUser
12+from identityprovider.webservice.models import RegistrationSet
13+from identityprovider.webservice import forms
14 from identityprovider.tests.utils import SQLCachedTestCase
15 from identityprovider.utils import encrypt_launchpad_password, generate_salt
16
17@@ -39,3 +44,23 @@
18
19 def test_unicode(self):
20 self.assertEqual(unicode(self.user), u'username')
21+
22+
23+class RegistrationSetTestCase(TestCase):
24+
25+ def test_register_email_error_is_in_list(self):
26+ old_gcbr = forms.get_current_browser_request
27+ forms.get_current_browser_request = lambda: self
28+ self.environment = {}
29+ EmailAddress.objects.create(email="register@example.com",
30+ status=EmailStatus.NEW)
31+
32+ registration = RegistrationSet()
33+ r = registration.register(email="register@example.com",
34+ password="blogdf3Daa",
35+ captcha_solution="solution",
36+ captcha_id="id")
37+
38+ self.assertEquals(r['errors'], {'email': ["Email already registered"]})
39+
40+ forms.get_current_browser_request = old_gcbr
41
42=== modified file 'identityprovider/webservice/models.py'
43--- identityprovider/webservice/models.py 2010-08-27 11:26:30 +0000
44+++ identityprovider/webservice/models.py 2010-09-22 14:39:48 +0000
45@@ -231,7 +231,7 @@
46 emails = EmailAddress.objects.filter(email__iexact=requested_email)
47 if len(emails) > 0:
48 return {'status': 'error', 'errors':
49- {'email': 'Email already registered'}}
50+ {'email': ['Email already registered']}}
51
52 account = Account.objects.create(
53 creation_rationale=AccountCreationRationale.OWNER_CREATED_LAUNCHPAD,