Merge lp:~nataliabidart/ubuntuone-control-panel/device-list-type-error into lp:ubuntuone-control-panel
- device-list-type-error
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 124 |
Merged at revision: | 121 |
Proposed branch: | lp:~nataliabidart/ubuntuone-control-panel/device-list-type-error |
Merge into: | lp:ubuntuone-control-panel |
Diff against target: |
349 lines (+106/-19) 6 files modified
ubuntuone/controlpanel/backend.py (+31/-5) ubuntuone/controlpanel/dbus_client.py (+0/-1) ubuntuone/controlpanel/dbus_service.py (+11/-8) ubuntuone/controlpanel/tests/__init__.py (+10/-0) ubuntuone/controlpanel/tests/test_backend.py (+50/-2) ubuntuone/controlpanel/webclient.py (+4/-3) |
To merge this branch: | bzr merge lp:~nataliabidart/ubuntuone-control-panel/device-list-type-error |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Albisetti (community) | Approve | ||
Eric Casteleijn (community) | Approve | ||
Review via email: mp+55808@code.launchpad.net |
Commit message
- Made the backend robust against possible None values (or any non basestring instance) sent from the API server (LP: #745790).
Description of the change
There is no good way of IRL test this since we would need to force a response from our API servers to send a null device name, for example.
If you insist, you should temporarly change the line 275 in backend.py and set something like:
local_device[
and then run both the backend and UI from this branch.
To post a comment you must log in.
- 124. By Natalia Bidart
-
Typo.
Revision history for this message
Martin Albisetti (beuno) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ubuntuone/controlpanel/backend.py' | |||
2 | --- ubuntuone/controlpanel/backend.py 2011-03-29 17:10:59 +0000 | |||
3 | +++ ubuntuone/controlpanel/backend.py 2011-03-31 21:12:36 +0000 | |||
4 | @@ -61,6 +61,16 @@ | |||
5 | 61 | return 'True' if value else '' | 61 | return 'True' if value else '' |
6 | 62 | 62 | ||
7 | 63 | 63 | ||
8 | 64 | def filter_field(info, field): | ||
9 | 65 | """Return a copy of 'info' where each item has 'field' hidden.""" | ||
10 | 66 | result = [] | ||
11 | 67 | for item in info: | ||
12 | 68 | item = item.copy() | ||
13 | 69 | item[field] = '<hidden>' | ||
14 | 70 | result.append(item) | ||
15 | 71 | return result | ||
16 | 72 | |||
17 | 73 | |||
18 | 64 | class ControlBackend(object): | 74 | class ControlBackend(object): |
19 | 65 | """The control panel backend.""" | 75 | """The control panel backend.""" |
20 | 66 | 76 | ||
21 | @@ -178,6 +188,13 @@ | |||
22 | 178 | # di["available_services"] = "" | 188 | # di["available_services"] = "" |
23 | 179 | # di["enabled_services"] = "" | 189 | # di["enabled_services"] = "" |
24 | 180 | 190 | ||
25 | 191 | # make a sanity check | ||
26 | 192 | for key, val in di.iteritems(): | ||
27 | 193 | if not isinstance(val, basestring): | ||
28 | 194 | logger.warning('_process_device_web_info: (key %r), ' | ||
29 | 195 | 'val %r is not a basestring.', key, val) | ||
30 | 196 | di[key] = repr(val) | ||
31 | 197 | |||
32 | 181 | if is_local: # prepend the local device! | 198 | if is_local: # prepend the local device! |
33 | 182 | result.insert(0, di) | 199 | result.insert(0, di) |
34 | 183 | else: | 200 | else: |
35 | @@ -197,7 +214,6 @@ | |||
36 | 197 | dtype, did = self.type_n_id(device_id) | 214 | dtype, did = self.type_n_id(device_id) |
37 | 198 | local_token = yield self.get_token() | 215 | local_token = yield self.get_token() |
38 | 199 | is_local = (dtype == DEVICE_TYPE_COMPUTER and did == local_token) | 216 | is_local = (dtype == DEVICE_TYPE_COMPUTER and did == local_token) |
39 | 200 | logger.info('device_is_local: result %r, ', is_local) | ||
40 | 201 | returnValue(is_local) | 217 | returnValue(is_local) |
41 | 202 | 218 | ||
42 | 203 | @log_call(logger.debug) | 219 | @log_call(logger.debug) |
43 | @@ -238,6 +254,10 @@ | |||
44 | 238 | show_notifs = yield dbus_client.show_all_notifications_enabled() | 254 | show_notifs = yield dbus_client.show_all_notifications_enabled() |
45 | 239 | limits = yield dbus_client.get_throttling_limits() | 255 | limits = yield dbus_client.get_throttling_limits() |
46 | 240 | 256 | ||
47 | 257 | logger.debug('devices_info: file sync enabled? %s limit_bw %s, limits ' | ||
48 | 258 | '%s, show_notifs %s', | ||
49 | 259 | enabled, limit_bw, limits, show_notifs) | ||
50 | 260 | |||
51 | 241 | try: | 261 | try: |
52 | 242 | devices = yield self.wc.call_api(DEVICES_API) | 262 | devices = yield self.wc.call_api(DEVICES_API) |
53 | 243 | except WebClientError: | 263 | except WebClientError: |
54 | @@ -247,6 +267,8 @@ | |||
55 | 247 | limit_bw, limits, | 267 | limit_bw, limits, |
56 | 248 | show_notifs) | 268 | show_notifs) |
57 | 249 | if result is None: | 269 | if result is None: |
58 | 270 | logger.info('devices_info: result is None after calling ' | ||
59 | 271 | 'devices/ API, building the local device.') | ||
60 | 250 | credentials = yield dbus_client.get_credentials() | 272 | credentials = yield dbus_client.get_credentials() |
61 | 251 | local_device = {} | 273 | local_device = {} |
62 | 252 | local_device["type"] = DEVICE_TYPE_COMPUTER | 274 | local_device["type"] = DEVICE_TYPE_COMPUTER |
63 | @@ -264,6 +286,10 @@ | |||
64 | 264 | local_device[UPLOAD_KEY] = str(upload) | 286 | local_device[UPLOAD_KEY] = str(upload) |
65 | 265 | local_device[DOWNLOAD_KEY] = str(download) | 287 | local_device[DOWNLOAD_KEY] = str(download) |
66 | 266 | result = [local_device] | 288 | result = [local_device] |
67 | 289 | else: | ||
68 | 290 | logger.info('devices_info: result is not None after calling ' | ||
69 | 291 | 'devices/ API: %r', | ||
70 | 292 | filter_field(result, field='device_id')) | ||
71 | 267 | 293 | ||
72 | 268 | returnValue(result) | 294 | returnValue(result) |
73 | 269 | 295 | ||
74 | @@ -275,7 +301,7 @@ | |||
75 | 275 | return DEVICE_TYPE_PHONE, device_id[5:] | 301 | return DEVICE_TYPE_PHONE, device_id[5:] |
76 | 276 | return "No device", device_id | 302 | return "No device", device_id |
77 | 277 | 303 | ||
79 | 278 | @log_call(logger.info) | 304 | @log_call(logger.info, with_args=False) |
80 | 279 | @inlineCallbacks | 305 | @inlineCallbacks |
81 | 280 | def change_device_settings(self, device_id, settings): | 306 | def change_device_settings(self, device_id, settings): |
82 | 281 | """Change the settings for the given device.""" | 307 | """Change the settings for the given device.""" |
83 | @@ -311,7 +337,7 @@ | |||
84 | 311 | # still pending: more work on the settings dict (LP: #673674) | 337 | # still pending: more work on the settings dict (LP: #673674) |
85 | 312 | returnValue(device_id) | 338 | returnValue(device_id) |
86 | 313 | 339 | ||
88 | 314 | @log_call(logger.warning) | 340 | @log_call(logger.warning, with_args=False) |
89 | 315 | @inlineCallbacks | 341 | @inlineCallbacks |
90 | 316 | def remove_device(self, device_id): | 342 | def remove_device(self, device_id): |
91 | 317 | """Remove a device's tokens from the sso server.""" | 343 | """Remove a device's tokens from the sso server.""" |
92 | @@ -322,8 +348,8 @@ | |||
93 | 322 | yield self.wc.call_api(api) | 348 | yield self.wc.call_api(api) |
94 | 323 | 349 | ||
95 | 324 | if is_local: | 350 | if is_local: |
98 | 325 | logger.warning('remove_device: device is local, id %r, ' | 351 | logger.warning('remove_device: device is local! removing and ' |
99 | 326 | 'clearing credentials.', device_id) | 352 | 'clearing credentials.') |
100 | 327 | yield dbus_client.clear_credentials() | 353 | yield dbus_client.clear_credentials() |
101 | 328 | 354 | ||
102 | 329 | returnValue(device_id) | 355 | returnValue(device_id) |
103 | 330 | 356 | ||
104 | === modified file 'ubuntuone/controlpanel/dbus_client.py' | |||
105 | --- ubuntuone/controlpanel/dbus_client.py 2011-02-16 15:56:43 +0000 | |||
106 | +++ ubuntuone/controlpanel/dbus_client.py 2011-03-31 21:12:36 +0000 | |||
107 | @@ -64,7 +64,6 @@ | |||
108 | 64 | 64 | ||
109 | 65 | def found_credentials(app_name, creds): | 65 | def found_credentials(app_name, creds): |
110 | 66 | """Credentials have been found.""" | 66 | """Credentials have been found.""" |
111 | 67 | logger.debug('credentials were found for app_name %r.', app_name) | ||
112 | 68 | if app_name == APP_NAME: | 67 | if app_name == APP_NAME: |
113 | 69 | logger.info('credentials were found! (%r).', APP_NAME) | 68 | logger.info('credentials were found! (%r).', APP_NAME) |
114 | 70 | d.callback(creds) | 69 | d.callback(creds) |
115 | 71 | 70 | ||
116 | === modified file 'ubuntuone/controlpanel/dbus_service.py' | |||
117 | --- ubuntuone/controlpanel/dbus_service.py 2011-03-28 17:25:21 +0000 | |||
118 | +++ ubuntuone/controlpanel/dbus_service.py 2011-03-31 21:12:36 +0000 | |||
119 | @@ -32,7 +32,8 @@ | |||
120 | 32 | from ubuntuone.controlpanel import (DBUS_BUS_NAME, DBUS_PREFERENCES_PATH, | 32 | from ubuntuone.controlpanel import (DBUS_BUS_NAME, DBUS_PREFERENCES_PATH, |
121 | 33 | DBUS_PREFERENCES_IFACE) | 33 | DBUS_PREFERENCES_IFACE) |
122 | 34 | from ubuntuone.controlpanel.backend import ( | 34 | from ubuntuone.controlpanel.backend import ( |
124 | 35 | ControlBackend, FILE_SYNC_DISABLED, FILE_SYNC_DISCONNECTED, | 35 | ControlBackend, filter_field, |
125 | 36 | FILE_SYNC_DISABLED, FILE_SYNC_DISCONNECTED, | ||
126 | 36 | FILE_SYNC_ERROR, FILE_SYNC_IDLE, FILE_SYNC_STARTING, FILE_SYNC_STOPPED, | 37 | FILE_SYNC_ERROR, FILE_SYNC_IDLE, FILE_SYNC_STARTING, FILE_SYNC_STOPPED, |
127 | 37 | FILE_SYNC_SYNCING, | 38 | FILE_SYNC_SYNCING, |
128 | 38 | MSG_KEY, STATUS_KEY, | 39 | MSG_KEY, STATUS_KEY, |
129 | @@ -85,6 +86,7 @@ | |||
130 | 85 | """ | 86 | """ |
131 | 86 | def inner(error, _=None): | 87 | def inner(error, _=None): |
132 | 87 | """Do the Failure transformation.""" | 88 | """Do the Failure transformation.""" |
133 | 89 | logger.error('processing failure: %r', error.printTraceback()) | ||
134 | 88 | error_dict = error_handler(error) | 90 | error_dict = error_handler(error) |
135 | 89 | if _ is not None: | 91 | if _ is not None: |
136 | 90 | result = f(_, error_dict) | 92 | result = f(_, error_dict) |
137 | @@ -149,10 +151,11 @@ | |||
138 | 149 | d.addCallback(self.DevicesInfoReady) | 151 | d.addCallback(self.DevicesInfoReady) |
139 | 150 | d.addErrback(transform_failure(self.DevicesInfoError)) | 152 | d.addErrback(transform_failure(self.DevicesInfoError)) |
140 | 151 | 153 | ||
141 | 152 | @log_call(logger.debug) | ||
142 | 153 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="aa{ss}") | 154 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="aa{ss}") |
143 | 154 | def DevicesInfoReady(self, info): | 155 | def DevicesInfoReady(self, info): |
144 | 155 | """The info for the devices is available right now.""" | 156 | """The info for the devices is available right now.""" |
145 | 157 | logger.debug('DevicesInfoReady: args %r', | ||
146 | 158 | filter_field(info, field='device_id')) | ||
147 | 156 | 159 | ||
148 | 157 | @log_call(logger.error) | 160 | @log_call(logger.error) |
149 | 158 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="a{ss}") | 161 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="a{ss}") |
150 | @@ -161,7 +164,7 @@ | |||
151 | 161 | 164 | ||
152 | 162 | #--- | 165 | #--- |
153 | 163 | 166 | ||
155 | 164 | @log_call(logger.info) | 167 | @log_call(logger.info, with_args=False) |
156 | 165 | @method(dbus_interface=DBUS_PREFERENCES_IFACE, in_signature="sa{ss}") | 168 | @method(dbus_interface=DBUS_PREFERENCES_IFACE, in_signature="sa{ss}") |
157 | 166 | def change_device_settings(self, device_id, settings): | 169 | def change_device_settings(self, device_id, settings): |
158 | 167 | """Configure a given device.""" | 170 | """Configure a given device.""" |
159 | @@ -170,19 +173,19 @@ | |||
160 | 170 | d.addErrback(transform_failure(self.DeviceSettingsChangeError), | 173 | d.addErrback(transform_failure(self.DeviceSettingsChangeError), |
161 | 171 | device_id) | 174 | device_id) |
162 | 172 | 175 | ||
164 | 173 | @log_call(logger.info) | 176 | @log_call(logger.info, with_args=False) |
165 | 174 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="s") | 177 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="s") |
166 | 175 | def DeviceSettingsChanged(self, device_id): | 178 | def DeviceSettingsChanged(self, device_id): |
167 | 176 | """The settings for the device were changed.""" | 179 | """The settings for the device were changed.""" |
168 | 177 | 180 | ||
170 | 178 | @log_call(logger.error) | 181 | @log_call(logger.error, with_args=False) |
171 | 179 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="sa{ss}") | 182 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="sa{ss}") |
172 | 180 | def DeviceSettingsChangeError(self, device_id, error): | 183 | def DeviceSettingsChangeError(self, device_id, error): |
173 | 181 | """Problem changing settings for the device.""" | 184 | """Problem changing settings for the device.""" |
174 | 182 | 185 | ||
175 | 183 | #--- | 186 | #--- |
176 | 184 | 187 | ||
178 | 185 | @log_call(logger.warning) | 188 | @log_call(logger.warning, with_args=False) |
179 | 186 | @method(dbus_interface=DBUS_PREFERENCES_IFACE, in_signature="s") | 189 | @method(dbus_interface=DBUS_PREFERENCES_IFACE, in_signature="s") |
180 | 187 | def remove_device(self, device_id): | 190 | def remove_device(self, device_id): |
181 | 188 | """Remove a given device.""" | 191 | """Remove a given device.""" |
182 | @@ -190,12 +193,12 @@ | |||
183 | 190 | d.addCallback(self.DeviceRemoved) | 193 | d.addCallback(self.DeviceRemoved) |
184 | 191 | d.addErrback(transform_failure(self.DeviceRemovalError), device_id) | 194 | d.addErrback(transform_failure(self.DeviceRemovalError), device_id) |
185 | 192 | 195 | ||
187 | 193 | @log_call(logger.warning) | 196 | @log_call(logger.warning, with_args=False) |
188 | 194 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="s") | 197 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="s") |
189 | 195 | def DeviceRemoved(self, device_id): | 198 | def DeviceRemoved(self, device_id): |
190 | 196 | """The removal for the device was completed.""" | 199 | """The removal for the device was completed.""" |
191 | 197 | 200 | ||
193 | 198 | @log_call(logger.error) | 201 | @log_call(logger.error, with_args=False) |
194 | 199 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="sa{ss}") | 202 | @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="sa{ss}") |
195 | 200 | def DeviceRemovalError(self, device_id, error): | 203 | def DeviceRemovalError(self, device_id, error): |
196 | 201 | """Problem removing the device.""" | 204 | """Problem removing the device.""" |
197 | 202 | 205 | ||
198 | === modified file 'ubuntuone/controlpanel/tests/__init__.py' | |||
199 | --- ubuntuone/controlpanel/tests/__init__.py 2011-03-29 11:38:39 +0000 | |||
200 | +++ ubuntuone/controlpanel/tests/__init__.py 2011-03-31 21:12:36 +0000 | |||
201 | @@ -110,6 +110,16 @@ | |||
202 | 110 | ] | 110 | ] |
203 | 111 | """ | 111 | """ |
204 | 112 | 112 | ||
205 | 113 | EMPTY_DESCRIPTION_JSON = """ | ||
206 | 114 | [ | ||
207 | 115 | { | ||
208 | 116 | "token": "ABCDEF01234token", | ||
209 | 117 | "description": null, | ||
210 | 118 | "kind": "Computer" | ||
211 | 119 | } | ||
212 | 120 | ] | ||
213 | 121 | """ | ||
214 | 122 | |||
215 | 113 | LOCAL_DEVICE = { | 123 | LOCAL_DEVICE = { |
216 | 114 | 'is_local': 'True', | 124 | 'is_local': 'True', |
217 | 115 | 'configurable': 'True', | 125 | 'configurable': 'True', |
218 | 116 | 126 | ||
219 | === modified file 'ubuntuone/controlpanel/tests/test_backend.py' | |||
220 | --- ubuntuone/controlpanel/tests/test_backend.py 2011-03-29 14:48:28 +0000 | |||
221 | +++ ubuntuone/controlpanel/tests/test_backend.py 2011-03-31 21:12:36 +0000 | |||
222 | @@ -30,6 +30,7 @@ | |||
223 | 30 | from ubuntuone.controlpanel import backend, replication_client | 30 | from ubuntuone.controlpanel import backend, replication_client |
224 | 31 | from ubuntuone.controlpanel.backend import (bool_str, | 31 | from ubuntuone.controlpanel.backend import (bool_str, |
225 | 32 | ACCOUNT_API, DEVICES_API, DEVICE_REMOVE_API, QUOTA_API, | 32 | ACCOUNT_API, DEVICES_API, DEVICE_REMOVE_API, QUOTA_API, |
226 | 33 | DEVICE_TYPE_COMPUTER, | ||
227 | 33 | FILE_SYNC_DISABLED, | 34 | FILE_SYNC_DISABLED, |
228 | 34 | FILE_SYNC_DISCONNECTED, | 35 | FILE_SYNC_DISCONNECTED, |
229 | 35 | FILE_SYNC_ERROR, | 36 | FILE_SYNC_ERROR, |
230 | @@ -41,6 +42,7 @@ | |||
231 | 41 | MSG_KEY, STATUS_KEY, | 42 | MSG_KEY, STATUS_KEY, |
232 | 42 | ) | 43 | ) |
233 | 43 | from ubuntuone.controlpanel.tests import (TestCase, | 44 | from ubuntuone.controlpanel.tests import (TestCase, |
234 | 45 | EMPTY_DESCRIPTION_JSON, | ||
235 | 44 | EXPECTED_ACCOUNT_INFO, | 46 | EXPECTED_ACCOUNT_INFO, |
236 | 45 | EXPECTED_ACCOUNT_INFO_WITH_CURRENT_PLAN, | 47 | EXPECTED_ACCOUNT_INFO_WITH_CURRENT_PLAN, |
237 | 46 | EXPECTED_DEVICES_INFO, | 48 | EXPECTED_DEVICES_INFO, |
238 | @@ -251,7 +253,7 @@ | |||
239 | 251 | self.patch(backend, "WebClient", MockWebClient) | 253 | self.patch(backend, "WebClient", MockWebClient) |
240 | 252 | self.patch(backend, "dbus_client", MockDBusClient()) | 254 | self.patch(backend, "dbus_client", MockDBusClient()) |
241 | 253 | self.patch(backend, "replication_client", MockReplicationClient()) | 255 | self.patch(backend, "replication_client", MockReplicationClient()) |
243 | 254 | self.local_token = "Computer" + TOKEN["token"] | 256 | self.local_token = DEVICE_TYPE_COMPUTER + TOKEN["token"] |
244 | 255 | self.be = backend.ControlBackend() | 257 | self.be = backend.ControlBackend() |
245 | 256 | 258 | ||
246 | 257 | self.memento = MementoHandler() | 259 | self.memento = MementoHandler() |
247 | @@ -380,9 +382,35 @@ | |||
248 | 380 | self.assertEqual(result, expected) | 382 | self.assertEqual(result, expected) |
249 | 381 | 383 | ||
250 | 382 | @inlineCallbacks | 384 | @inlineCallbacks |
251 | 385 | def test_devices_info_when_token_name_is_empty(self): | ||
252 | 386 | """The devices_info can handle empty token names.""" | ||
253 | 387 | # pylint: disable=E1101 | ||
254 | 388 | self.be.wc.results[DEVICES_API] = EMPTY_DESCRIPTION_JSON | ||
255 | 389 | result = yield self.be.devices_info() | ||
256 | 390 | expected = {'configurable': '', | ||
257 | 391 | 'device_id': 'ComputerABCDEF01234token', | ||
258 | 392 | 'is_local': '', 'name': 'None', | ||
259 | 393 | 'type': DEVICE_TYPE_COMPUTER} | ||
260 | 394 | self.assertEqual(result, [expected]) | ||
261 | 395 | self.assertTrue(self.memento.check_warning('name', 'None')) | ||
262 | 396 | |||
263 | 397 | @inlineCallbacks | ||
264 | 398 | def test_devices_info_does_not_log_device_id(self): | ||
265 | 399 | """The devices_info does not log the device_id.""" | ||
266 | 400 | # pylint: disable=E1101 | ||
267 | 401 | self.be.wc.results[DEVICES_API] = SAMPLE_DEVICES_JSON | ||
268 | 402 | yield self.be.devices_info() | ||
269 | 403 | |||
270 | 404 | dids = (d['device_id'] for d in EXPECTED_DEVICES_INFO) | ||
271 | 405 | device_id_logged = all(all(did not in r.getMessage() | ||
272 | 406 | for r in self.memento.records) | ||
273 | 407 | for did in dids) | ||
274 | 408 | self.assertTrue(device_id_logged) | ||
275 | 409 | |||
276 | 410 | @inlineCallbacks | ||
277 | 383 | def test_remove_device(self): | 411 | def test_remove_device(self): |
278 | 384 | """The remove_device method calls the right api.""" | 412 | """The remove_device method calls the right api.""" |
280 | 385 | dtype, did = "Computer", "SAMPLE-TOKEN" | 413 | dtype, did = DEVICE_TYPE_COMPUTER, "SAMPLE-TOKEN" |
281 | 386 | device_id = dtype + did | 414 | device_id = dtype + did |
282 | 387 | apiurl = DEVICE_REMOVE_API % (dtype.lower(), did) | 415 | apiurl = DEVICE_REMOVE_API % (dtype.lower(), did) |
283 | 388 | # pylint: disable=E1101 | 416 | # pylint: disable=E1101 |
284 | @@ -411,6 +439,16 @@ | |||
285 | 411 | WebClientError) | 439 | WebClientError) |
286 | 412 | 440 | ||
287 | 413 | @inlineCallbacks | 441 | @inlineCallbacks |
288 | 442 | def test_remove_device_does_not_log_device_id(self): | ||
289 | 443 | """The remove_device does not log the device_id.""" | ||
290 | 444 | device_id = DEVICE_TYPE_COMPUTER + TOKEN['token'] | ||
291 | 445 | yield self.be.remove_device(device_id) | ||
292 | 446 | |||
293 | 447 | device_id_logged = all(device_id not in r.getMessage() | ||
294 | 448 | for r in self.memento.records) | ||
295 | 449 | self.assertTrue(device_id_logged) | ||
296 | 450 | |||
297 | 451 | @inlineCallbacks | ||
298 | 414 | def test_change_show_all_notifications(self): | 452 | def test_change_show_all_notifications(self): |
299 | 415 | """The device settings are updated.""" | 453 | """The device settings are updated.""" |
300 | 416 | backend.dbus_client.show_all_notifications = False | 454 | backend.dbus_client.show_all_notifications = False |
301 | @@ -465,6 +503,16 @@ | |||
302 | 465 | self.assertEqual(backend.dbus_client.limits["upload"], -1) | 503 | self.assertEqual(backend.dbus_client.limits["upload"], -1) |
303 | 466 | self.assertEqual(backend.dbus_client.limits["download"], -1) | 504 | self.assertEqual(backend.dbus_client.limits["download"], -1) |
304 | 467 | 505 | ||
305 | 506 | @inlineCallbacks | ||
306 | 507 | def test_changing_settings_does_not_log_device_id(self): | ||
307 | 508 | """The change_device_settings does not log the device_id.""" | ||
308 | 509 | device_id = 'yadda-yadda' | ||
309 | 510 | yield self.be.change_device_settings(device_id, {}) | ||
310 | 511 | |||
311 | 512 | device_id_logged = all(device_id not in r.getMessage() | ||
312 | 513 | for r in self.memento.records) | ||
313 | 514 | self.assertTrue(device_id_logged) | ||
314 | 515 | |||
315 | 468 | 516 | ||
316 | 469 | class BackendVolumesTestCase(BackendBasicTestCase): | 517 | class BackendVolumesTestCase(BackendBasicTestCase): |
317 | 470 | """Volumes tests for the backend.""" | 518 | """Volumes tests for the backend.""" |
318 | 471 | 519 | ||
319 | === modified file 'ubuntuone/controlpanel/webclient.py' | |||
320 | --- ubuntuone/controlpanel/webclient.py 2010-12-18 16:21:36 +0000 | |||
321 | +++ ubuntuone/controlpanel/webclient.py 2011-03-31 21:12:36 +0000 | |||
322 | @@ -48,7 +48,7 @@ | |||
323 | 48 | 48 | ||
324 | 49 | def _handler(self, session, msg, d): | 49 | def _handler(self, session, msg, d): |
325 | 50 | """Handle the result of an http message.""" | 50 | """Handle the result of an http message.""" |
327 | 51 | logger.debug("WebClient: got http response %d for uri %r", | 51 | logger.debug("got http response %d for uri %r", |
328 | 52 | msg.status_code, msg.get_uri().to_string(False)) | 52 | msg.status_code, msg.get_uri().to_string(False)) |
329 | 53 | data = msg.response_body.data | 53 | data = msg.response_body.data |
330 | 54 | if msg.status_code == 200: | 54 | if msg.status_code == 200: |
331 | @@ -62,7 +62,7 @@ | |||
332 | 62 | """Get a given url from the webservice with credentials.""" | 62 | """Get a given url from the webservice with credentials.""" |
333 | 63 | url = (self.base_url + api_name).encode('utf-8') | 63 | url = (self.base_url + api_name).encode('utf-8') |
334 | 64 | method = "GET" | 64 | method = "GET" |
336 | 65 | logger.debug("WebClient: getting url: %s, %s", method, url) | 65 | logger.debug("getting url: %s, %s", method, url) |
337 | 66 | msg = Soup.Message.new(method, url) | 66 | msg = Soup.Message.new(method, url) |
338 | 67 | add_oauth_headers(msg.request_headers.append, method, url, credentials) | 67 | add_oauth_headers(msg.request_headers.append, method, url, credentials) |
339 | 68 | d = defer.Deferred() | 68 | d = defer.Deferred() |
340 | @@ -71,7 +71,8 @@ | |||
341 | 71 | 71 | ||
342 | 72 | def call_api(self, api_name): | 72 | def call_api(self, api_name): |
343 | 73 | """Get a given url from the webservice.""" | 73 | """Get a given url from the webservice.""" |
345 | 74 | logger.debug("WebClient: calling api: %s", api_name) | 74 | # this may log device ID's, but only for removals, which is OK |
346 | 75 | logger.debug("calling api: %s", api_name) | ||
347 | 75 | d = self.get_credentials() | 76 | d = self.get_credentials() |
348 | 76 | d.addCallback(self._call_api_with_creds, api_name) | 77 | d.addCallback(self._call_api_with_creds, api_name) |
349 | 77 | return d | 78 | return d |
Looks great!