Merge lp:~dobey/ubuntuone-client/cp-account-info into lp:ubuntuone-client

Proposed by dobey
Status: Merged
Approved by: Rick McBride
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~dobey/ubuntuone-client/cp-account-info
Merge into: lp:ubuntuone-client
Diff against target: 183 lines (+91/-15)
2 files modified
bin/ubuntuone-preferences (+67/-13)
tests/test_preferences.py (+24/-2)
To merge this branch: bzr merge lp:~dobey/ubuntuone-client/cp-account-info
Reviewer Review Type Date Requested Status
Rick McBride (community) Approve
Martin Albisetti (community) Approve
Review via email: mp+19525@code.launchpad.net

Commit message

Add code to get account details and show them in the Account tab in CP

To post a comment you must log in.
Revision history for this message
Martin Albisetti (beuno) :
review: Approve
Revision history for this message
Rick McBride (rmcbride) wrote :

Cool!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/ubuntuone-preferences'
--- bin/ubuntuone-preferences 2010-02-17 04:01:37 +0000
+++ bin/ubuntuone-preferences 2010-02-17 19:37:14 +0000
@@ -84,7 +84,6 @@
8484
85 self.__bus = dbus.SessionBus()85 self.__bus = dbus.SessionBus()
86 self.keyring = gnomekeyring86 self.keyring = gnomekeyring
87 self.httpclient = httplib2.Http()
8887
89 try:88 try:
90 client = self.__bus.get_object(DBUS_IFACE_NAME, "/config",89 client = self.__bus.get_object(DBUS_IFACE_NAME, "/config",
@@ -205,8 +204,8 @@
205 'percent' : percent })204 'percent' : percent })
206 self.usage_graph.set_fraction(percent / 100)205 self.usage_graph.set_fraction(percent / 100)
207206
208 def request_quota_info(self):207 def request_REST_info(self, url, method):
209 """Request new quota info from server, and update display."""208 """Make a REST request and return the resulting dict, or None."""
210 consumer = oauth.OAuthConsumer("ubuntuone", "hammertime")209 consumer = oauth.OAuthConsumer("ubuntuone", "hammertime")
211 items = []210 items = []
212 items = self.keyring.find_items_sync(211 items = self.keyring.find_items_sync(
@@ -215,25 +214,36 @@
215 'oauth-consumer-key': consumer.key})214 'oauth-consumer-key': consumer.key})
216 token = oauth.OAuthToken.from_string(items[0].secret)215 token = oauth.OAuthToken.from_string(items[0].secret)
217 request = oauth.OAuthRequest.from_consumer_and_token(216 request = oauth.OAuthRequest.from_consumer_and_token(
218 http_url='https://one.ubuntu.com/api/quota/',217 http_url=url, http_method=method, oauth_consumer=consumer,
219 http_method='GET',
220 oauth_consumer=consumer,
221 token=token)218 token=token)
222 request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(),219 request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(),
223 consumer, token)220 consumer, token)
224 client = self.httpclient221 client = httplib2.Http()
225 headers = {}222 headers = {}
226 headers.update(request.to_header())223 headers.update(request.to_header())
227 resp, content = client.request(request.http_url,224 resp, content = client.request(url, method, headers=headers)
228 request.http_method,
229 headers=headers)
230 if resp['status'] == '200':225 if resp['status'] == '200':
231 quota = simplejson.loads(content)226 return simplejson.loads(content)
232 self.update_quota_display(quota['used'], quota['total'])
233 # FIXME: Log json parsing failures227 # FIXME: Log json parsing failures
234 else:228 else:
235 # FIXME: Log errors229 # FIXME: Log errors
236 return230 return None
231
232 def request_quota_info(self):
233 """Request new quota info from server, and update display."""
234 quota = self.request_REST_info('https://one.ubuntu.com/api/quota/',
235 'GET')
236 if quota:
237 self.update_quota_display(quota['used'], quota['total'])
238
239 def request_account_info(self):
240 """Request account info from server, and update display."""
241 user = self.request_REST_info('https://one.ubuntu.com/api/account/',
242 'GET')
243 if user:
244 self.name_label.set_text(user['nickname'])
245 self.user_label.set_text(user['username'])
246 self.mail_label.set_text(user['email'])
237247
238 def __construct(self):248 def __construct(self):
239 """Construct the dialog's layout."""249 """Construct the dialog's layout."""
@@ -280,6 +290,49 @@
280 self.notebook.set_tab_label_text(account, _("Account"))290 self.notebook.set_tab_label_text(account, _("Account"))
281 account.show()291 account.show()
282292
293 # User info in account tab
294 table = gtk.Table(rows=3, columns=2)
295 table.set_row_spacings(6)
296 table.set_col_spacings(6)
297 account.pack_start(table, False, False)
298 table.show()
299
300 label = gtk.Label(_("_Name:"))
301 label.set_use_underline(True)
302 label.set_alignment(0.0, 0.5)
303 table.attach(label, 0, 1, 0, 1)
304 label.show()
305
306 self.name_label = gtk.Label("")
307 self.name_label.set_use_underline(True)
308 self.name_label.set_alignment(0.0, 0.5)
309 table.attach(self.name_label, 1, 2, 0, 1)
310 self.name_label.show()
311
312 label = gtk.Label(_("_Username:"))
313 label.set_use_underline(True)
314 label.set_alignment(0.0, 0.5)
315 table.attach(label, 0, 1, 1, 2)
316 label.show()
317
318 self.user_label = gtk.Label("")
319 self.user_label.set_use_underline(True)
320 self.user_label.set_alignment(0.0, 0.5)
321 table.attach(self.user_label, 1, 2, 1, 2)
322 self.user_label.show()
323
324 label = gtk.Label(_("_E-mail:"))
325 label.set_use_underline(True)
326 label.set_alignment(0.0, 0.5)
327 table.attach(label, 0, 1, 2, 3)
328 label.show()
329
330 self.mail_label = gtk.Label("")
331 self.mail_label.set_use_underline(True)
332 self.mail_label.set_alignment(0.0, 0.5)
333 table.attach(self.mail_label, 1, 2, 2, 3)
334 self.mail_label.show()
335
283 # Devices tab336 # Devices tab
284 devices = gtk.VBox(spacing=12)337 devices = gtk.VBox(spacing=12)
285 devices.set_border_width(6)338 devices.set_border_width(6)
@@ -361,6 +414,7 @@
361 self.disconnect_signal_handlers()414 self.disconnect_signal_handlers()
362 dialog = UbuntuOneDialog()415 dialog = UbuntuOneDialog()
363 dialog.request_quota_info()416 dialog.request_quota_info()
417 dialog.request_account_info()
364 dialog.show()418 dialog.show()
365419
366 def got_oautherror(self, message=None):420 def got_oautherror(self, message=None):
367421
=== modified file 'tests/test_preferences.py'
--- tests/test_preferences.py 2010-02-17 04:01:37 +0000
+++ tests/test_preferences.py 2010-02-17 19:37:14 +0000
@@ -48,6 +48,7 @@
4848
49 # For testing keyring queries49 # For testing keyring queries
50 self.keyring = self.mocker.mock()50 self.keyring = self.mocker.mock()
51 self.u1prefs.httplib2 = self.mocker.mock()
51 self.item = self.mocker.mock(gnomekeyring.Found)52 self.item = self.mocker.mock(gnomekeyring.Found)
5253
53 self.item_id = 99954 self.item_id = 999
@@ -114,13 +115,13 @@
114 """Test that we can request the quota info properly."""115 """Test that we can request the quota info properly."""
115 self.mock_has_token()116 self.mock_has_token()
116 dialog = self.u1prefs.UbuntuOneDialog()117 dialog = self.u1prefs.UbuntuOneDialog()
118 self.assertTrue(dialog is not None)
117 dialog.keyring = self.keyring119 dialog.keyring = self.keyring
118 self.assertEqual(dialog.usage_graph.get_fraction(), 0.0)120 self.assertEqual(dialog.usage_graph.get_fraction(), 0.0)
119 self.assertTrue(dialog is not None)
120 response = { 'status' : '200' }121 response = { 'status' : '200' }
121 content = '{"total":2048, "used":1024}'122 content = '{"total":2048, "used":1024}'
122 client = self.mocker.mock()123 client = self.mocker.mock()
123 dialog.httpclient = client124 self.expect(self.u1prefs.httplib2.Http()).result(client)
124 self.expect(client.request('https://one.ubuntu.com/api/quota/',125 self.expect(client.request('https://one.ubuntu.com/api/quota/',
125 'GET', KWARGS)).result((response, content))126 'GET', KWARGS)).result((response, content))
126 self.mocker.replay()127 self.mocker.replay()
@@ -128,6 +129,27 @@
128 self.assertEqual(dialog.usage_graph.get_fraction(), 0.5)129 self.assertEqual(dialog.usage_graph.get_fraction(), 0.5)
129 dialog.destroy()130 dialog.destroy()
130131
132 def test_request_account_info(self):
133 """Test that we can request the account info properly."""
134 self.mock_has_token()
135 dialog = self.u1prefs.UbuntuOneDialog()
136 self.assertTrue(dialog is not None)
137 dialog.keyring = self.keyring
138 response = { 'status' : '200' }
139 content = '''{"username": "ubuntuone", "nickname": "Ubuntu One",
140 "email": "uone@example.com"}
141 '''
142 client = self.mocker.mock()
143 self.expect(self.u1prefs.httplib2.Http()).result(client)
144 self.expect(client.request('https://one.ubuntu.com/api/account/',
145 'GET', KWARGS)).result((response, content))
146 self.mocker.replay()
147 dialog.request_account_info()
148 self.assertEqual(dialog.name_label.get_text(), 'Ubuntu One')
149 self.assertEqual(dialog.user_label.get_text(), 'ubuntuone')
150 self.assertEqual(dialog.mail_label.get_text(), 'uone@example.com')
151 dialog.destroy()
152
131 def test_login_check(self):153 def test_login_check(self):
132 """Test that our login check works correctly."""154 """Test that our login check works correctly."""
133 self.mocker.replay()155 self.mocker.replay()

Subscribers

People subscribed via source and target branches