Merge lp:~mandel/ubuntuone-windows-installer/fix-reactor-import into lp:ubuntuone-windows-installer
- fix-reactor-import
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Natalia Bidart | ||||
Approved revision: | 96 | ||||
Merged at revision: | 82 | ||||
Proposed branch: | lp:~mandel/ubuntuone-windows-installer/fix-reactor-import | ||||
Merge into: | lp:ubuntuone-windows-installer | ||||
Diff against target: |
555 lines (+280/-156) 5 files modified
ubuntuone_installer/gui/qt/main/tests/test_windows.py (+108/-119) ubuntuone_installer/gui/qt/main/windows.py (+7/-36) ubuntuone_installer/gui/qt/utils/__init__.py (+4/-0) ubuntuone_installer/gui/qt/utils/tests/test_windows.py (+126/-1) ubuntuone_installer/gui/qt/utils/windows.py (+35/-0) |
||||
To merge this branch: | bzr merge lp:~mandel/ubuntuone-windows-installer/fix-reactor-import | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Natalia Bidart (community) | Approve | ||
Diego Sarmentero (community) | Approve | ||
Review via email: mp+79842@code.launchpad.net |
Commit message
Fix the reactor installation by ensuring that tools does not install the reactor.
Description of the change
Fix the reactor installation by ensuring that tools does not install the reactor.
- 86. By Manuel de la Peña
-
Import tools from inside the func and get utils out again.
- 87. By Manuel de la Peña
-
Reset else.
- 88. By Manuel de la Peña
-
Fix pep8.
- 89. By Manuel de la Peña
-
Fix tests.
Natalia Bidart (nataliabidart) wrote : | # |
(01:34:37 PM) nessita: mandel: right, so the fix should be move the utils import from the global space to inside the def's that need it
(01:35:10 PM) nessita: mandel: in fact, I'm wondering why those def's are in main() (besides the main() itself)
(01:35:50 PM) nessita: mandel: so, I would move:
(01:36:29 PM) nessita: check_updates, check_credentials to utils, and then import the utils module inside the main() def, after the reactor was installed
(01:36:56 PM) nessita: mandel: that way we can also cleanup the passing of the CredentialsMana
(01:37:33 PM) nessita: mandel: since, if we move check_credentials to utils, which will be imported after the reactor was installed, we can import CredentialsMana
(01:37:38 PM) nessita: mandel: you followed me?
(01:38:37 PM) mandel: nessita, so, move everything but move to utils and then simply import check_credentials, right?
(01:38:57 PM) nessita: mandel: hem.. that's a subset, yes
(01:39:10 PM) nessita: mandel: you can't move the reactor callbacks, for example
(01:39:31 PM) nessita: so, stop, error_cb, and success_cb remain in main()
(01:39:46 PM) mandel: nessita, why can't I move success?
(01:39:55 PM) nessita: mandel: it creates a GUI
(01:40:02 PM) nessita: we don't want to move that to utils
(01:40:06 PM) mandel: oh, true..
(01:40:33 PM) mandel: I hate that stupid import magic from the reactor, is making or code look horrible
(01:40:41 PM) nessita: mandel: yes
(01:41:16 PM) mandel: nessita, ok, can you add a needs fixing and I'll sort out this tom early morning, I ran out of hours
- 90. By Manuel de la Peña
-
Moved functions to utils and sorted the tests to ensure everything works as expected.
- 91. By Manuel de la Peña
-
Fixed lint issues.
- 92. By Manuel de la Peña
-
Import credentials from the main function.
Natalia Bidart (nataliabidart) wrote : | # |
* Code looks good. One tiny note: the FakeCredsManage
255 + def find_credential
256 + """Fake find credentials."""
257 + if FakeCredsManage
258 + return defer.fail(
259 + else:
260 + return defer.succeed(
* Tests are not passing on windows:
=======
[ERROR]
Traceback (most recent call last):
File "C:\Python27\
_inlineCallbacks
result = g.send(result)
File "E:\windows-
t\main\
yield windows.
exceptions.
ubuntuone_
_failure
=======
[ERROR]
Traceback (most recent call last):
File "C:\Python27\
_inlineCallbacks
result = g.send(result)
File "E:\windows-
t\main\
yield windows.
exceptions.
ubuntuone_
_no_creds
=======
[ERROR]
Traceback (most recent call last):
File "C:\Python27\
_inlineCallbacks
result = g.send(result)
File "E:\windows-
t\main\
yield windows.
exceptions.
ubuntuone_
_with_creds
=======
[ERROR]
Traceback (most recent call last):
File "C:\Python27\
_inlineCallbacks
result = g.send(result)
File "E:\windows-
t\main\
yield windows.
exceptions.
ubuntuone_
_with_installed
=======
[ERROR]
Traceback (most recent call last):
File "C:\Python27\
_inlineCallbacks
result = g.send(result)
File "E:\windows-
t\main\
- 93. By Manuel de la Peña
-
Fixed tests.
- 94. By Manuel de la Peña
-
Fixed lint issues.
- 95. By Manuel de la Peña
-
Ignore pylint.
- 96. By Manuel de la Peña
-
Added test for error_cb
Natalia Bidart (nataliabidart) wrote : | # |
Looks good!
Preview Diff
1 | === modified file 'ubuntuone_installer/gui/qt/main/tests/test_windows.py' |
2 | --- ubuntuone_installer/gui/qt/main/tests/test_windows.py 2011-09-29 13:26:44 +0000 |
3 | +++ ubuntuone_installer/gui/qt/main/tests/test_windows.py 2011-10-21 15:53:24 +0000 |
4 | @@ -21,39 +21,10 @@ |
5 | |
6 | from twisted.internet import defer |
7 | |
8 | -from ubuntuone_installer.gui.qt import gui, utils |
9 | from ubuntuone_installer.gui.qt.main import windows |
10 | -from ubuntuone_installer.gui.qt.tests.test_gui import FakeMainWindow |
11 | from ubuntuone_installer.tests import TestCase |
12 | |
13 | |
14 | -class FakeFailingCredentialsManagementTool(object): |
15 | - |
16 | - """A fake CredentialsManagementTool that fails.""" |
17 | - |
18 | - def find_credentials(self): |
19 | - """Return a failure.""" |
20 | - return defer.fail(Exception()) |
21 | - |
22 | - |
23 | -class FakeNoCredentialsManagementTool(object): |
24 | - |
25 | - """A fake CredentialsManagementTool that fakes no credentials.""" |
26 | - |
27 | - def find_credentials(self): |
28 | - """Return a success, but no credentials.""" |
29 | - return defer.succeed({}) |
30 | - |
31 | - |
32 | -class FakeCredentialsManagementTool(object): |
33 | - |
34 | - """A fake CredentialsManagementTool that fakes credentials.""" |
35 | - |
36 | - def find_credentials(self): |
37 | - """Return a success, but no credentials.""" |
38 | - return defer.succeed("Something not false") |
39 | - |
40 | - |
41 | class FakeLogger(object): |
42 | |
43 | """Fake Logger.""" |
44 | @@ -75,93 +46,111 @@ |
45 | self.info_args = (args, kwargs) |
46 | |
47 | |
48 | -class CredsFailureMainTestCase(TestCase): |
49 | - |
50 | - """Test the qt main window.""" |
51 | - |
52 | - stopped = False |
53 | - updates_checked = False |
54 | - |
55 | - def stop(self): |
56 | - """A fake stop.""" |
57 | - self.stopped = True |
58 | - |
59 | - def check_updates(self, gui_ref, logger): |
60 | - """A fake check updates.""" |
61 | - self.updates_checked = True |
62 | - |
63 | - @defer.inlineCallbacks |
64 | - def test_failure(self): |
65 | - """Credential errors should display a critical message.""" |
66 | - logger = FakeLogger() |
67 | - self.patch(windows, 'stop', self.stop) |
68 | - self.stopped = False |
69 | - yield windows.check_credentials( |
70 | - FakeFailingCredentialsManagementTool, |
71 | - gui, logger) |
72 | - # Should log the error |
73 | - self.assertEqual(logger.error_args[0][0], |
74 | - ('Error while getting the credentials: %r')) |
75 | - # Should stop the app |
76 | - self.assertTrue(self.stopped) |
77 | - |
78 | - @defer.inlineCallbacks |
79 | - def test_no_creds(self): |
80 | - """No credentials should start the wizard.""" |
81 | - logger = FakeLogger() |
82 | - fakemain = FakeMainWindow() |
83 | - self.patch(gui, 'MainWindow', lambda *args, **kwargs: fakemain) |
84 | - self.patch(windows, 'stop', self._set_called) |
85 | - self.assertFalse(fakemain.shown) |
86 | - self.patch(windows, 'stop', self.stop) |
87 | - self.stopped = False |
88 | - yield windows.check_credentials( |
89 | - FakeNoCredentialsManagementTool, |
90 | - gui, logger) |
91 | - # Should show the main window |
92 | - self.assertTrue(fakemain.shown) |
93 | - # Should not log errors |
94 | - self.assertEqual(logger.error_args, None) |
95 | - # Should not stop the app |
96 | - self.assertFalse(self.stopped) |
97 | - |
98 | - @defer.inlineCallbacks |
99 | - def test_with_creds(self): |
100 | - """Having credentials should start the control panel.""" |
101 | - logger = FakeLogger() |
102 | - self.patch(utils, 'start_control_panel', self._set_called) |
103 | - self.patch(windows, 'stop', self.stop) |
104 | - self.patch(windows, 'check_updates', self.check_updates) |
105 | - self.stopped = False |
106 | - yield windows.check_credentials( |
107 | - FakeCredentialsManagementTool, |
108 | - gui, logger) |
109 | - # Should not log errors |
110 | - self.assertEqual(logger.error_args, None) |
111 | - # Should start u1cp |
112 | - self.assertEqual(self._called, ((), {'with_icon': False})) |
113 | - # Should stop the app |
114 | - self.assertTrue(self.stopped) |
115 | - self.assertTrue(self.updates_checked) |
116 | - |
117 | - @defer.inlineCallbacks |
118 | - def test_without_installed_flag(self): |
119 | - """Test behaviour without the installer flag.""" |
120 | - logger = FakeLogger() |
121 | - self.patch(windows, "success_cb", self._set_called) |
122 | - yield windows.check_credentials( |
123 | - FakeCredentialsManagementTool, |
124 | - gui, logger) |
125 | - self.assertEqual(self._called, (('Something not false', |
126 | - gui, False, logger), {})) |
127 | - |
128 | - @defer.inlineCallbacks |
129 | - def test_with_installed_flag(self): |
130 | - """Test behaviour without the installer flag.""" |
131 | - logger = FakeLogger() |
132 | - self.patch(windows, "success_cb", self._set_called) |
133 | - yield windows.check_credentials( |
134 | - FakeCredentialsManagementTool, |
135 | - gui, logger, installer=True) |
136 | - self.assertEqual(self._called, (('Something not false', |
137 | - gui, True, logger), {})) |
138 | +class FakeGui(object): |
139 | + """Fake gui module.""" |
140 | + |
141 | + def __init__(self): |
142 | + """Create a new instance.""" |
143 | + self.main_window = None |
144 | + self.close = None |
145 | + self.installing = False |
146 | + self.called = [] |
147 | + |
148 | + # pylint: disable=C0103 |
149 | + def MainWindow(self, close_callback=lambda: None, installing=False): |
150 | + """Fake main window creation.""" |
151 | + self.close = close_callback |
152 | + self.installing = installing |
153 | + self.called.append('MainWindow') |
154 | + return self.main_window |
155 | + # pylint: enable=C0103 |
156 | + |
157 | + |
158 | +class FakeWindow(object): |
159 | + """Fake a window.""" |
160 | + |
161 | + def __init__(self): |
162 | + """Create a new instance.""" |
163 | + self.shown = False |
164 | + |
165 | + def show(self): |
166 | + """Fake a shown window.""" |
167 | + self.shown = True |
168 | + |
169 | + |
170 | +class SuccessTestCase(TestCase): |
171 | + """Test the success callback.""" |
172 | + |
173 | + @defer.inlineCallbacks |
174 | + def setUp(self): |
175 | + """Set up the diff tests.""" |
176 | + yield super(SuccessTestCase, self).setUp() |
177 | + self.called = [] |
178 | + self.start_name = 'start' |
179 | + self.update_name = 'update' |
180 | + self.stop_name = 'stop' |
181 | + self.gui = FakeGui() |
182 | + self.gui.main_window = FakeWindow() |
183 | + self.logger = FakeLogger() |
184 | + |
185 | + def fake_start(with_icon=False): |
186 | + """Fake the control panel start.""" |
187 | + self.called.append((self.start_name, with_icon)) |
188 | + return defer.succeed(None) |
189 | + |
190 | + def fake_check_updates(gui, logger): |
191 | + """Fake the check of updates.""" |
192 | + self.called.append((self.update_name, gui, logger)) |
193 | + return defer.succeed(None) |
194 | + |
195 | + def fake_stop(): |
196 | + """Fake stop.""" |
197 | + self.called.append((self.stop_name,)) |
198 | + |
199 | + self.patch(windows, 'stop', fake_stop) |
200 | + self.start_cb = fake_start |
201 | + self.check_updates_cb = fake_check_updates |
202 | + |
203 | + @defer.inlineCallbacks |
204 | + def test_success_with_creds(self): |
205 | + """Test the success callback with creds.""" |
206 | + yield windows.success_cb('creds', self.gui, False, self.logger, |
207 | + self.start_cb, self.check_updates_cb) |
208 | + self.assertEqual(self.start_name, self.called[0][0]) |
209 | + self.assertFalse(self.called[0][1]) |
210 | + self.assertEqual(self.update_name, self.called[1][0]) |
211 | + self.assertEqual(self.gui, self.called[1][1]) |
212 | + self.assertEqual(self.logger, self.called[1][2]) |
213 | + self.assertEqual(self.stop_name, self.called[2][0]) |
214 | + self.assertEqual(0, len(self.gui.called)) |
215 | + |
216 | + @defer.inlineCallbacks |
217 | + def test_success_not_creds(self): |
218 | + """Test the success callback with no creds.""" |
219 | + yield windows.success_cb(None, self.gui, True, self.logger, |
220 | + self.start_cb, self.check_updates_cb) |
221 | + self.assertTrue('MainWindow' in self.gui.called) |
222 | + self.assertTrue(self.gui.main_window.shown) |
223 | + |
224 | + |
225 | +class ErrorTestCase(TestCase): |
226 | + """Test the success callback.""" |
227 | + |
228 | + @defer.inlineCallbacks |
229 | + def setUp(self): |
230 | + """Set up the diff tests.""" |
231 | + yield super(ErrorTestCase, self).setUp() |
232 | + self.called = [] |
233 | + self.stop_name = 'stop' |
234 | + self.logger = FakeLogger() |
235 | + |
236 | + def fake_stop(): |
237 | + """Fake stop.""" |
238 | + self.called.append(self.stop_name) |
239 | + |
240 | + self.patch(windows, 'stop', fake_stop) |
241 | + |
242 | + def test_stop(self): |
243 | + """Test the error_cb""" |
244 | + windows.error_cb(Exception('test'), self.logger) |
245 | + self.assertTrue(self.stop_name in self.called) |
246 | |
247 | === modified file 'ubuntuone_installer/gui/qt/main/windows.py' |
248 | --- ubuntuone_installer/gui/qt/main/windows.py 2011-09-29 13:26:44 +0000 |
249 | +++ ubuntuone_installer/gui/qt/main/windows.py 2011-10-21 15:53:24 +0000 |
250 | @@ -29,7 +29,6 @@ |
251 | # pylint: disable=W0611 |
252 | from ubuntuone_installer.gui.qt.ui import images_rc |
253 | # pylint: enable=W0611 |
254 | -from ubuntuone_installer.gui.qt import utils |
255 | |
256 | |
257 | def stop(*args): |
258 | @@ -46,13 +45,14 @@ |
259 | |
260 | |
261 | @defer.inlineCallbacks |
262 | -def success_cb(creds, gui, installing, logger): |
263 | +def success_cb(creds, gui, installing, logger, start_control_panel, |
264 | + check_updates): |
265 | """Handle credentials success.""" |
266 | logger.debug('Got back from sso.') |
267 | if creds: # Have credentials already |
268 | logger.debug('Already got credentials.') |
269 | logger.info('Starting control panel.') |
270 | - utils.start_control_panel(with_icon=False) |
271 | + start_control_panel(with_icon=False) |
272 | logger.info('Checking updates.') |
273 | yield check_updates(gui, logger) |
274 | logger.info('Stopping.') |
275 | @@ -72,37 +72,6 @@ |
276 | window.show() |
277 | |
278 | |
279 | -@defer.inlineCallbacks |
280 | -def check_credentials(credentials_tool, gui, logger, |
281 | - installer=False): |
282 | - """Check credentials and either start u1cp or show the wizard.""" |
283 | - credtool = credentials_tool() |
284 | - # pylint: disable=W0703 |
285 | - try: |
286 | - creds = yield credtool.find_credentials() |
287 | - except Exception, exc: |
288 | - error_cb(exc, logger) |
289 | - else: |
290 | - yield success_cb(creds, gui, installer, logger) |
291 | - |
292 | - |
293 | -@defer.inlineCallbacks |
294 | -def check_updates(gui, logger): |
295 | - """Check for updates.""" |
296 | - logger.info('Checking for updates.') |
297 | - # the idea is simple, check if there are updates, ask user if we perform |
298 | - # the update and continue. |
299 | - are_updates_present = yield utils.are_updates_present(logger) |
300 | - logger.debug('Updates present: %r', are_updates_present) |
301 | - if are_updates_present: |
302 | - logger.info('Updates are present.') |
303 | - if gui.user_wants_to_update(): |
304 | - logger.info('Performing auto-update in diff process.') |
305 | - utils.perform_update() |
306 | - else: |
307 | - logger.info('No updates are present.') |
308 | - |
309 | - |
310 | def main(installing=False): |
311 | """Perform a client request to be logged in.""" |
312 | # pylint: disable=W0612 |
313 | @@ -113,8 +82,10 @@ |
314 | from ubuntuone_installer.gui.qt import gui |
315 | from twisted.internet import reactor |
316 | # All this has to be imported here because it installs a reactor |
317 | - from ubuntuone.platform.credentials import CredentialsManagementTool |
318 | from ubuntuone_installer.logger import setup_logging |
319 | + from ubuntuone_installer.gui.qt.utils import check_credentials |
320 | + |
321 | logger = setup_logging('qt.gui') |
322 | - check_credentials(CredentialsManagementTool, gui, logger, installing) |
323 | + check_credentials(gui, logger, success_cb, |
324 | + error_cb, installing) |
325 | reactor.run() |
326 | |
327 | === modified file 'ubuntuone_installer/gui/qt/utils/__init__.py' |
328 | --- ubuntuone_installer/gui/qt/utils/__init__.py 2011-10-06 10:42:01 +0000 |
329 | +++ ubuntuone_installer/gui/qt/utils/__init__.py 2011-10-21 15:53:24 +0000 |
330 | @@ -33,6 +33,8 @@ |
331 | perform_update = windows.perform_update |
332 | uninstall_old_beta = windows.uninstall_old_beta |
333 | migrate_old_data = windows.migrate_old_data |
334 | + check_updates = windows.check_updates |
335 | + check_credentials = windows.check_credentials |
336 | else: |
337 | from ubuntuone_installer.gui.qt.utils import linux |
338 | uninstall_application = linux.uninstall_application |
339 | @@ -44,3 +46,5 @@ |
340 | perform_update = lambda *args, **kwargs: None |
341 | uninstall_old_beta = lambda *args, **kwargs: None |
342 | migrate_old_data = lambda *args, **kwargs: None |
343 | + check_updates = lambda *args, **kwargs: None |
344 | + check_credentials = lambda *args, **kwargs: None |
345 | |
346 | === modified file 'ubuntuone_installer/gui/qt/utils/tests/test_windows.py' |
347 | --- ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-10-18 13:42:46 +0000 |
348 | +++ ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-10-21 15:53:24 +0000 |
349 | @@ -29,7 +29,11 @@ |
350 | # pylint: enable=F0401 |
351 | |
352 | from twisted.internet import defer |
353 | +# pylint: disable=E0611 |
354 | +from ubuntuone.platform import tools |
355 | +# pylint: enable=E0611 |
356 | |
357 | +from ubuntuone_installer.gui.qt import gui |
358 | from ubuntuone_installer.gui.qt import utils |
359 | from ubuntuone_installer.gui.qt.tests import BaseTestCase |
360 | |
361 | @@ -269,7 +273,7 @@ |
362 | |
363 | self.patch(utils.windows, 'default_folders', |
364 | fake_get_default_folders) |
365 | - self.patch(utils.windows.tools, 'SyncDaemonTool', |
366 | + self.patch(tools, 'SyncDaemonTool', |
367 | FakeSDTool) |
368 | self.patch(utils.windows, 'deferToThread', fake_defer_to_thread) |
369 | |
370 | @@ -541,3 +545,124 @@ |
371 | |
372 | def test_get_auto_update_path(self): |
373 | """Test the method used to get the autoupdate.""" |
374 | + |
375 | + |
376 | +class CheckUpdatesTestCase(BaseTestCase): |
377 | + """Test the code that is used for the auto update check process.""" |
378 | + |
379 | + @defer.inlineCallbacks |
380 | + def setUp(self): |
381 | + """Set the different tests.""" |
382 | + yield super(CheckUpdatesTestCase, self).setUp() |
383 | + self.are_present = False |
384 | + self.user_wants_update = False |
385 | + self.logger = FakeLogger() |
386 | + self.called = [] |
387 | + |
388 | + def fake_are_present(logger): |
389 | + """Fake are updates present.""" |
390 | + self.called.append('are_updates_present') |
391 | + return self.are_present |
392 | + |
393 | + def fake_perform_update(): |
394 | + """Fake perform update.""" |
395 | + self.called.append('perform_update') |
396 | + |
397 | + def fake_user_wants_to_update(): |
398 | + """Fake user_wants_to_update.""" |
399 | + self.called.append('user_wants_to_update') |
400 | + return self.user_wants_update |
401 | + |
402 | + self.patch(utils.windows, 'are_updates_present', fake_are_present) |
403 | + self.patch(utils.windows, 'perform_update', fake_perform_update) |
404 | + self.patch(gui, 'user_wants_to_update', fake_user_wants_to_update) |
405 | + |
406 | + @defer.inlineCallbacks |
407 | + def test_check_updates_not_present(self): |
408 | + """Test the method that interacts with the user.""" |
409 | + self.are_present = False |
410 | + yield utils.check_updates(gui, self.logger) |
411 | + self.assertTrue('are_updates_present' in self.called) |
412 | + self.assertFalse('perform_update' in self.called) |
413 | + |
414 | + @defer.inlineCallbacks |
415 | + def test_check_updates_present_not_user(self): |
416 | + """Test the method that interacts with the user.""" |
417 | + self.are_present = True |
418 | + self.user_wants_update = False |
419 | + yield utils.check_updates(gui, self.logger) |
420 | + self.assertTrue('are_updates_present' in self.called) |
421 | + self.assertTrue('user_wants_to_update' in self.called) |
422 | + self.assertFalse('perform_update' in self.called) |
423 | + |
424 | + @defer.inlineCallbacks |
425 | + def test_check_updates_present_user(self): |
426 | + """Test the method that interacts with the user.""" |
427 | + self.are_present = True |
428 | + self.user_wants_update = True |
429 | + yield utils.check_updates(gui, self.logger) |
430 | + self.assertTrue('are_updates_present' in self.called) |
431 | + self.assertTrue('user_wants_to_update' in self.called) |
432 | + self.assertTrue('perform_update' in self.called) |
433 | + |
434 | + |
435 | +class FakeCredsManagementTool(object): |
436 | + """Fake a creds management tool.""" |
437 | + |
438 | + raise_error = False |
439 | + credentials = None |
440 | + |
441 | + def __init__(self): |
442 | + """Create a new instance.""" |
443 | + |
444 | + def find_credentials(self): |
445 | + """Fake find credentials.""" |
446 | + if FakeCredsManagementTool.raise_error: |
447 | + return defer.fail(Exception('Test!')) |
448 | + else: |
449 | + return defer.succeed(FakeCredsManagementTool.credentials) |
450 | + |
451 | + |
452 | +class CheckCredentialsTestCase(BaseTestCase): |
453 | + """Test the code that is used to check the credentials.""" |
454 | + |
455 | + @defer.inlineCallbacks |
456 | + def setUp(self): |
457 | + """Set the different tests.""" |
458 | + yield super(CheckCredentialsTestCase, self).setUp() |
459 | + self.logger = FakeLogger() |
460 | + self.called = [] |
461 | + |
462 | + def success(creds, gui_ref, installing, logger, start_control_panel, |
463 | + check_updates): |
464 | + """Success cb.""" |
465 | + self.called.append(('success', creds, gui_ref, installing, logger, |
466 | + start_control_panel, check_updates)) |
467 | + |
468 | + def error(exc, logger): |
469 | + """Error cb.""" |
470 | + self.called.append(('error', exc, logger)) |
471 | + |
472 | + self.success_cb = success |
473 | + self.error_cb = error |
474 | + self.patch(utils.windows, 'CredentialsManagementTool', |
475 | + FakeCredsManagementTool) |
476 | + |
477 | + @defer.inlineCallbacks |
478 | + def test_check_credentials_not_present(self): |
479 | + """Test when creds are not present.""" |
480 | + FakeCredsManagementTool.raise_error = True |
481 | + yield utils.check_credentials(gui, self.logger, self.success_cb, |
482 | + self.error_cb) |
483 | + self.assertTrue('error' in self.called[0]) |
484 | + |
485 | + @defer.inlineCallbacks |
486 | + def test_check_credentials_present(self): |
487 | + """Test when creds are present.""" |
488 | + FakeCredsManagementTool.raise_error = False |
489 | + FakeCredsManagementTool.credentials = 'creds' |
490 | + yield utils.check_credentials(gui, self.logger, self.success_cb, |
491 | + self.error_cb) |
492 | + self.assertTrue('success' in self.called[0]) |
493 | + self.assertEqual(FakeCredsManagementTool.credentials, |
494 | + self.called[0][1]) |
495 | |
496 | === modified file 'ubuntuone_installer/gui/qt/utils/windows.py' |
497 | --- ubuntuone_installer/gui/qt/utils/windows.py 2011-10-18 13:42:46 +0000 |
498 | +++ ubuntuone_installer/gui/qt/utils/windows.py 2011-10-21 15:53:24 +0000 |
499 | @@ -38,7 +38,10 @@ |
500 | from twisted.internet.utils import getProcessValue |
501 | from twisted.internet.threads import deferToThread |
502 | |
503 | +# pylint: disable=E0611 |
504 | from ubuntuone.platform import tools |
505 | +# pylint: enable=E0611 |
506 | +from ubuntuone.platform.credentials import CredentialsManagementTool |
507 | |
508 | AUTORUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run" |
509 | |
510 | @@ -98,6 +101,21 @@ |
511 | |
512 | |
513 | @defer.inlineCallbacks |
514 | +def check_credentials(gui, logger, success_cb, error_cb, |
515 | + installer=False): |
516 | + """Check credentials and either start u1cp or show the wizard.""" |
517 | + credtool = CredentialsManagementTool() |
518 | + # pylint: disable=W0703 |
519 | + try: |
520 | + creds = yield credtool.find_credentials() |
521 | + except Exception, exc: |
522 | + error_cb(exc, logger) |
523 | + else: |
524 | + yield success_cb(creds, gui, installer, logger, start_control_panel, |
525 | + check_updates) |
526 | + |
527 | + |
528 | +@defer.inlineCallbacks |
529 | def are_updates_present(logger): |
530 | """Return if there are updates for Ubuntu One.""" |
531 | update_path = _get_update_path() |
532 | @@ -125,6 +143,23 @@ |
533 | '--unattendedmodeui none', '', 0) |
534 | |
535 | |
536 | +@defer.inlineCallbacks |
537 | +def check_updates(gui, logger): |
538 | + """Check for updates.""" |
539 | + logger.info('Checking for updates.') |
540 | + # the idea is simple, check if there are updates, ask user if we perform |
541 | + # the update and continue. |
542 | + are_present = yield are_updates_present(logger) |
543 | + logger.debug('Updates present: %r', are_updates_present) |
544 | + if are_present: |
545 | + logger.info('Updates are present.') |
546 | + if gui.user_wants_to_update(): |
547 | + logger.info('Performing auto-update in diff process.') |
548 | + perform_update() |
549 | + else: |
550 | + logger.info('No updates are present.') |
551 | + |
552 | + |
553 | def start_control_panel(with_icon=True): |
554 | """Start the control panel.""" |
555 | # If we are in windows and "frozen", assume it's in |
+1