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
1=== modified file 'bin/ubuntuone-preferences'
2--- bin/ubuntuone-preferences 2010-02-17 04:01:37 +0000
3+++ bin/ubuntuone-preferences 2010-02-17 19:37:14 +0000
4@@ -84,7 +84,6 @@
5
6 self.__bus = dbus.SessionBus()
7 self.keyring = gnomekeyring
8- self.httpclient = httplib2.Http()
9
10 try:
11 client = self.__bus.get_object(DBUS_IFACE_NAME, "/config",
12@@ -205,8 +204,8 @@
13 'percent' : percent })
14 self.usage_graph.set_fraction(percent / 100)
15
16- def request_quota_info(self):
17- """Request new quota info from server, and update display."""
18+ def request_REST_info(self, url, method):
19+ """Make a REST request and return the resulting dict, or None."""
20 consumer = oauth.OAuthConsumer("ubuntuone", "hammertime")
21 items = []
22 items = self.keyring.find_items_sync(
23@@ -215,25 +214,36 @@
24 'oauth-consumer-key': consumer.key})
25 token = oauth.OAuthToken.from_string(items[0].secret)
26 request = oauth.OAuthRequest.from_consumer_and_token(
27- http_url='https://one.ubuntu.com/api/quota/',
28- http_method='GET',
29- oauth_consumer=consumer,
30+ http_url=url, http_method=method, oauth_consumer=consumer,
31 token=token)
32 request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(),
33 consumer, token)
34- client = self.httpclient
35+ client = httplib2.Http()
36 headers = {}
37 headers.update(request.to_header())
38- resp, content = client.request(request.http_url,
39- request.http_method,
40- headers=headers)
41+ resp, content = client.request(url, method, headers=headers)
42 if resp['status'] == '200':
43- quota = simplejson.loads(content)
44- self.update_quota_display(quota['used'], quota['total'])
45+ return simplejson.loads(content)
46 # FIXME: Log json parsing failures
47 else:
48 # FIXME: Log errors
49- return
50+ return None
51+
52+ def request_quota_info(self):
53+ """Request new quota info from server, and update display."""
54+ quota = self.request_REST_info('https://one.ubuntu.com/api/quota/',
55+ 'GET')
56+ if quota:
57+ self.update_quota_display(quota['used'], quota['total'])
58+
59+ def request_account_info(self):
60+ """Request account info from server, and update display."""
61+ user = self.request_REST_info('https://one.ubuntu.com/api/account/',
62+ 'GET')
63+ if user:
64+ self.name_label.set_text(user['nickname'])
65+ self.user_label.set_text(user['username'])
66+ self.mail_label.set_text(user['email'])
67
68 def __construct(self):
69 """Construct the dialog's layout."""
70@@ -280,6 +290,49 @@
71 self.notebook.set_tab_label_text(account, _("Account"))
72 account.show()
73
74+ # User info in account tab
75+ table = gtk.Table(rows=3, columns=2)
76+ table.set_row_spacings(6)
77+ table.set_col_spacings(6)
78+ account.pack_start(table, False, False)
79+ table.show()
80+
81+ label = gtk.Label(_("_Name:"))
82+ label.set_use_underline(True)
83+ label.set_alignment(0.0, 0.5)
84+ table.attach(label, 0, 1, 0, 1)
85+ label.show()
86+
87+ self.name_label = gtk.Label("")
88+ self.name_label.set_use_underline(True)
89+ self.name_label.set_alignment(0.0, 0.5)
90+ table.attach(self.name_label, 1, 2, 0, 1)
91+ self.name_label.show()
92+
93+ label = gtk.Label(_("_Username:"))
94+ label.set_use_underline(True)
95+ label.set_alignment(0.0, 0.5)
96+ table.attach(label, 0, 1, 1, 2)
97+ label.show()
98+
99+ self.user_label = gtk.Label("")
100+ self.user_label.set_use_underline(True)
101+ self.user_label.set_alignment(0.0, 0.5)
102+ table.attach(self.user_label, 1, 2, 1, 2)
103+ self.user_label.show()
104+
105+ label = gtk.Label(_("_E-mail:"))
106+ label.set_use_underline(True)
107+ label.set_alignment(0.0, 0.5)
108+ table.attach(label, 0, 1, 2, 3)
109+ label.show()
110+
111+ self.mail_label = gtk.Label("")
112+ self.mail_label.set_use_underline(True)
113+ self.mail_label.set_alignment(0.0, 0.5)
114+ table.attach(self.mail_label, 1, 2, 2, 3)
115+ self.mail_label.show()
116+
117 # Devices tab
118 devices = gtk.VBox(spacing=12)
119 devices.set_border_width(6)
120@@ -361,6 +414,7 @@
121 self.disconnect_signal_handlers()
122 dialog = UbuntuOneDialog()
123 dialog.request_quota_info()
124+ dialog.request_account_info()
125 dialog.show()
126
127 def got_oautherror(self, message=None):
128
129=== modified file 'tests/test_preferences.py'
130--- tests/test_preferences.py 2010-02-17 04:01:37 +0000
131+++ tests/test_preferences.py 2010-02-17 19:37:14 +0000
132@@ -48,6 +48,7 @@
133
134 # For testing keyring queries
135 self.keyring = self.mocker.mock()
136+ self.u1prefs.httplib2 = self.mocker.mock()
137 self.item = self.mocker.mock(gnomekeyring.Found)
138
139 self.item_id = 999
140@@ -114,13 +115,13 @@
141 """Test that we can request the quota info properly."""
142 self.mock_has_token()
143 dialog = self.u1prefs.UbuntuOneDialog()
144+ self.assertTrue(dialog is not None)
145 dialog.keyring = self.keyring
146 self.assertEqual(dialog.usage_graph.get_fraction(), 0.0)
147- self.assertTrue(dialog is not None)
148 response = { 'status' : '200' }
149 content = '{"total":2048, "used":1024}'
150 client = self.mocker.mock()
151- dialog.httpclient = client
152+ self.expect(self.u1prefs.httplib2.Http()).result(client)
153 self.expect(client.request('https://one.ubuntu.com/api/quota/',
154 'GET', KWARGS)).result((response, content))
155 self.mocker.replay()
156@@ -128,6 +129,27 @@
157 self.assertEqual(dialog.usage_graph.get_fraction(), 0.5)
158 dialog.destroy()
159
160+ def test_request_account_info(self):
161+ """Test that we can request the account info properly."""
162+ self.mock_has_token()
163+ dialog = self.u1prefs.UbuntuOneDialog()
164+ self.assertTrue(dialog is not None)
165+ dialog.keyring = self.keyring
166+ response = { 'status' : '200' }
167+ content = '''{"username": "ubuntuone", "nickname": "Ubuntu One",
168+ "email": "uone@example.com"}
169+ '''
170+ client = self.mocker.mock()
171+ self.expect(self.u1prefs.httplib2.Http()).result(client)
172+ self.expect(client.request('https://one.ubuntu.com/api/account/',
173+ 'GET', KWARGS)).result((response, content))
174+ self.mocker.replay()
175+ dialog.request_account_info()
176+ self.assertEqual(dialog.name_label.get_text(), 'Ubuntu One')
177+ self.assertEqual(dialog.user_label.get_text(), 'ubuntuone')
178+ self.assertEqual(dialog.mail_label.get_text(), 'uone@example.com')
179+ dialog.destroy()
180+
181 def test_login_check(self):
182 """Test that our login check works correctly."""
183 self.mocker.replay()

Subscribers

People subscribed via source and target branches