Fom

Merge lp:~terrycojones/fom/add-oauth-calls-899576 into lp:fom

Proposed by Terry Jones
Status: Merged
Merge reported by: Nicholas Tollervey
Merged at revision: not available
Proposed branch: lp:~terrycojones/fom/add-oauth-calls-899576
Merge into: lp:fom
Diff against target: 82 lines (+44/-5)
3 files modified
fom/db.py (+11/-1)
fom/session.py (+14/-4)
tests/test_db.py (+19/-0)
To merge this branch: bzr merge lp:~terrycojones/fom/add-oauth-calls-899576
Reviewer Review Type Date Requested Status
Nicholas Tollervey Approve
Review via email: mp+84364@code.launchpad.net

Description of the change

Makes it possible to make OAuth2 calls to Fluidinfo.

To post a comment you must log in.
Revision history for this message
Nicholas Tollervey (ntoll) wrote :

All the tests pass. I've also tried running some requests via the main instance using the new oAuth functionality and it works. +1 LGTM.

Now I just need to remember how to merge the bloody thing.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'fom/db.py'
--- fom/db.py 2011-08-30 11:40:04 +0000
+++ fom/db.py 2011-12-03 13:18:24 +0000
@@ -246,7 +246,17 @@
246 auth = 'Basic ' + userpass.encode('base64').strip()246 auth = 'Basic ' + userpass.encode('base64').strip()
247 self.headers['Authorization'] = auth247 self.headers['Authorization'] = auth
248248
249 def login_oauth2(self, token):
250 """Prepare to make OAuth2 calls to Fluidinfo.
251
252 :param token: The OAuth token to pass in calls to Fluidinfo.
253 """
254 self.headers['Authorization'] = 'oauth2'
255 self.headers['X-FluidDB-Access-Token'] = token
256
249 def logout(self):257 def logout(self):
250 """Log out of this FluidDB instance258 """Log out of this FluidDB instance
251 """259 """
252 del self.headers['Authorization']260 # Use pop here, to avoid catching KeyError if login was never called.
261 self.headers.pop('Authorization', None)
262 self.headers.pop('X-FluidDB-Access-Token', None)
253263
=== modified file 'fom/session.py'
--- fom/session.py 2010-02-06 22:29:08 +0000
+++ fom/session.py 2011-12-03 13:18:24 +0000
@@ -54,11 +54,21 @@
54 """54 """
55 return self.db.login(username, password)55 return self.db.login(username, password)
5656
57 def login_oauth2(self, token):
58 """Log in to the connected FluidDB using OAuth2
59
60 The login is maintained for the session until :meth:`~Fluid.logout`
61 is called.
62
63 >>> fdb = Fluid()
64 >>> fdb.login_oauth2(u'token')
65 >>> fdb.users.get(u'aliafshar') # this is now authenticated
66
67 :param token: The OAuth token to pass in calls to Fluidinfo.
68 """
69 return self.db.login_oauth2(token)
70
57 def logout(self):71 def logout(self):
58 """Log out of the FluidDB session72 """Log out of the FluidDB session
59 """73 """
60 return self.db.logout()74 return self.db.logout()
61
62
63
64
6575
=== modified file 'tests/test_db.py'
--- tests/test_db.py 2010-12-24 15:30:04 +0000
+++ tests/test_db.py 2011-12-03 13:18:24 +0000
@@ -184,6 +184,25 @@
184 db.logout()184 db.logout()
185 self.assertFalse('Authorization' in db.headers)185 self.assertFalse('Authorization' in db.headers)
186186
187 def testLoginLogoutOAuth2(self):
188 """
189 Make sure login and logout functions set things up correctly
190 when we use OAuth2.
191 """
192 token = 'kajfjowijmssafuwoisflsjlfsoieuossfh'
193 db = FluidDB(TEST_INSTANCE)
194 # start from a blank slate
195 self.assertFalse('Authorization' in db.headers)
196 self.assertFalse('X-FluidDB-Access-Token' in db.headers)
197 # Login
198 db.login_oauth2(token)
199 self.assertEquals(db.headers['Authorization'], 'oauth2')
200 self.assertEquals(db.headers['X-FluidDB-Access-Token'], token)
201 # Logout
202 db.logout()
203 self.assertFalse('Authorization' in db.headers)
204 self.assertFalse('X-FluidDB-Access-Token' in db.headers)
205
187206
188if __name__ == '__main__':207if __name__ == '__main__':
189 unittest.main()208 unittest.main()

Subscribers

People subscribed via source and target branches

to all changes: