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
=== modified file 'identityprovider/tests/test_models_api.py'
--- identityprovider/tests/test_models_api.py 2010-05-19 20:52:44 +0000
+++ identityprovider/tests/test_models_api.py 2010-09-22 14:39:48 +0000
@@ -1,7 +1,12 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
3from django.test import TestCase
34
5from identityprovider.models.emailaddress import EmailAddress
6from identityprovider.models.const import EmailStatus
4from identityprovider.models.api import APIUser7from identityprovider.models.api import APIUser
8from identityprovider.webservice.models import RegistrationSet
9from identityprovider.webservice import forms
5from identityprovider.tests.utils import SQLCachedTestCase10from identityprovider.tests.utils import SQLCachedTestCase
6from identityprovider.utils import encrypt_launchpad_password, generate_salt11from identityprovider.utils import encrypt_launchpad_password, generate_salt
712
@@ -39,3 +44,23 @@
3944
40 def test_unicode(self):45 def test_unicode(self):
41 self.assertEqual(unicode(self.user), u'username')46 self.assertEqual(unicode(self.user), u'username')
47
48
49class RegistrationSetTestCase(TestCase):
50
51 def test_register_email_error_is_in_list(self):
52 old_gcbr = forms.get_current_browser_request
53 forms.get_current_browser_request = lambda: self
54 self.environment = {}
55 EmailAddress.objects.create(email="register@example.com",
56 status=EmailStatus.NEW)
57
58 registration = RegistrationSet()
59 r = registration.register(email="register@example.com",
60 password="blogdf3Daa",
61 captcha_solution="solution",
62 captcha_id="id")
63
64 self.assertEquals(r['errors'], {'email': ["Email already registered"]})
65
66 forms.get_current_browser_request = old_gcbr
4267
=== modified file 'identityprovider/webservice/models.py'
--- identityprovider/webservice/models.py 2010-08-27 11:26:30 +0000
+++ identityprovider/webservice/models.py 2010-09-22 14:39:48 +0000
@@ -231,7 +231,7 @@
231 emails = EmailAddress.objects.filter(email__iexact=requested_email)231 emails = EmailAddress.objects.filter(email__iexact=requested_email)
232 if len(emails) > 0:232 if len(emails) > 0:
233 return {'status': 'error', 'errors':233 return {'status': 'error', 'errors':
234 {'email': 'Email already registered'}}234 {'email': ['Email already registered']}}
235235
236 account = Account.objects.create(236 account = Account.objects.create(
237 creation_rationale=AccountCreationRationale.OWNER_CREATED_LAUNCHPAD,237 creation_rationale=AccountCreationRationale.OWNER_CREATED_LAUNCHPAD,