Merge lp:~nataliabidart/ubuntuone-windows-installer/import-qt4reactor into lp:ubuntuone-windows-installer

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 90
Merged at revision: 88
Proposed branch: lp:~nataliabidart/ubuntuone-windows-installer/import-qt4reactor
Merge into: lp:ubuntuone-windows-installer
Diff against target: 814 lines (+223/-395)
10 files modified
ubuntuone_installer/gui/qt/main/__init__.py (+37/-7)
ubuntuone_installer/gui/qt/main/linux.py (+9/-30)
ubuntuone_installer/gui/qt/main/tests/__init__.py (+0/-19)
ubuntuone_installer/gui/qt/main/tests/test_windows.py (+0/-156)
ubuntuone_installer/gui/qt/main/windows.py (+16/-74)
ubuntuone_installer/gui/qt/utils/__init__.py (+35/-3)
ubuntuone_installer/gui/qt/utils/linux.py (+1/-1)
ubuntuone_installer/gui/qt/utils/tests/test_common.py (+112/-0)
ubuntuone_installer/gui/qt/utils/tests/test_windows.py (+6/-86)
ubuntuone_installer/gui/qt/utils/windows.py (+7/-19)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-windows-installer/import-qt4reactor
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+82012@code.launchpad.net

Commit message

