Merge lp:~ralsina/ubuntuone-windows-installer/no-credentials into lp:ubuntuone-windows-installer

Proposed by Roberto Alsina
Status: Merged
Approved by: Roberto Alsina
Approved revision: 45
Merged at revision: 41
Proposed branch: lp:~ralsina/ubuntuone-windows-installer/no-credentials
Merge into: lp:ubuntuone-windows-installer
Diff against target: 490 lines (+213/-125)
8 files modified
ubuntuone_installer/gui/qt/gui.py (+3/-31)
ubuntuone_installer/gui/qt/main/tests/test_windows.py (+128/-0)
ubuntuone_installer/gui/qt/main/windows.py (+54/-18)
ubuntuone_installer/gui/qt/tests/test_gui.py (+3/-73)
ubuntuone_installer/gui/qt/utils/__init__.py (+3/-1)
ubuntuone_installer/gui/qt/utils/linux.py (+6/-0)
ubuntuone_installer/gui/qt/utils/tests/test_windows.py (+1/-1)
ubuntuone_installer/gui/qt/utils/windows.py (+15/-1)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-windows-installer/no-credentials
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+72935@code.launchpad.net

Commit message

Start the control panel directly if the user already has credentials.

Description of the change

Start the control panel directly if the user already has credentials.

To post a comment you must log in.
44. By Roberto Alsina

solve merge conflict

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good!

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

"start_control_panel" function should be moved into "utils" (platform dependent) module as the uninstall function, because both are checking if sys.platform == "win32".

review: Needs Fixing
45. By Roberto Alsina

refactored as suggested by diego

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

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ubuntuone_installer/gui/qt/gui.py'
--- ubuntuone_installer/gui/qt/gui.py 2011-08-23 17:43:40 +0000
+++ ubuntuone_installer/gui/qt/gui.py 2011-08-29 12:42:23 +0000
@@ -59,7 +59,6 @@
5959
60from ubuntuone.platform.credentials import (60from ubuntuone.platform.credentials import (
61 APP_NAME,61 APP_NAME,
62 CredentialsManagementTool,
63 TC_URL,62 TC_URL,
64)63)
6564
@@ -90,6 +89,7 @@
90TITLE_STYLE = "<span style=\"font-size:24px\">%s</span>"89TITLE_STYLE = "<span style=\"font-size:24px\">%s</span>"
91CREDENTIALS_ERROR_TITLE = _("Error getting credentials")90CREDENTIALS_ERROR_TITLE = _("Error getting credentials")
92CREDENTIALS_ERROR = _('Application will close.\n\n%r')91CREDENTIALS_ERROR = _('Application will close.\n\n%r')
92STARTING_CP_ERROR = _('Error starting Ubuntu One')
93# Invalid name logger93# Invalid name logger
94# pylint: disable=C010394# pylint: disable=C0103
95logger = setup_logging('qt.gui')95logger = setup_logging('qt.gui')
@@ -291,6 +291,7 @@
291291
292 self.setSideWidget(SideWidget())292 self.setSideWidget(SideWidget())
293 self.overlay = LoadingOverlay(self)293 self.overlay = LoadingOverlay(self)
294 self.overlay.hide()
294295
295 self.setOption(self.NoBackButtonOnStartPage, True)296 self.setOption(self.NoBackButtonOnStartPage, True)
296297
@@ -388,30 +389,9 @@
388 # Set Wizard buttons style389 # Set Wizard buttons style
389 self.button(QtGui.QWizard.NextButton).setDefault(True)390 self.button(QtGui.QWizard.NextButton).setDefault(True)
390391
391 credtool = CredentialsManagementTool()
392 d = credtool.find_credentials()
393 d.addCallback(self.creds_cb)
394 d.addErrback(self.creds_eb)
395
396 # Invalid name "closeEvent"392 # Invalid name "closeEvent"
397 # pylint: disable=C0103393 # pylint: disable=C0103
398394
399 def creds_eb(self, exc):
400 """Handle credentials error."""
401 self.LICENSE_PAGE._next_id = self.SIGNIN_PAGE
402 self.critical(CREDENTIALS_ERROR % exc.value)
403 logger.error(
404 'Error while getting the credentials: %r', exc.value)
405 self.close()
406
407 def creds_cb(self, token):
408 """Change wizard flow if we have credentials."""
409 self.overlay.hide()
410 if not token:
411 self.LICENSE_PAGE._next_id = self.SIGNIN_PAGE
412 else:
413 self.LICENSE_PAGE._next_id = self.local_folders_page_id
414
415 def critical(self, message):395 def critical(self, message):
416 """Show a message at the bottom of the page on form errors."""396 """Show a message at the bottom of the page on form errors."""
417 self.overlay.hide()397 self.overlay.hide()
@@ -451,15 +431,7 @@
451 """The main window is being closed, call any custom callback."""431 """The main window is being closed, call any custom callback."""
452 # Finished, not cancelled432 # Finished, not cancelled
453 if result == 1: # Cancelled433 if result == 1: # Cancelled
454 # If we are in windows and "frozen", assume it's in434 utils.start_control_panel()
455 # the same folder as this .exe
456 if sys.platform == "win32" and hasattr(sys, "frozen"):
457 cp_path = os.path.join(os.path.dirname(
458 os.path.abspath(sys.executable)),
459 "ubuntuone-control-panel-qt.exe")
460 else:
461 cp_path = "ubuntuone-control-panel-qt"
462 subprocess.Popen([cp_path, ])
463 elif self.currentId() == self.LICENSE_PAGE_ID:435 elif self.currentId() == self.LICENSE_PAGE_ID:
464 if not AreYouSure(self).exec_():436 if not AreYouSure(self).exec_():
465 utils.uninstall_application()437 utils.uninstall_application()
466438
=== added file 'ubuntuone_installer/gui/qt/main/tests/test_windows.py'
--- ubuntuone_installer/gui/qt/main/tests/test_windows.py 1970-01-01 00:00:00 +0000
+++ ubuntuone_installer/gui/qt/main/tests/test_windows.py 2011-08-29 12:42:23 +0000
@@ -0,0 +1,128 @@
1# -*- coding: utf-8 -*-
2
3# Authors: Alejandro J. Cura <alecu@canonical.com>
4# Roberto Alsina <roberto.alsina@canonical.com>
5#
6# Copyright 2011 Canonical Ltd.
7#
8# This program is free software: you can redistribute it and/or modify it
9# under the terms of the GNU General Public License version 3, as published
10# by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranties of
14# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15# PURPOSE. See the GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program. If not, see <http://www.gnu.org/licenses/>.
19
20"""Tests for the Windows main."""
21
22from twisted.internet import defer
23
24from ubuntuone_installer.gui.qt import gui, utils
25from ubuntuone_installer.gui.qt.main import windows
26from ubuntuone_installer.gui.qt.tests.test_gui import FakeMainWindow
27from ubuntuone_installer.tests import TestCase
28
29
30class FakeFailingCredentialsManagementTool(object):
31
32 """A fake CredentialsManagementTool that fails."""
33
34 def find_credentials(self):
35 """Return a failure."""
36 return defer.fail(Exception())
37
38
39class FakeNoCredentialsManagementTool(object):
40
41 """A fake CredentialsManagementTool that fakes no credentials."""
42
43 def find_credentials(self):
44 """Return a success, but no credentials."""
45 return defer.succeed({})
46
47
48class FakeCredentialsManagementTool(object):
49
50 """A fake CredentialsManagementTool that fakes credentials."""
51
52 def find_credentials(self):
53 """Return a success, but no credentials."""
54 return defer.succeed("Something not false")
55
56
57class FakeLogger(object):
58
59 """Fake Logger."""
60
61 error_args = None
62
63 def error(self, *args, **kwargs):
64 """Save the error."""
65 self.error_args = (args, kwargs)
66
67
68class CredsFailureMainTestCase(TestCase):
69
70 """Test the qt main window."""
71
72 stopped = False
73
74 def stop(self):
75 """A fake stop."""
76 self.stopped = True
77
78 @defer.inlineCallbacks
79 def test_failure(self):
80 """Credential errors should display a critical message."""
81 logger = FakeLogger()
82 self.patch(windows, 'stop', self.stop)
83 self.stopped = False
84 yield windows.check_credentials(
85 FakeFailingCredentialsManagementTool,
86 gui, logger)
87 # Should log the error
88 self.assertEqual(logger.error_args[0][0],
89 ('Error while getting the credentials: %r'))
90 # Should stop the app
91 self.assertTrue(self.stopped)
92
93 @defer.inlineCallbacks
94 def test_no_creds(self):
95 """No credentials should start the wizard."""
96 logger = FakeLogger()
97 fakemain = FakeMainWindow()
98 self.patch(gui, 'MainWindow', lambda *args, **kwargs: fakemain)
99 self.patch(windows, 'stop', self._set_called)
100 self.assertFalse(fakemain.shown)
101 self.patch(windows, 'stop', self.stop)
102 self.stopped = False
103 yield windows.check_credentials(
104 FakeNoCredentialsManagementTool,
105 gui, logger)
106 # Should show the main window
107 self.assertTrue(fakemain.shown)
108 # Should not log errors
109 self.assertEqual(logger.error_args, None)
110 # Should not stop the app
111 self.assertFalse(self.stopped)
112
113 @defer.inlineCallbacks
114 def test_with_creds(self):
115 """Having credentials should start the control panel."""
116 logger = FakeLogger()
117 self.patch(utils, 'start_control_panel', self._set_called)
118 self.patch(windows, 'stop', self.stop)
119 self.stopped = False
120 yield windows.check_credentials(
121 FakeCredentialsManagementTool,
122 gui, logger)
123 # Should not log errors
124 self.assertEqual(logger.error_args, None)
125 # Should start u1cp
126 self.assertEqual(self._called, ((), {}))
127 # Should stop the app
128 self.assertTrue(self.stopped)
0129
=== modified file 'ubuntuone_installer/gui/qt/main/windows.py'
--- ubuntuone_installer/gui/qt/main/windows.py 2011-08-12 01:07:04 +0000
+++ ubuntuone_installer/gui/qt/main/windows.py 2011-08-29 12:42:23 +0000
@@ -21,8 +21,8 @@
2121
22import sys22import sys
2323
24from PyQt4 import QtGui24from PyQt4 import QtGui, QtCore
25from PyQt4 import QtCore25from twisted.internet import defer
2626
27# Module used to include the resources into this file27# Module used to include the resources into this file
28# pylint: disable=W061128# pylint: disable=W0611
@@ -36,26 +36,62 @@
36 reactor.stop()36 reactor.stop()
3737
3838
39def error_cb(exc, logger):
40 """Handle credentials errors."""
41 logger.error(
42 'Error while getting the credentials: %r', exc)
43 stop()
44
45
46def success_cb(creds, gui):
47 """Handle credentials success."""
48 if creds: # Have credentials already
49 try:
50 gui.utils.start_control_panel()
51 except OSError:
52 QtGui.QMessageBox.critical(
53 None, "Ubuntu One", gui.STARTING_CP_ERROR)
54 stop()
55 else: # No credentials
56 window = gui.MainWindow(close_callback=stop)
57 # Set Application Style Sheet
58 app = QtGui.QApplication.instance()
59 qss = QtCore.QResource(":/ubuntuone.qss")
60 app.setStyleSheet(QtCore.QString(qss.data()))
61 # Apply font to the entire application
62 QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-R.ttf')
63 QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-B.ttf')
64 # Set Application Icon
65 app.setWindowIcon(QtGui.QIcon(":/ubuntu_one_favicon.png"))
66 window.show()
67
68
69@defer.inlineCallbacks
70def check_credentials(credentials_tool, gui, logger):
71 """Check credentials and either start u1cp or show the wizard."""
72 credtool = credentials_tool()
73 # pylint: disable=W0703
74 try:
75 creds = yield credtool.find_credentials()
76 except Exception, exc:
77 error_cb(exc, logger)
78 else:
79 success_cb(creds, gui)
80
81
39def main():82def main():
40 """Perform a client request to be logged in."""83 """Perform a client request to be logged in."""
4184 # pylint: disable=W0612
42 app = QtGui.QApplication(sys.argv)85 app = QtGui.QApplication(sys.argv)
86 # pylint: enable=W0612
43 import qtreactor.qt4reactor87 import qtreactor.qt4reactor
44 qtreactor.qt4reactor.install()88 qtreactor.qt4reactor.install()
45 from ubuntuone_installer.gui.qt.gui import MainWindow89 from ubuntuone_installer.gui.qt import gui, utils
46 from twisted.internet import reactor90 from twisted.internet import reactor
47 window = MainWindow(close_callback=stop)91 # All this has to be imported here because it installs a reactor
48 app.window = window92 from ubuntuone.platform.credentials import CredentialsManagementTool
4993 from ubuntuone_installer.logger import setup_logging
50 # Set Application Style Sheet94 logger = setup_logging('qt.gui')
51 app = QtGui.QApplication.instance()95
52 qss = QtCore.QResource(":/ubuntuone.qss")96 check_credentials(CredentialsManagementTool, gui, logger)
53 app.setStyleSheet(QtCore.QString(qss.data()))
54 # Apply font to the entire application
55 QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-R.ttf')
56 QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-B.ttf')
57 # Set Application Icon
58 app.setWindowIcon(QtGui.QIcon(":/ubuntu_one_favicon.png"))
59
60 window.show()
61 reactor.run()97 reactor.run()
6298
=== modified file 'ubuntuone_installer/gui/qt/tests/test_gui.py'
--- ubuntuone_installer/gui/qt/tests/test_gui.py 2011-08-26 12:24:48 +0000
+++ ubuntuone_installer/gui/qt/tests/test_gui.py 2011-08-29 12:42:23 +0000
@@ -31,22 +31,6 @@
31from ubuntuone_installer.gui.qt.tests import BaseTestCase31from ubuntuone_installer.gui.qt.tests import BaseTestCase
3232
3333
34TOKEN = {u'consumer_key': u'xQ7xDAz',
35 u'consumer_secret': u'KzCJWCTNbbntwfyCKKjomJDzlgqxLy',
36 u'token_name': u'test',
37 u'token': u'GkInOfSMGwTXAUoVQwLUoPxElEEUdhsLVNTPhxHJDUIeHCPNEo',
38 u'token_secret': u'qFYImEtlczPbsCnYyuwLoPDlPEnvNcIktZphPQklAWrvyfFMV'}
39
40
41class FakeFailureCredentialsManagementTool(object):
42
43 """A fake CredentialsManagementTool that fails."""
44
45 def find_credentials(self):
46 """Return a deferred that never triggers callback."""
47 return defer.succeed({})
48
49
50class FakeController(object):34class FakeController(object):
5135
52 """A fake controller for the tests."""36 """A fake controller for the tests."""
@@ -165,8 +149,6 @@
165 self.patch(gui, "LocalFoldersPage", FakeLocalFoldersPage)149 self.patch(gui, "LocalFoldersPage", FakeLocalFoldersPage)
166 self.patch(qt.preferences, "PreferencesPanel", FakePreferencesPanel)150 self.patch(qt.preferences, "PreferencesPanel", FakePreferencesPanel)
167 self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel)151 self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel)
168 self.patch(gui, "CredentialsManagementTool",
169 FakeFailureCredentialsManagementTool)
170 super(MainWindowTestCase, self).setUp()152 super(MainWindowTestCase, self).setUp()
171153
172 def test_execute_uninstall_on_licence_cancel(self):154 def test_execute_uninstall_on_licence_cancel(self):
@@ -566,17 +548,6 @@
566 QtCore.QCoreApplication.instance().processEvents()548 QtCore.QCoreApplication.instance().processEvents()
567 self.assertEqual(self.ui.result(), self.ui.Rejected)549 self.assertEqual(self.ui.result(), self.ui.Rejected)
568550
569 def test_license_next(self):
570 """Test what's the license page's nextID."""
571 self.ui.creds_cb("fakecreds")
572 self.assertEqual(self.ui.LICENSE_PAGE.nextId(),
573 self.ui.local_folders_page_id)
574
575 def test_license_next_default(self):
576 """By default, should be the sign in page."""
577 self.assertEqual(self.ui.LICENSE_PAGE.nextId(),
578 self.ui.SIGNIN_PAGE)
579
580551
581class FakeSignal(object):552class FakeSignal(object):
582553
@@ -604,50 +575,9 @@
604 userCancellation = FakeSignal()575 userCancellation = FakeSignal()
605 shown = False576 shown = False
606577
578 def __init__(self, close_callback=None):
579 pass
580
607 def show(self):581 def show(self):
608 """Fake method."""582 """Fake method."""
609 self.shown = True583 self.shown = True
610
611
612class FakeFailingCredentialsManagementTool(object):
613
614 """A fake CredentialsManagementTool that fails."""
615
616 def find_credentials(self):
617 """Return a deferred that never triggers callback."""
618 return defer.fail(Exception())
619
620
621class CredsFailureMainWindowTestCase(BaseTestCase):
622 """Test the qt main window."""
623
624 class_ui = gui.MainWindow
625
626 def setUp(self):
627 """Initialize this test instance."""
628 # Faking each SSO object instead of doing it lower
629 # so we don't rely on any SSO behaviour
630 self.patch(gui, "SetUpAccountController", FakeController)
631 self.patch(gui, "TosController", FakeController)
632 self.patch(gui, "EmailVerificationController", FakeController)
633 self.patch(gui, "CurrentUserController", FakeController)
634 self.patch(gui, "SuccessController", FakeController)
635 self.patch(gui, "ForgottenPasswordController", FakeController)
636 self.patch(gui, "ResetPasswordController", FakeController)
637 self.patch(gui, "AreYouSure", FakeAreYouSure)
638 self.patch(gui, "LoadingOverlay", FakeOverlay)
639 self.patch(gui, "LocalFoldersPage", FakeLocalFoldersPage)
640 self.patch(qt.preferences, "PreferencesPanel", FakePreferencesPanel)
641 self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel)
642 self.patch(gui, "CredentialsManagementTool",
643 FakeFailingCredentialsManagementTool)
644 super(CredsFailureMainWindowTestCase, self).setUp()
645
646 def test_overlay_hiding(self):
647 """Credential errors should make the overlay hide."""
648 self.assertEqual(self.ui.overlay.hide_counter, 1)
649
650 def test_critical(self):
651 """Credential errors should display a critical message."""
652 self.assertEqual(self.ui.form_errors_label.text(),
653 "Application will close.\n\nException()")
654584
=== modified file 'ubuntuone_installer/gui/qt/utils/__init__.py'
--- ubuntuone_installer/gui/qt/utils/__init__.py 2011-08-23 17:27:56 +0000
+++ ubuntuone_installer/gui/qt/utils/__init__.py 2011-08-29 12:42:23 +0000
@@ -21,10 +21,12 @@
2121
22import sys22import sys
2323
2424# pylint: disable=C0103
25if sys.platform == 'win32':25if sys.platform == 'win32':
26 from ubuntuone_installer.gui.qt.utils import windows26 from ubuntuone_installer.gui.qt.utils import windows
27 uninstall_application = windows.uninstall_application27 uninstall_application = windows.uninstall_application
28 start_control_panel = windows.start_control_panel
28else:29else:
29 from ubuntuone_installer.gui.qt.utils import linux30 from ubuntuone_installer.gui.qt.utils import linux
30 uninstall_application = linux.uninstall_application31 uninstall_application = linux.uninstall_application
32 start_control_panel = linux.start_control_panel
3133
=== modified file 'ubuntuone_installer/gui/qt/utils/linux.py'
--- ubuntuone_installer/gui/qt/utils/linux.py 2011-08-23 17:27:56 +0000
+++ ubuntuone_installer/gui/qt/utils/linux.py 2011-08-29 12:42:23 +0000
@@ -18,7 +18,13 @@
1818
19"""Utils Functions Linux specific."""19"""Utils Functions Linux specific."""
2020
21import subprocess
2122
22def uninstall_application():23def uninstall_application():
23 """Uninstall Ubuntu One."""24 """Uninstall Ubuntu One."""
24 pass25 pass
26
27
28def start_control_panel():
29 """Start the control panel."""
30 subprocess.Popen(["ubuntuone-control-panel-qt", ])
2531
=== modified file 'ubuntuone_installer/gui/qt/utils/tests/test_windows.py'
--- ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-08-26 18:41:33 +0000
+++ ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-08-29 12:42:23 +0000
@@ -54,6 +54,6 @@
54 self.assertTrue(self._called[0][0] is None)54 self.assertTrue(self._called[0][0] is None)
55 self.assertTrue("uninstall.exe" in self._called[0][2])55 self.assertTrue("uninstall.exe" in self._called[0][2])
56 self.assertTrue('runas' == self._called[0][1])56 self.assertTrue('runas' == self._called[0][1])
57 self.assertTrue('--mode=qt' == self._called[0][3])57 self.assertTrue('--mode qt' == self._called[0][3])
58 self.assertTrue('' == self._called[0][4])58 self.assertTrue('' == self._called[0][4])
59 self.assertTrue(0 == self._called[0][5])59 self.assertTrue(0 == self._called[0][5])
6060
=== modified file 'ubuntuone_installer/gui/qt/utils/windows.py'
--- ubuntuone_installer/gui/qt/utils/windows.py 2011-08-26 18:41:33 +0000
+++ ubuntuone_installer/gui/qt/utils/windows.py 2011-08-29 12:42:23 +0000
@@ -19,8 +19,9 @@
19"""Utils Functions Windows specific."""19"""Utils Functions Windows specific."""
2020
2121
22import os
23import subprocess
22import sys24import sys
23import os
2425
25import win32api26import win32api
2627
@@ -36,3 +37,16 @@
36 win32api.ShellExecute(None, 'runas',37 win32api.ShellExecute(None, 'runas',
37 uninstall_path,38 uninstall_path,
38 '--mode qt', '', 0)39 '--mode qt', '', 0)
40
41
42def start_control_panel():
43 """Start the control panel."""
44 # If we are in windows and "frozen", assume it's in
45 # the same folder as this .exe
46 if sys.platform == "win32" and hasattr(sys, "frozen"):
47 cp_path = os.path.join(os.path.dirname(
48 os.path.abspath(sys.executable)),
49 "ubuntuone-control-panel-qt.exe")
50 else:
51 cp_path = "ubuntuone-control-panel-qt"
52 subprocess.Popen([cp_path, ])

Subscribers

People subscribed via source and target branches