Merge lp:~canonical-isd-hackers/canonical-identity-provider/794957-api-register-platform into lp:canonical-identity-provider/release

Proposed by Ricardo Kirkner
Status: Merged
Approved by: David Owen
Approved revision: no longer in the source branch.
Merged at revision: 163
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/794957-api-register-platform
Merge into: lp:canonical-identity-provider/release
Diff against target: 146 lines (+65/-7)
5 files modified
identityprovider/api10/handlers.py (+15/-1)
identityprovider/templates/wadl1.0.xml (+7/-0)
identityprovider/tests/test_handlers.py (+43/-1)
payload/__init__.py (+0/-2)
payload/postgresql.py (+0/-3)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/794957-api-register-platform
Reviewer Review Type Date Requested Status
David Owen (community) Approve
Review via email: mp+64838@code.launchpad.net

Commit message

added platform parameter to the register api call to support different api user types

Description of the change

added platform parameter to the register api call to support different api user types

To post a comment you must log in.
Revision history for this message
David Owen (dsowen) wrote :

Great way to maintain backwards compatibility!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identityprovider/api10/handlers.py'
2--- identityprovider/api10/handlers.py 2011-06-07 15:03:14 +0000
3+++ identityprovider/api10/handlers.py 2011-06-16 14:06:48 +0000
4@@ -54,6 +54,13 @@
5 from oauth_backend.models import Token
6
7
8+EMAIL_VALIDATION_TEMPLATES = {
9+ 'web': 'newuser.txt',
10+ 'mobile': 'newuser.txt',
11+ 'desktop': 'api-newuser.txt',
12+}
13+
14+
15 class CanNotResetPasswordError(Exception):
16 pass
17
18@@ -203,7 +210,14 @@
19 token = AuthTokenFactory().new_api_email_validation_token(
20 account, cleaned_data['email'])
21
22- token.sendNewUserEmail('api-newuser.txt')
23+ platform = data.get('platform', 'desktop')
24+ template = EMAIL_VALIDATION_TEMPLATES.get(platform)
25+ if template is None:
26+ msg = ('Invalid platform requested during registration: {0}. '
27+ 'Using default platform.'.format(platform))
28+ logging.warn(msg)
29+ template = EMAIL_VALIDATION_TEMPLATES.get('desktop')
30+ token.sendNewUserEmail(template=template)
31
32 account_created.send(sender=self,
33 openid_identifier=account.openid_identifier)
34
35=== modified file 'identityprovider/templates/wadl1.0.xml'
36--- identityprovider/templates/wadl1.0.xml 2011-05-10 12:37:21 +0000
37+++ identityprovider/templates/wadl1.0.xml 2011-06-16 14:06:48 +0000
38@@ -597,6 +597,13 @@
39 </wadl:doc>
40
41 </wadl:param>
42+ <wadl:param style="query" required="false"
43+ name="consumer_type">
44+ <wadl:doc xmlns="http://www.w3.org/1999/xhtml">
45+Consumer type.
46+</wadl:doc>
47+
48+ </wadl:param>
49 </wadl:representation>
50 </wadl:request>
51
52
53=== modified file 'identityprovider/tests/test_handlers.py'
54--- identityprovider/tests/test_handlers.py 2011-05-11 13:01:00 +0000
55+++ identityprovider/tests/test_handlers.py 2011-06-16 14:06:48 +0000
56@@ -19,6 +19,7 @@
57 RegistrationHandler,
58 )
59
60+
61 class MockRequest(object):
62 def __init__(self, data=None, user=None):
63 self.user = user
64@@ -48,7 +49,7 @@
65
66 def test_reset_token_when_email_is_invalid(self):
67 request = MockRequest(data={'email': "non-existing@example.com"})
68-
69+
70 self.assertRaises(CanNotResetPasswordError,
71 self.registration.request_password_reset_token,
72 request)
73@@ -112,6 +113,47 @@
74 account = Account.objects.get_by_email('test@example.com')
75 self.assertEqual(account.displayname, 'Test User')
76
77+ @patch('identityprovider.models.authtoken.AuthToken.sendNewUserEmail')
78+ def test_register_without_platform(self, mock_sendNewUserEmail):
79+ request = MockRequest(data={
80+ 'email': 'test@example.com',
81+ 'password': 'MySecretPassword1',
82+ 'captcha_solution': 'foobar',
83+ 'captcha_id': 'id',
84+ })
85+ response = self.registration.register(request)
86+ self.assertEqual(response['status'], 'ok')
87+
88+ mock_sendNewUserEmail.assert_called_with(template='api-newuser.txt')
89+
90+ @patch('identityprovider.models.authtoken.AuthToken.sendNewUserEmail')
91+ def test_register_with_platform(self, mock_sendNewUserEmail):
92+ request = MockRequest(data={
93+ 'email': 'test@example.com',
94+ 'password': 'MySecretPassword1',
95+ 'captcha_solution': 'foobar',
96+ 'captcha_id': 'id',
97+ 'platform': 'mobile',
98+ })
99+ response = self.registration.register(request)
100+ self.assertEqual(response['status'], 'ok')
101+
102+ mock_sendNewUserEmail.assert_called_with(template='newuser.txt')
103+
104+ @patch('identityprovider.models.authtoken.AuthToken.sendNewUserEmail')
105+ def test_register_with_invalid_platform(self, mock_sendNewUserEmail):
106+ request = MockRequest(data={
107+ 'email': 'test@example.com',
108+ 'password': 'MySecretPassword1',
109+ 'captcha_solution': 'foobar',
110+ 'captcha_id': 'id',
111+ 'platform': 'foo',
112+ })
113+ response = self.registration.register(request)
114+ self.assertEqual(response['status'], 'ok')
115+
116+ mock_sendNewUserEmail.assert_called_with(template='api-newuser.txt')
117+
118
119 class AuthenticationTestCase(SQLCachedTestCase):
120
121
122=== modified file 'payload/__init__.py'
123--- payload/__init__.py 2011-06-10 14:23:27 +0000
124+++ payload/__init__.py 2011-06-16 14:06:48 +0000
125@@ -49,8 +49,6 @@
126 setup_virtualenv()
127 install_dependencies()
128 _setup_configuration()
129- # make sure the virtualenv is refreshed
130- setup_virtualenv()
131
132
133 def clean():
134
135=== modified file 'payload/postgresql.py'
136--- payload/postgresql.py 2011-06-10 15:55:13 +0000
137+++ payload/postgresql.py 2011-06-16 14:06:48 +0000
138@@ -162,9 +162,6 @@
139 port = env.database['PORT']
140 if port:
141 pg_env.append("PGPORT=%s" % port)
142- user = os.environ.get('PGUSER', env.database['USER'])
143- if user:
144- pg_env.append("PGUSER=%s" % user)
145
146 env.postgres['ENV'] = ' '.join(pg_env)
147