- Import qt4reactor properly (LP: #888722).

Description of the change

This also allows us to run the wizard from Linux (is not functional, but the UI is shown if you don't have U1 credentials):

PYTHONPATH=../../controlpanel/trunk/:../../ussoc/trunk/:. bin/ubuntuone-installer-qt

(you will get a
  File "/home/nessita/canonical/ussoc/trunk/ubuntu_sso/main/linux.py", line 412, in get_sso_login_backend
    raise NotImplementedError()
which will be fixed later in the cycle)

To post a comment you must log in.
88. By Natalia Bidart

- Import qt4reactor properly (LP: #888722).

89. By Natalia Bidart

Forgotten file.

90. By Natalia Bidart

No more tests for main (all the logic is in utils).

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Tested IRL under oneiric: works as advertised.
All tests pass under oneiric too.
Nice branch!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone_installer/gui/qt/main/__init__.py'
2--- ubuntuone_installer/gui/qt/main/__init__.py 2011-06-21 15:41:55 +0000
3+++ ubuntuone_installer/gui/qt/main/__init__.py 2011-11-11 19:41:25 +0000
4@@ -1,6 +1,4 @@
5 # -*- coding: utf-8 -*-
6-
7-# Authors: Manuel de la Pena <manuel@canonical.com>
8 #
9 # Copyright 2011 Canonical Ltd.
10 #
11@@ -15,16 +13,48 @@
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16 """Provide the correct reactor and ui integration."""
17
18 import sys
19
20-# pylint: disable=C0103
21-main = None
22-
23+from PyQt4 import QtGui
24+
25+# Module used to include the resources into this file
26+# Unused import images_rc, pylint: disable=W0611
27+from ubuntuone_installer.gui.qt.ui import images_rc
28+# pylint: enable=W0611
29+
30+
31+# Invalid name "source", pylint: disable=C0103
32 if sys.platform == 'win32':
33 from ubuntuone_installer.gui.qt.main import windows
34- main = windows.main
35+ source = windows
36 else:
37 from ubuntuone_installer.gui.qt.main import linux
38- main = linux.main
39+ source = linux
40+# pylint: enable=C0103
41+
42+
43+def main(installing=False):
44+ """Start the Qt reactor and open the main window."""
45+ # The following cannot be imported outside this function
46+ # because u1trial already provides a reactor.
47+
48+ # The main loop MUST be initialized before importing the reactor
49+ app = QtGui.QApplication(sys.argv)
50+ source.main(app)
51+
52+ # Reimport 'qt4reactor', 'reactor', pylint: disable=W0404
53+ import qt4reactor
54+ qt4reactor.install()
55+
56+ from twisted.internet import reactor
57+ from ubuntuone_installer.gui.qt.utils import check_credentials
58+ # pylint: enable=W0404
59+
60+ # Module 'reactor' has no 'run'/'stop' member, pylint: disable=E1101
61+ reactor.callWhenRunning(check_credentials,
62+ installing=installing, stop_cb=reactor.stop)
63+ reactor.run()
64+ # pylint: enable=E1101
65
66=== modified file 'ubuntuone_installer/gui/qt/main/linux.py'
67--- ubuntuone_installer/gui/qt/main/linux.py 2011-06-27 09:59:34 +0000
68+++ ubuntuone_installer/gui/qt/main/linux.py 2011-11-11 19:41:25 +0000
69@@ -1,7 +1,4 @@
70 # -*- coding: utf-8 -*-
71-
72-# Authors: Manuel de la Pena <manuel@canonical.com>
73-# Authors: Alejandro J. Cura <alecu@canonical.com>
74 #
75 # Copyright 2011 Canonical Ltd.
76 #
77@@ -16,36 +13,18 @@
78 #
79 # You should have received a copy of the GNU General Public License along
80 # with this program. If not, see <http://www.gnu.org/licenses/>.
81+
82 """Main method to be used on linux."""
83
84-import sys
85-
86 from dbus.mainloop.qt import DBusQtMainLoop
87-from PyQt4 import Qt
88-
89-from ubuntuone_installer.gui.qt.gui import MainWindow
90-
91-
92-def main():
93- """Start the Qt reactor and open the main window."""
94-
95+from PyQt4 import QtCore
96+
97+
98+def main(app):
99+ """Apply style sheet."""
100 # The DBus main loop MUST be initialized before importing the reactor
101 DBusQtMainLoop(set_as_default=True)
102
103- # The app variable should be in scope of the reactor.run()
104- # pylint: disable=W0612
105- Qt.QApplication(sys.argv)
106-
107- # The following cannot be imported outside this function
108- # because u1trial already provides a reactor.
109- # pylint: disable=W0404, F0401
110- from qtreactor import qt4reactor
111- qt4reactor.install()
112- from twisted.internet import reactor
113-
114- # pylint believes that reactor has no run nor stop methods. Silence it.
115- # pylint: disable=E1101
116- window = MainWindow(close_callback=reactor.stop)
117- window.show()
118-
119- reactor.run()
120+ # Apply Style Sheet -- The linux version may be different
121+ qss = QtCore.QResource(":/ubuntuone.qss")
122+ app.setStyleSheet(qss.data())
123
124=== removed directory 'ubuntuone_installer/gui/qt/main/tests'
125=== removed file 'ubuntuone_installer/gui/qt/main/tests/__init__.py'
126--- ubuntuone_installer/gui/qt/main/tests/__init__.py 2011-07-14 03:48:51 +0000
127+++ ubuntuone_installer/gui/qt/main/tests/__init__.py 1970-01-01 00:00:00 +0000
128@@ -1,19 +0,0 @@
129-# -*- coding: utf-8 -*-
130-
131-# Authors: Roberto Alsina <roberto.alsina@canonical.com>
132-#
133-# Copyright 2011 Canonical Ltd.
134-#
135-# This program is free software: you can redistribute it and/or modify it
136-# under the terms of the GNU General Public License version 3, as published
137-# by the Free Software Foundation.
138-#
139-# This program is distributed in the hope that it will be useful, but
140-# WITHOUT ANY WARRANTY; without even the implied warranties of
141-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
142-# PURPOSE. See the GNU General Public License for more details.
143-#
144-# You should have received a copy of the GNU General Public License along
145-# with this program. If not, see <http://www.gnu.org/licenses/>.
146-
147-"""The test suite for the Qt UI of the Ubuntu One Installer."""
148
149=== removed file 'ubuntuone_installer/gui/qt/main/tests/test_windows.py'
150--- ubuntuone_installer/gui/qt/main/tests/test_windows.py 2011-10-21 15:49:09 +0000
151+++ ubuntuone_installer/gui/qt/main/tests/test_windows.py 1970-01-01 00:00:00 +0000
152@@ -1,156 +0,0 @@
153-# -*- coding: utf-8 -*-
154-
155-# Authors: Alejandro J. Cura <alecu@canonical.com>
156-# Roberto Alsina <roberto.alsina@canonical.com>
157-#
158-# Copyright 2011 Canonical Ltd.
159-#
160-# This program is free software: you can redistribute it and/or modify it
161-# under the terms of the GNU General Public License version 3, as published
162-# by the Free Software Foundation.
163-#
164-# This program is distributed in the hope that it will be useful, but
165-# WITHOUT ANY WARRANTY; without even the implied warranties of
166-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
167-# PURPOSE. See the GNU General Public License for more details.
168-#
169-# You should have received a copy of the GNU General Public License along
170-# with this program. If not, see <http://www.gnu.org/licenses/>.
171-
172-"""Tests for the Windows main."""
173-
174-from twisted.internet import defer
175-
176-from ubuntuone_installer.gui.qt.main import windows
177-from ubuntuone_installer.tests import TestCase
178-
179-
180-class FakeLogger(object):
181-
182- """Fake Logger."""
183-
184- error_args = None
185- debug_args = None
186- info_args = None
187-
188- def error(self, *args, **kwargs):
189- """Save the error."""
190- self.error_args = (args, kwargs)
191-
192- def debug(self, *args, **kwargs):
193- """Save the debug."""
194- self.debug_args = (args, kwargs)
195-
196- def info(self, *args, **kwargs):
197- """Save the info."""
198- self.info_args = (args, kwargs)
199-
200-
201-class FakeGui(object):
202- """Fake gui module."""
203-
204- def __init__(self):
205- """Create a new instance."""
206- self.main_window = None
207- self.close = None
208- self.installing = False
209- self.called = []
210-
211- # pylint: disable=C0103
212- def MainWindow(self, close_callback=lambda: None, installing=False):
213- """Fake main window creation."""
214- self.close = close_callback
215- self.installing = installing
216- self.called.append('MainWindow')
217- return self.main_window
218- # pylint: enable=C0103
219-
220-
221-class FakeWindow(object):
222- """Fake a window."""
223-
224- def __init__(self):
225- """Create a new instance."""
226- self.shown = False
227-
228- def show(self):
229- """Fake a shown window."""
230- self.shown = True
231-
232-
233-class SuccessTestCase(TestCase):
234- """Test the success callback."""
235-
236- @defer.inlineCallbacks
237- def setUp(self):
238- """Set up the diff tests."""
239- yield super(SuccessTestCase, self).setUp()
240- self.called = []
241- self.start_name = 'start'
242- self.update_name = 'update'
243- self.stop_name = 'stop'
244- self.gui = FakeGui()
245- self.gui.main_window = FakeWindow()
246- self.logger = FakeLogger()
247-
248- def fake_start(with_icon=False):
249- """Fake the control panel start."""
250- self.called.append((self.start_name, with_icon))
251- return defer.succeed(None)
252-
253- def fake_check_updates(gui, logger):
254- """Fake the check of updates."""
255- self.called.append((self.update_name, gui, logger))
256- return defer.succeed(None)
257-
258- def fake_stop():
259- """Fake stop."""
260- self.called.append((self.stop_name,))
261-
262- self.patch(windows, 'stop', fake_stop)
263- self.start_cb = fake_start
264- self.check_updates_cb = fake_check_updates
265-
266- @defer.inlineCallbacks
267- def test_success_with_creds(self):
268- """Test the success callback with creds."""
269- yield windows.success_cb('creds', self.gui, False, self.logger,
270- self.start_cb, self.check_updates_cb)
271- self.assertEqual(self.start_name, self.called[0][0])
272- self.assertFalse(self.called[0][1])
273- self.assertEqual(self.update_name, self.called[1][0])
274- self.assertEqual(self.gui, self.called[1][1])
275- self.assertEqual(self.logger, self.called[1][2])
276- self.assertEqual(self.stop_name, self.called[2][0])
277- self.assertEqual(0, len(self.gui.called))
278-
279- @defer.inlineCallbacks
280- def test_success_not_creds(self):
281- """Test the success callback with no creds."""
282- yield windows.success_cb(None, self.gui, True, self.logger,
283- self.start_cb, self.check_updates_cb)
284- self.assertTrue('MainWindow' in self.gui.called)
285- self.assertTrue(self.gui.main_window.shown)
286-
287-
288-class ErrorTestCase(TestCase):
289- """Test the success callback."""
290-
291- @defer.inlineCallbacks
292- def setUp(self):
293- """Set up the diff tests."""
294- yield super(ErrorTestCase, self).setUp()
295- self.called = []
296- self.stop_name = 'stop'
297- self.logger = FakeLogger()
298-
299- def fake_stop():
300- """Fake stop."""
301- self.called.append(self.stop_name)
302-
303- self.patch(windows, 'stop', fake_stop)
304-
305- def test_stop(self):
306- """Test the error_cb"""
307- windows.error_cb(Exception('test'), self.logger)
308- self.assertTrue(self.stop_name in self.called)
309
310=== modified file 'ubuntuone_installer/gui/qt/main/windows.py'
311--- ubuntuone_installer/gui/qt/main/windows.py 2011-10-24 12:39:07 +0000
312+++ ubuntuone_installer/gui/qt/main/windows.py 2011-11-11 19:41:25 +0000
313@@ -1,7 +1,4 @@
314 # -*- coding: utf-8 -*-
315-
316-# Authors: Manuel de la Pena <manuel@canonical.com>
317-# Roberto Alsina <roberto.alsina@canonical.com>
318 #
319 # Copyright 2011 Canonical Ltd.
320 #
321@@ -16,76 +13,21 @@
322 #
323 # You should have received a copy of the GNU General Public License along
324 # with this program. If not, see <http://www.gnu.org/licenses/>.
325-"""Reactor installation for windows."""
326-
327-# pylint: disable=E1101, F0401, W0404
328-
329-import sys
330+
331+"""Main method to be used on windows."""
332
333 from PyQt4 import QtGui, QtCore
334-from twisted.internet import defer
335-
336-# Module used to include the resources into this file
337-# pylint: disable=W0611
338-from ubuntuone_installer.gui.qt.ui import images_rc
339-# pylint: enable=W0611
340-
341-
342-def stop(*args):
343- """End the process."""
344- from twisted.internet import reactor
345- reactor.stop()
346-
347-
348-def error_cb(exc, logger):
349- """Handle credentials errors."""
350- logger.error(
351- 'Error while getting the credentials: %r', exc)
352- stop()
353-
354-
355-@defer.inlineCallbacks
356-def success_cb(creds, gui, installing, logger, start_control_panel,
357- check_updates):
358- """Handle credentials success."""
359- logger.debug('Got back from sso.')
360- if creds: # Have credentials already
361- logger.debug('Already got credentials.')
362- logger.info('Starting control panel.')
363- start_control_panel(with_icon=False)
364- logger.info('Checking updates.')
365- yield check_updates(gui, logger)
366- logger.info('Stopping.')
367- stop()
368- else: # No credentials
369- logger.debug('Did got connections.')
370- window = gui.MainWindow(close_callback=stop, installing=installing)
371- # Set Application Style Sheet
372- app = QtGui.QApplication.instance()
373- qss = QtCore.QResource(":/ubuntuone.qss")
374- app.setStyleSheet(QtCore.QString(qss.data()))
375- # Apply font to the entire application
376- QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-R.ttf')
377- QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-B.ttf')
378- # Set Application Icon
379- app.setWindowIcon(QtGui.QIcon(":/ubuntu_one_favicon.png"))
380- window.show()
381-
382-
383-def main(installing=False):
384- """Perform a client request to be logged in."""
385- # pylint: disable=W0612
386- app = QtGui.QApplication(sys.argv)
387- # pylint: enable=W0612
388- import qtreactor.qt4reactor
389- qtreactor.qt4reactor.install()
390- from ubuntuone_installer.gui.qt import gui
391- from twisted.internet import reactor
392- # All this has to be imported here because it installs a reactor
393- from ubuntuone_installer.logger import setup_logging
394- from ubuntuone_installer.gui.qt.utils import check_credentials
395-
396- logger = setup_logging('qt.gui')
397- check_credentials(gui, logger, success_cb,
398- error_cb, installing)
399- reactor.run()
400+
401+
402+def main(app):
403+ """Apply style sheet and fonts."""
404+ # Apply font to the entire application
405+ QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-R.ttf')
406+ QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-B.ttf')
407+
408+ # Set Application Icon
409+ app.setWindowIcon(QtGui.QIcon(":/ubuntu_one_favicon.png"))
410+
411+ # Apply Style Sheet -- The windows version may be different
412+ qss = QtCore.QResource(":/ubuntuone.qss")
413+ app.setStyleSheet(qss.data())
414
415=== modified file 'ubuntuone_installer/gui/qt/utils/__init__.py'
416--- ubuntuone_installer/gui/qt/utils/__init__.py 2011-10-20 14:17:13 +0000
417+++ ubuntuone_installer/gui/qt/utils/__init__.py 2011-11-11 19:41:25 +0000
418@@ -18,9 +18,17 @@
419
420 """Utils Functions Platform specific."""
421
422-
423 import sys
424
425+from ubuntuone.platform.credentials import CredentialsManagementTool
426+from twisted.internet import defer
427+
428+from ubuntuone_installer.logger import setup_logging
429+
430+
431+logger = setup_logging('qt.utils')
432+
433+
434 # pylint: disable=C0103
435 if sys.platform == 'win32':
436 from ubuntuone_installer.gui.qt.utils import windows
437@@ -34,7 +42,6 @@
438 uninstall_old_beta = windows.uninstall_old_beta
439 migrate_old_data = windows.migrate_old_data
440 check_updates = windows.check_updates
441- check_credentials = windows.check_credentials
442 else:
443 from ubuntuone_installer.gui.qt.utils import linux
444 uninstall_application = linux.uninstall_application
445@@ -47,4 +54,29 @@
446 uninstall_old_beta = lambda *args, **kwargs: None
447 migrate_old_data = lambda *args, **kwargs: None
448 check_updates = lambda *args, **kwargs: None
449- check_credentials = lambda *args, **kwargs: None
450+# pylint: enable=C0103
451+
452+
453+@defer.inlineCallbacks
454+def check_credentials(stop_cb, installing):
455+ """Check credentials and either start u1cp or show the wizard."""
456+ credtool = CredentialsManagementTool()
457+ try:
458+ creds = yield credtool.find_credentials()
459+ except: # pylint: disable=W0702
460+ logger.exception('Error while getting the credentials:')
461+ stop_cb()
462+ else:
463+ from ubuntuone_installer.gui.qt import gui # pylint: disable=W0404
464+ if creds: # Have credentials already
465+ logger.info('Got credentials! starting controlpanel.')
466+ start_control_panel(with_icon=False)
467+ logger.info('Checking updates')
468+ yield check_updates(gui)
469+ logger.info('Updates checked, stopping.')
470+ stop_cb()
471+ else: # No credentials
472+ logger.info('Got empty credentials, starting wizard app.')
473+ window = gui.MainWindow(close_callback=stop_cb,
474+ installing=installing)
475+ window.show()
476
477=== modified file 'ubuntuone_installer/gui/qt/utils/linux.py'
478--- ubuntuone_installer/gui/qt/utils/linux.py 2011-09-15 19:33:35 +0000
479+++ ubuntuone_installer/gui/qt/utils/linux.py 2011-11-11 19:41:25 +0000
480@@ -27,7 +27,7 @@
481 pass
482
483
484-def start_control_panel():
485+def start_control_panel(with_icon=False):
486 """Start the control panel."""
487 subprocess.Popen(["ubuntuone-control-panel-qt"])
488
489
490=== added file 'ubuntuone_installer/gui/qt/utils/tests/test_common.py'
491--- ubuntuone_installer/gui/qt/utils/tests/test_common.py 1970-01-01 00:00:00 +0000
492+++ ubuntuone_installer/gui/qt/utils/tests/test_common.py 2011-11-11 19:41:25 +0000
493@@ -0,0 +1,112 @@
494+# -*- coding: utf-8 -*-
495+#
496+# Copyright 2011 Canonical Ltd.
497+#
498+# This program is free software: you can redistribute it and/or modify it
499+# under the terms of the GNU General Public License version 3, as published
500+# by the Free Software Foundation.
501+#
502+# This program is distributed in the hope that it will be useful, but
503+# WITHOUT ANY WARRANTY; without even the implied warranties of
504+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
505+# PURPOSE. See the GNU General Public License for more details.
506+#
507+# You should have received a copy of the GNU General Public License along
508+# with this program. If not, see <http://www.gnu.org/licenses/>.
509+
510+"""Tests for the multiplatform functions."""
511+
512+import logging
513+
514+from twisted.internet import defer
515+from ubuntuone.devtools.handlers import MementoHandler
516+
517+from ubuntuone_installer.gui.qt import utils, gui
518+from ubuntuone_installer.gui.qt.tests import BaseTestCase
519+
520+
521+class FakeCredsManagementTool(object):
522+ """Fake a creds management tool."""
523+
524+ raise_error = None
525+ credentials = None
526+
527+ def find_credentials(self):
528+ """Fake find credentials."""
529+ if FakeCredsManagementTool.raise_error is not None:
530+ return defer.fail(FakeCredsManagementTool.raise_error)
531+ else:
532+ return defer.succeed(FakeCredsManagementTool.credentials)
533+
534+
535+class FakeWindow(object):
536+ """Fake a windows."""
537+
538+ args = None
539+ visible = False
540+
541+ def __init__(self, *a, **kw):
542+ FakeWindow.args = (a, kw)
543+ self.show = lambda: setattr(FakeWindow, 'visible', True)
544+
545+
546+class CheckCredentialsTestCase(BaseTestCase):
547+ """Test the code that is used to check the credentials."""
548+
549+ @defer.inlineCallbacks
550+ def setUp(self):
551+ """Set the different tests."""
552+ yield super(CheckCredentialsTestCase, self).setUp()
553+ self.called = []
554+ self.patch(utils, 'CredentialsManagementTool', FakeCredsManagementTool)
555+
556+ self.memento = MementoHandler()
557+ self.memento.setLevel(logging.DEBUG)
558+ utils.logger.addHandler(self.memento)
559+ self.addCleanup(utils.logger.removeHandler, self.memento)
560+
561+ self.stop_cb = lambda: self.called.append('stop_cb')
562+
563+ self.start_cp = lambda with_icon: \
564+ self.called.extend(('start_cp', with_icon))
565+ self.patch(utils, 'start_control_panel', self.start_cp)
566+
567+ self.check_updates = lambda _: self.called.append('check_updates')
568+ self.patch(utils, 'check_updates', self.check_updates)
569+
570+ self.patch(gui, 'MainWindow', FakeWindow)
571+
572+ @defer.inlineCallbacks
573+ def test_check_credentials_failure(self):
574+ """Test when the credtool fail."""
575+ exc = ValueError('foo')
576+ self.patch(FakeCredsManagementTool, 'raise_error', exc)
577+ yield utils.check_credentials(stop_cb=self.stop_cb, installing=False)
578+
579+ self.assertEqual(self.called, ['stop_cb'])
580+ self.assertTrue(self.memento.check_exception(exc.__class__, 'foo'))
581+
582+ @defer.inlineCallbacks
583+ def test_check_credentials_present(self):
584+ """Test when creds are present."""
585+ self.patch(FakeCredsManagementTool, 'credentials', {'foo': 'bar'})
586+ yield utils.check_credentials(stop_cb=self.stop_cb, installing=False)
587+
588+ self.assertEqual(self.called, ['start_cp', False,
589+ 'check_updates', 'stop_cb'])
590+ msgs = ('Got credentials! starting controlpanel.', 'Checking updates',
591+ 'Updates checked, stopping.')
592+ for msg in msgs:
593+ self.assertTrue(self.memento.check_info(msg))
594+
595+ @defer.inlineCallbacks
596+ def test_check_credentials_not_present(self):
597+ """Test when creds are present."""
598+ self.patch(FakeCredsManagementTool, 'credentials', {})
599+ yield utils.check_credentials(stop_cb=self.stop_cb, installing=False)
600+
601+ kw = dict(close_callback=self.stop_cb, installing=False)
602+ self.assertEqual(FakeWindow.args, ((), kw))
603+ self.assertTrue(FakeWindow.visible)
604+ msgs = ('Got empty credentials', 'starting wizard')
605+ self.assertTrue(self.memento.check_info(*msgs))
606
607=== modified file 'ubuntuone_installer/gui/qt/utils/tests/test_windows.py'
608--- ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-10-28 11:00:42 +0000
609+++ ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-11-11 19:41:25 +0000
610@@ -469,22 +469,6 @@
611 self.assertEqual(0, len(self.called_paths))
612
613
614-class FakeLogger(object):
615- """A Fake logging object."""
616-
617- def __init__(self):
618- """Create a new instance."""
619- self.called_methods = []
620-
621- def info(self, message, *args, **kwargs):
622- """Set an info log message."""
623- self.called_methods.append(('info', message, args, kwargs))
624-
625- def debug(self, message, *args, **kwargs):
626- """Set a debug log message."""
627- self.called_methods.append(('debug', message, args, kwargs))
628-
629-
630 class AutoupdaterTestCase(BaseTestCase):
631 """Test the code that is used for the auto update process."""
632
633@@ -503,7 +487,6 @@
634 self.args = args
635 return self.return_from_call
636
637- self.fake_logger = FakeLogger()
638 self.patch(utils.windows, 'getProcessValue', fake_execute_process)
639 self.patch(utils.windows, '_get_update_path',
640 lambda: self.auto_update_path)
641@@ -515,7 +498,7 @@
642 # the fake call, assert that we get true and also that
643 # we did use the correct parameters.
644 self.return_from_call = 0
645- are_present = yield utils.are_updates_present(self.fake_logger)
646+ are_present = yield utils.are_updates_present()
647 self.assertTrue(are_present, 'Updates should be present.')
648 # lets assert that we did use the correct args
649 expected_args = ('--mode', 'unattended')
650@@ -527,7 +510,7 @@
651 """Test when updates are not present."""
652 # similar to test_are_updates_present_true but with diff retcode
653 self.return_from_call = 40
654- are_present = yield utils.are_updates_present(self.fake_logger)
655+ are_present = yield utils.are_updates_present()
656 self.assertFalse(are_present, 'Updates should NOT be present.')
657 # lets assert that we did use the correct args
658 expected_args = ('--mode', 'unattended')
659@@ -557,10 +540,9 @@
660 yield super(CheckUpdatesTestCase, self).setUp()
661 self.are_present = False
662 self.user_wants_update = False
663- self.logger = FakeLogger()
664 self.called = []
665
666- def fake_are_present(logger):
667+ def fake_are_present():
668 """Fake are updates present."""
669 self.called.append('are_updates_present')
670 return self.are_present
671@@ -582,7 +564,7 @@
672 def test_check_updates_not_present(self):
673 """Test the method that interacts with the user."""
674 self.are_present = False
675- yield utils.check_updates(gui, self.logger)
676+ yield utils.check_updates(gui)
677 self.assertTrue('are_updates_present' in self.called)
678 self.assertFalse('perform_update' in self.called)
679
680@@ -591,7 +573,7 @@
681 """Test the method that interacts with the user."""
682 self.are_present = True
683 self.user_wants_update = False
684- yield utils.check_updates(gui, self.logger)
685+ yield utils.check_updates(gui)
686 self.assertTrue('are_updates_present' in self.called)
687 self.assertTrue('user_wants_to_update' in self.called)
688 self.assertFalse('perform_update' in self.called)
689@@ -601,69 +583,7 @@
690 """Test the method that interacts with the user."""
691 self.are_present = True
692 self.user_wants_update = True
693- yield utils.check_updates(gui, self.logger)
694+ yield utils.check_updates(gui)
695 self.assertTrue('are_updates_present' in self.called)
696 self.assertTrue('user_wants_to_update' in self.called)
697 self.assertTrue('perform_update' in self.called)
698-
699-
700-class FakeCredsManagementTool(object):
701- """Fake a creds management tool."""
702-
703- raise_error = False
704- credentials = None
705-
706- def __init__(self):
707- """Create a new instance."""
708-
709- def find_credentials(self):
710- """Fake find credentials."""
711- if FakeCredsManagementTool.raise_error:
712- return defer.fail(Exception('Test!'))
713- else:
714- return defer.succeed(FakeCredsManagementTool.credentials)
715-
716-
717-class CheckCredentialsTestCase(BaseTestCase):
718- """Test the code that is used to check the credentials."""
719-
720- @defer.inlineCallbacks
721- def setUp(self):
722- """Set the different tests."""
723- yield super(CheckCredentialsTestCase, self).setUp()
724- self.logger = FakeLogger()
725- self.called = []
726-
727- def success(creds, gui_ref, installing, logger, start_control_panel,
728- check_updates):
729- """Success cb."""
730- self.called.append(('success', creds, gui_ref, installing, logger,
731- start_control_panel, check_updates))
732-
733- def error(exc, logger):
734- """Error cb."""
735- self.called.append(('error', exc, logger))
736-
737- self.success_cb = success
738- self.error_cb = error
739- self.patch(utils.windows, 'CredentialsManagementTool',
740- FakeCredsManagementTool)
741-
742- @defer.inlineCallbacks
743- def test_check_credentials_not_present(self):
744- """Test when creds are not present."""
745- FakeCredsManagementTool.raise_error = True
746- yield utils.check_credentials(gui, self.logger, self.success_cb,
747- self.error_cb)
748- self.assertTrue('error' in self.called[0])
749-
750- @defer.inlineCallbacks
751- def test_check_credentials_present(self):
752- """Test when creds are present."""
753- FakeCredsManagementTool.raise_error = False
754- FakeCredsManagementTool.credentials = 'creds'
755- yield utils.check_credentials(gui, self.logger, self.success_cb,
756- self.error_cb)
757- self.assertTrue('success' in self.called[0])
758- self.assertEqual(FakeCredsManagementTool.credentials,
759- self.called[0][1])
760
761=== modified file 'ubuntuone_installer/gui/qt/utils/windows.py'
762--- ubuntuone_installer/gui/qt/utils/windows.py 2011-11-08 12:52:10 +0000
763+++ ubuntuone_installer/gui/qt/utils/windows.py 2011-11-11 19:41:25 +0000
764@@ -42,7 +42,10 @@
765 from ubuntuone.platform import tools
766 # pylint: enable=E0611
767
768-from ubuntuone.platform.credentials import CredentialsManagementTool
769+from ubuntuone_installer.logger import setup_logging
770+
771+
772+logger = setup_logging('qt.utils.windows')
773
774 AUTORUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run"
775
776@@ -102,22 +105,7 @@
777
778
779 @defer.inlineCallbacks
780-def check_credentials(gui, logger, success_cb, error_cb,
781- installer=False):
782- """Check credentials and either start u1cp or show the wizard."""
783- credtool = CredentialsManagementTool()
784- # pylint: disable=W0703
785- try:
786- creds = yield credtool.find_credentials()
787- except Exception, exc:
788- error_cb(exc, logger)
789- else:
790- yield success_cb(creds, gui, installer, logger, start_control_panel,
791- check_updates)
792-
793-
794-@defer.inlineCallbacks
795-def are_updates_present(logger):
796+def are_updates_present():
797 """Return if there are updates for Ubuntu One."""
798 update_path = _get_update_path()
799 logger.debug('Update path %s', update_path)
800@@ -145,12 +133,12 @@
801
802
803 @defer.inlineCallbacks
804-def check_updates(gui, logger):
805+def check_updates(gui):
806 """Check for updates."""
807 logger.info('Checking for updates.')
808 # the idea is simple, check if there are updates, ask user if we perform
809 # the update and continue.
810- are_present = yield are_updates_present(logger)
811+ are_present = yield are_updates_present()
812 logger.debug('Updates present: %r', are_updates_present)
813 if are_present:
814 logger.info('Updates are present.')

Subscribers

People subscribed via source and target branches