Merge lp:~ralsina/ubuntuone-windows-installer/no-credentials into lp:ubuntuone-windows-installer
- no-credentials
- Merge into trunk
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 | ||||
Related bugs: |
|
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
Diego Sarmentero (diegosarmentero) wrote : | # |
"start_
review:
Needs Fixing
- 45. By Roberto Alsina
-
refactored as suggested by diego
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ubuntuone_installer/gui/qt/gui.py' | |||
2 | --- ubuntuone_installer/gui/qt/gui.py 2011-08-23 17:43:40 +0000 | |||
3 | +++ ubuntuone_installer/gui/qt/gui.py 2011-08-29 12:42:23 +0000 | |||
4 | @@ -59,7 +59,6 @@ | |||
5 | 59 | 59 | ||
6 | 60 | from ubuntuone.platform.credentials import ( | 60 | from ubuntuone.platform.credentials import ( |
7 | 61 | APP_NAME, | 61 | APP_NAME, |
8 | 62 | CredentialsManagementTool, | ||
9 | 63 | TC_URL, | 62 | TC_URL, |
10 | 64 | ) | 63 | ) |
11 | 65 | 64 | ||
12 | @@ -90,6 +89,7 @@ | |||
13 | 90 | TITLE_STYLE = "<span style=\"font-size:24px\">%s</span>" | 89 | TITLE_STYLE = "<span style=\"font-size:24px\">%s</span>" |
14 | 91 | CREDENTIALS_ERROR_TITLE = _("Error getting credentials") | 90 | CREDENTIALS_ERROR_TITLE = _("Error getting credentials") |
15 | 92 | CREDENTIALS_ERROR = _('Application will close.\n\n%r') | 91 | CREDENTIALS_ERROR = _('Application will close.\n\n%r') |
16 | 92 | STARTING_CP_ERROR = _('Error starting Ubuntu One') | ||
17 | 93 | # Invalid name logger | 93 | # Invalid name logger |
18 | 94 | # pylint: disable=C0103 | 94 | # pylint: disable=C0103 |
19 | 95 | logger = setup_logging('qt.gui') | 95 | logger = setup_logging('qt.gui') |
20 | @@ -291,6 +291,7 @@ | |||
21 | 291 | 291 | ||
22 | 292 | self.setSideWidget(SideWidget()) | 292 | self.setSideWidget(SideWidget()) |
23 | 293 | self.overlay = LoadingOverlay(self) | 293 | self.overlay = LoadingOverlay(self) |
24 | 294 | self.overlay.hide() | ||
25 | 294 | 295 | ||
26 | 295 | self.setOption(self.NoBackButtonOnStartPage, True) | 296 | self.setOption(self.NoBackButtonOnStartPage, True) |
27 | 296 | 297 | ||
28 | @@ -388,30 +389,9 @@ | |||
29 | 388 | # Set Wizard buttons style | 389 | # Set Wizard buttons style |
30 | 389 | self.button(QtGui.QWizard.NextButton).setDefault(True) | 390 | self.button(QtGui.QWizard.NextButton).setDefault(True) |
31 | 390 | 391 | ||
32 | 391 | credtool = CredentialsManagementTool() | ||
33 | 392 | d = credtool.find_credentials() | ||
34 | 393 | d.addCallback(self.creds_cb) | ||
35 | 394 | d.addErrback(self.creds_eb) | ||
36 | 395 | |||
37 | 396 | # Invalid name "closeEvent" | 392 | # Invalid name "closeEvent" |
38 | 397 | # pylint: disable=C0103 | 393 | # pylint: disable=C0103 |
39 | 398 | 394 | ||
40 | 399 | def creds_eb(self, exc): | ||
41 | 400 | """Handle credentials error.""" | ||
42 | 401 | self.LICENSE_PAGE._next_id = self.SIGNIN_PAGE | ||
43 | 402 | self.critical(CREDENTIALS_ERROR % exc.value) | ||
44 | 403 | logger.error( | ||
45 | 404 | 'Error while getting the credentials: %r', exc.value) | ||
46 | 405 | self.close() | ||
47 | 406 | |||
48 | 407 | def creds_cb(self, token): | ||
49 | 408 | """Change wizard flow if we have credentials.""" | ||
50 | 409 | self.overlay.hide() | ||
51 | 410 | if not token: | ||
52 | 411 | self.LICENSE_PAGE._next_id = self.SIGNIN_PAGE | ||
53 | 412 | else: | ||
54 | 413 | self.LICENSE_PAGE._next_id = self.local_folders_page_id | ||
55 | 414 | |||
56 | 415 | def critical(self, message): | 395 | def critical(self, message): |
57 | 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.""" |
58 | 417 | self.overlay.hide() | 397 | self.overlay.hide() |
59 | @@ -451,15 +431,7 @@ | |||
60 | 451 | """The main window is being closed, call any custom callback.""" | 431 | """The main window is being closed, call any custom callback.""" |
61 | 452 | # Finished, not cancelled | 432 | # Finished, not cancelled |
62 | 453 | if result == 1: # Cancelled | 433 | if result == 1: # Cancelled |
72 | 454 | # If we are in windows and "frozen", assume it's in | 434 | utils.start_control_panel() |
64 | 455 | # the same folder as this .exe | ||
65 | 456 | if sys.platform == "win32" and hasattr(sys, "frozen"): | ||
66 | 457 | cp_path = os.path.join(os.path.dirname( | ||
67 | 458 | os.path.abspath(sys.executable)), | ||
68 | 459 | "ubuntuone-control-panel-qt.exe") | ||
69 | 460 | else: | ||
70 | 461 | cp_path = "ubuntuone-control-panel-qt" | ||
71 | 462 | subprocess.Popen([cp_path, ]) | ||
73 | 463 | elif self.currentId() == self.LICENSE_PAGE_ID: | 435 | elif self.currentId() == self.LICENSE_PAGE_ID: |
74 | 464 | if not AreYouSure(self).exec_(): | 436 | if not AreYouSure(self).exec_(): |
75 | 465 | utils.uninstall_application() | 437 | utils.uninstall_application() |
76 | 466 | 438 | ||
77 | === added file 'ubuntuone_installer/gui/qt/main/tests/test_windows.py' | |||
78 | --- ubuntuone_installer/gui/qt/main/tests/test_windows.py 1970-01-01 00:00:00 +0000 | |||
79 | +++ ubuntuone_installer/gui/qt/main/tests/test_windows.py 2011-08-29 12:42:23 +0000 | |||
80 | @@ -0,0 +1,128 @@ | |||
81 | 1 | # -*- coding: utf-8 -*- | ||
82 | 2 | |||
83 | 3 | # Authors: Alejandro J. Cura <alecu@canonical.com> | ||
84 | 4 | # Roberto Alsina <roberto.alsina@canonical.com> | ||
85 | 5 | # | ||
86 | 6 | # Copyright 2011 Canonical Ltd. | ||
87 | 7 | # | ||
88 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
89 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
90 | 10 | # by the Free Software Foundation. | ||
91 | 11 | # | ||
92 | 12 | # This program is distributed in the hope that it will be useful, but | ||
93 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
94 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
95 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
96 | 16 | # | ||
97 | 17 | # You should have received a copy of the GNU General Public License along | ||
98 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
99 | 19 | |||
100 | 20 | """Tests for the Windows main.""" | ||
101 | 21 | |||
102 | 22 | from twisted.internet import defer | ||
103 | 23 | |||
104 | 24 | from ubuntuone_installer.gui.qt import gui, utils | ||
105 | 25 | from ubuntuone_installer.gui.qt.main import windows | ||
106 | 26 | from ubuntuone_installer.gui.qt.tests.test_gui import FakeMainWindow | ||
107 | 27 | from ubuntuone_installer.tests import TestCase | ||
108 | 28 | |||
109 | 29 | |||
110 | 30 | class FakeFailingCredentialsManagementTool(object): | ||
111 | 31 | |||
112 | 32 | """A fake CredentialsManagementTool that fails.""" | ||
113 | 33 | |||
114 | 34 | def find_credentials(self): | ||
115 | 35 | """Return a failure.""" | ||
116 | 36 | return defer.fail(Exception()) | ||
117 | 37 | |||
118 | 38 | |||
119 | 39 | class FakeNoCredentialsManagementTool(object): | ||
120 | 40 | |||
121 | 41 | """A fake CredentialsManagementTool that fakes no credentials.""" | ||
122 | 42 | |||
123 | 43 | def find_credentials(self): | ||
124 | 44 | """Return a success, but no credentials.""" | ||
125 | 45 | return defer.succeed({}) | ||
126 | 46 | |||
127 | 47 | |||
128 | 48 | class FakeCredentialsManagementTool(object): | ||
129 | 49 | |||
130 | 50 | """A fake CredentialsManagementTool that fakes credentials.""" | ||
131 | 51 | |||
132 | 52 | def find_credentials(self): | ||
133 | 53 | """Return a success, but no credentials.""" | ||
134 | 54 | return defer.succeed("Something not false") | ||
135 | 55 | |||
136 | 56 | |||
137 | 57 | class FakeLogger(object): | ||
138 | 58 | |||
139 | 59 | """Fake Logger.""" | ||
140 | 60 | |||
141 | 61 | error_args = None | ||
142 | 62 | |||
143 | 63 | def error(self, *args, **kwargs): | ||
144 | 64 | """Save the error.""" | ||
145 | 65 | self.error_args = (args, kwargs) | ||
146 | 66 | |||
147 | 67 | |||
148 | 68 | class CredsFailureMainTestCase(TestCase): | ||
149 | 69 | |||
150 | 70 | """Test the qt main window.""" | ||
151 | 71 | |||
152 | 72 | stopped = False | ||
153 | 73 | |||
154 | 74 | def stop(self): | ||
155 | 75 | """A fake stop.""" | ||
156 | 76 | self.stopped = True | ||
157 | 77 | |||
158 | 78 | @defer.inlineCallbacks | ||
159 | 79 | def test_failure(self): | ||
160 | 80 | """Credential errors should display a critical message.""" | ||
161 | 81 | logger = FakeLogger() | ||
162 | 82 | self.patch(windows, 'stop', self.stop) | ||
163 | 83 | self.stopped = False | ||
164 | 84 | yield windows.check_credentials( | ||
165 | 85 | FakeFailingCredentialsManagementTool, | ||
166 | 86 | gui, logger) | ||
167 | 87 | # Should log the error | ||
168 | 88 | self.assertEqual(logger.error_args[0][0], | ||
169 | 89 | ('Error while getting the credentials: %r')) | ||
170 | 90 | # Should stop the app | ||
171 | 91 | self.assertTrue(self.stopped) | ||
172 | 92 | |||
173 | 93 | @defer.inlineCallbacks | ||
174 | 94 | def test_no_creds(self): | ||
175 | 95 | """No credentials should start the wizard.""" | ||
176 | 96 | logger = FakeLogger() | ||
177 | 97 | fakemain = FakeMainWindow() | ||
178 | 98 | self.patch(gui, 'MainWindow', lambda *args, **kwargs: fakemain) | ||
179 | 99 | self.patch(windows, 'stop', self._set_called) | ||
180 | 100 | self.assertFalse(fakemain.shown) | ||
181 | 101 | self.patch(windows, 'stop', self.stop) | ||
182 | 102 | self.stopped = False | ||
183 | 103 | yield windows.check_credentials( | ||
184 | 104 | FakeNoCredentialsManagementTool, | ||
185 | 105 | gui, logger) | ||
186 | 106 | # Should show the main window | ||
187 | 107 | self.assertTrue(fakemain.shown) | ||
188 | 108 | # Should not log errors | ||
189 | 109 | self.assertEqual(logger.error_args, None) | ||
190 | 110 | # Should not stop the app | ||
191 | 111 | self.assertFalse(self.stopped) | ||
192 | 112 | |||
193 | 113 | @defer.inlineCallbacks | ||
194 | 114 | def test_with_creds(self): | ||
195 | 115 | """Having credentials should start the control panel.""" | ||
196 | 116 | logger = FakeLogger() | ||
197 | 117 | self.patch(utils, 'start_control_panel', self._set_called) | ||
198 | 118 | self.patch(windows, 'stop', self.stop) | ||
199 | 119 | self.stopped = False | ||
200 | 120 | yield windows.check_credentials( | ||
201 | 121 | FakeCredentialsManagementTool, | ||
202 | 122 | gui, logger) | ||
203 | 123 | # Should not log errors | ||
204 | 124 | self.assertEqual(logger.error_args, None) | ||
205 | 125 | # Should start u1cp | ||
206 | 126 | self.assertEqual(self._called, ((), {})) | ||
207 | 127 | # Should stop the app | ||
208 | 128 | self.assertTrue(self.stopped) | ||
209 | 0 | 129 | ||
210 | === modified file 'ubuntuone_installer/gui/qt/main/windows.py' | |||
211 | --- ubuntuone_installer/gui/qt/main/windows.py 2011-08-12 01:07:04 +0000 | |||
212 | +++ ubuntuone_installer/gui/qt/main/windows.py 2011-08-29 12:42:23 +0000 | |||
213 | @@ -21,8 +21,8 @@ | |||
214 | 21 | 21 | ||
215 | 22 | import sys | 22 | import sys |
216 | 23 | 23 | ||
219 | 24 | from PyQt4 import QtGui | 24 | from PyQt4 import QtGui, QtCore |
220 | 25 | from PyQt4 import QtCore | 25 | from twisted.internet import defer |
221 | 26 | 26 | ||
222 | 27 | # Module used to include the resources into this file | 27 | # Module used to include the resources into this file |
223 | 28 | # pylint: disable=W0611 | 28 | # pylint: disable=W0611 |
224 | @@ -36,26 +36,62 @@ | |||
225 | 36 | reactor.stop() | 36 | reactor.stop() |
226 | 37 | 37 | ||
227 | 38 | 38 | ||
228 | 39 | def error_cb(exc, logger): | ||
229 | 40 | """Handle credentials errors.""" | ||
230 | 41 | logger.error( | ||
231 | 42 | 'Error while getting the credentials: %r', exc) | ||
232 | 43 | stop() | ||
233 | 44 | |||
234 | 45 | |||
235 | 46 | def success_cb(creds, gui): | ||
236 | 47 | """Handle credentials success.""" | ||
237 | 48 | if creds: # Have credentials already | ||
238 | 49 | try: | ||
239 | 50 | gui.utils.start_control_panel() | ||
240 | 51 | except OSError: | ||
241 | 52 | QtGui.QMessageBox.critical( | ||
242 | 53 | None, "Ubuntu One", gui.STARTING_CP_ERROR) | ||
243 | 54 | stop() | ||
244 | 55 | else: # No credentials | ||
245 | 56 | window = gui.MainWindow(close_callback=stop) | ||
246 | 57 | # Set Application Style Sheet | ||
247 | 58 | app = QtGui.QApplication.instance() | ||
248 | 59 | qss = QtCore.QResource(":/ubuntuone.qss") | ||
249 | 60 | app.setStyleSheet(QtCore.QString(qss.data())) | ||
250 | 61 | # Apply font to the entire application | ||
251 | 62 | QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-R.ttf') | ||
252 | 63 | QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-B.ttf') | ||
253 | 64 | # Set Application Icon | ||
254 | 65 | app.setWindowIcon(QtGui.QIcon(":/ubuntu_one_favicon.png")) | ||
255 | 66 | window.show() | ||
256 | 67 | |||
257 | 68 | |||
258 | 69 | @defer.inlineCallbacks | ||
259 | 70 | def check_credentials(credentials_tool, gui, logger): | ||
260 | 71 | """Check credentials and either start u1cp or show the wizard.""" | ||
261 | 72 | credtool = credentials_tool() | ||
262 | 73 | # pylint: disable=W0703 | ||
263 | 74 | try: | ||
264 | 75 | creds = yield credtool.find_credentials() | ||
265 | 76 | except Exception, exc: | ||
266 | 77 | error_cb(exc, logger) | ||
267 | 78 | else: | ||
268 | 79 | success_cb(creds, gui) | ||
269 | 80 | |||
270 | 81 | |||
271 | 39 | def main(): | 82 | def main(): |
272 | 40 | """Perform a client request to be logged in.""" | 83 | """Perform a client request to be logged in.""" |
274 | 41 | 84 | # pylint: disable=W0612 | |
275 | 42 | app = QtGui.QApplication(sys.argv) | 85 | app = QtGui.QApplication(sys.argv) |
276 | 86 | # pylint: enable=W0612 | ||
277 | 43 | import qtreactor.qt4reactor | 87 | import qtreactor.qt4reactor |
278 | 44 | qtreactor.qt4reactor.install() | 88 | qtreactor.qt4reactor.install() |
280 | 45 | from ubuntuone_installer.gui.qt.gui import MainWindow | 89 | from ubuntuone_installer.gui.qt import gui, utils |
281 | 46 | from twisted.internet import reactor | 90 | from twisted.internet import reactor |
296 | 47 | window = MainWindow(close_callback=stop) | 91 | # All this has to be imported here because it installs a reactor |
297 | 48 | app.window = window | 92 | from ubuntuone.platform.credentials import CredentialsManagementTool |
298 | 49 | 93 | from ubuntuone_installer.logger import setup_logging | |
299 | 50 | # Set Application Style Sheet | 94 | logger = setup_logging('qt.gui') |
300 | 51 | app = QtGui.QApplication.instance() | 95 | |
301 | 52 | qss = QtCore.QResource(":/ubuntuone.qss") | 96 | check_credentials(CredentialsManagementTool, gui, logger) |
288 | 53 | app.setStyleSheet(QtCore.QString(qss.data())) | ||
289 | 54 | # Apply font to the entire application | ||
290 | 55 | QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-R.ttf') | ||
291 | 56 | QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-B.ttf') | ||
292 | 57 | # Set Application Icon | ||
293 | 58 | app.setWindowIcon(QtGui.QIcon(":/ubuntu_one_favicon.png")) | ||
294 | 59 | |||
295 | 60 | window.show() | ||
302 | 61 | reactor.run() | 97 | reactor.run() |
303 | 62 | 98 | ||
304 | === modified file 'ubuntuone_installer/gui/qt/tests/test_gui.py' | |||
305 | --- ubuntuone_installer/gui/qt/tests/test_gui.py 2011-08-26 12:24:48 +0000 | |||
306 | +++ ubuntuone_installer/gui/qt/tests/test_gui.py 2011-08-29 12:42:23 +0000 | |||
307 | @@ -31,22 +31,6 @@ | |||
308 | 31 | from ubuntuone_installer.gui.qt.tests import BaseTestCase | 31 | from ubuntuone_installer.gui.qt.tests import BaseTestCase |
309 | 32 | 32 | ||
310 | 33 | 33 | ||
311 | 34 | TOKEN = {u'consumer_key': u'xQ7xDAz', | ||
312 | 35 | u'consumer_secret': u'KzCJWCTNbbntwfyCKKjomJDzlgqxLy', | ||
313 | 36 | u'token_name': u'test', | ||
314 | 37 | u'token': u'GkInOfSMGwTXAUoVQwLUoPxElEEUdhsLVNTPhxHJDUIeHCPNEo', | ||
315 | 38 | u'token_secret': u'qFYImEtlczPbsCnYyuwLoPDlPEnvNcIktZphPQklAWrvyfFMV'} | ||
316 | 39 | |||
317 | 40 | |||
318 | 41 | class FakeFailureCredentialsManagementTool(object): | ||
319 | 42 | |||
320 | 43 | """A fake CredentialsManagementTool that fails.""" | ||
321 | 44 | |||
322 | 45 | def find_credentials(self): | ||
323 | 46 | """Return a deferred that never triggers callback.""" | ||
324 | 47 | return defer.succeed({}) | ||
325 | 48 | |||
326 | 49 | |||
327 | 50 | class FakeController(object): | 34 | class FakeController(object): |
328 | 51 | 35 | ||
329 | 52 | """A fake controller for the tests.""" | 36 | """A fake controller for the tests.""" |
330 | @@ -165,8 +149,6 @@ | |||
331 | 165 | self.patch(gui, "LocalFoldersPage", FakeLocalFoldersPage) | 149 | self.patch(gui, "LocalFoldersPage", FakeLocalFoldersPage) |
332 | 166 | self.patch(qt.preferences, "PreferencesPanel", FakePreferencesPanel) | 150 | self.patch(qt.preferences, "PreferencesPanel", FakePreferencesPanel) |
333 | 167 | self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel) | 151 | self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel) |
334 | 168 | self.patch(gui, "CredentialsManagementTool", | ||
335 | 169 | FakeFailureCredentialsManagementTool) | ||
336 | 170 | super(MainWindowTestCase, self).setUp() | 152 | super(MainWindowTestCase, self).setUp() |
337 | 171 | 153 | ||
338 | 172 | def test_execute_uninstall_on_licence_cancel(self): | 154 | def test_execute_uninstall_on_licence_cancel(self): |
339 | @@ -566,17 +548,6 @@ | |||
340 | 566 | QtCore.QCoreApplication.instance().processEvents() | 548 | QtCore.QCoreApplication.instance().processEvents() |
341 | 567 | self.assertEqual(self.ui.result(), self.ui.Rejected) | 549 | self.assertEqual(self.ui.result(), self.ui.Rejected) |
342 | 568 | 550 | ||
343 | 569 | def test_license_next(self): | ||
344 | 570 | """Test what's the license page's nextID.""" | ||
345 | 571 | self.ui.creds_cb("fakecreds") | ||
346 | 572 | self.assertEqual(self.ui.LICENSE_PAGE.nextId(), | ||
347 | 573 | self.ui.local_folders_page_id) | ||
348 | 574 | |||
349 | 575 | def test_license_next_default(self): | ||
350 | 576 | """By default, should be the sign in page.""" | ||
351 | 577 | self.assertEqual(self.ui.LICENSE_PAGE.nextId(), | ||
352 | 578 | self.ui.SIGNIN_PAGE) | ||
353 | 579 | |||
354 | 580 | 551 | ||
355 | 581 | class FakeSignal(object): | 552 | class FakeSignal(object): |
356 | 582 | 553 | ||
357 | @@ -604,50 +575,9 @@ | |||
358 | 604 | userCancellation = FakeSignal() | 575 | userCancellation = FakeSignal() |
359 | 605 | shown = False | 576 | shown = False |
360 | 606 | 577 | ||
361 | 578 | def __init__(self, close_callback=None): | ||
362 | 579 | pass | ||
363 | 580 | |||
364 | 607 | def show(self): | 581 | def show(self): |
365 | 608 | """Fake method.""" | 582 | """Fake method.""" |
366 | 609 | self.shown = True | 583 | self.shown = True |
367 | 610 | |||
368 | 611 | |||
369 | 612 | class FakeFailingCredentialsManagementTool(object): | ||
370 | 613 | |||
371 | 614 | """A fake CredentialsManagementTool that fails.""" | ||
372 | 615 | |||
373 | 616 | def find_credentials(self): | ||
374 | 617 | """Return a deferred that never triggers callback.""" | ||
375 | 618 | return defer.fail(Exception()) | ||
376 | 619 | |||
377 | 620 | |||
378 | 621 | class CredsFailureMainWindowTestCase(BaseTestCase): | ||
379 | 622 | """Test the qt main window.""" | ||
380 | 623 | |||
381 | 624 | class_ui = gui.MainWindow | ||
382 | 625 | |||
383 | 626 | def setUp(self): | ||
384 | 627 | """Initialize this test instance.""" | ||
385 | 628 | # Faking each SSO object instead of doing it lower | ||
386 | 629 | # so we don't rely on any SSO behaviour | ||
387 | 630 | self.patch(gui, "SetUpAccountController", FakeController) | ||
388 | 631 | self.patch(gui, "TosController", FakeController) | ||
389 | 632 | self.patch(gui, "EmailVerificationController", FakeController) | ||
390 | 633 | self.patch(gui, "CurrentUserController", FakeController) | ||
391 | 634 | self.patch(gui, "SuccessController", FakeController) | ||
392 | 635 | self.patch(gui, "ForgottenPasswordController", FakeController) | ||
393 | 636 | self.patch(gui, "ResetPasswordController", FakeController) | ||
394 | 637 | self.patch(gui, "AreYouSure", FakeAreYouSure) | ||
395 | 638 | self.patch(gui, "LoadingOverlay", FakeOverlay) | ||
396 | 639 | self.patch(gui, "LocalFoldersPage", FakeLocalFoldersPage) | ||
397 | 640 | self.patch(qt.preferences, "PreferencesPanel", FakePreferencesPanel) | ||
398 | 641 | self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel) | ||
399 | 642 | self.patch(gui, "CredentialsManagementTool", | ||
400 | 643 | FakeFailingCredentialsManagementTool) | ||
401 | 644 | super(CredsFailureMainWindowTestCase, self).setUp() | ||
402 | 645 | |||
403 | 646 | def test_overlay_hiding(self): | ||
404 | 647 | """Credential errors should make the overlay hide.""" | ||
405 | 648 | self.assertEqual(self.ui.overlay.hide_counter, 1) | ||
406 | 649 | |||
407 | 650 | def test_critical(self): | ||
408 | 651 | """Credential errors should display a critical message.""" | ||
409 | 652 | self.assertEqual(self.ui.form_errors_label.text(), | ||
410 | 653 | "Application will close.\n\nException()") | ||
411 | 654 | 584 | ||
412 | === modified file 'ubuntuone_installer/gui/qt/utils/__init__.py' | |||
413 | --- ubuntuone_installer/gui/qt/utils/__init__.py 2011-08-23 17:27:56 +0000 | |||
414 | +++ ubuntuone_installer/gui/qt/utils/__init__.py 2011-08-29 12:42:23 +0000 | |||
415 | @@ -21,10 +21,12 @@ | |||
416 | 21 | 21 | ||
417 | 22 | import sys | 22 | import sys |
418 | 23 | 23 | ||
420 | 24 | 24 | # pylint: disable=C0103 | |
421 | 25 | if sys.platform == 'win32': | 25 | if sys.platform == 'win32': |
422 | 26 | from ubuntuone_installer.gui.qt.utils import windows | 26 | from ubuntuone_installer.gui.qt.utils import windows |
423 | 27 | uninstall_application = windows.uninstall_application | 27 | uninstall_application = windows.uninstall_application |
424 | 28 | start_control_panel = windows.start_control_panel | ||
425 | 28 | else: | 29 | else: |
426 | 29 | from ubuntuone_installer.gui.qt.utils import linux | 30 | from ubuntuone_installer.gui.qt.utils import linux |
427 | 30 | uninstall_application = linux.uninstall_application | 31 | uninstall_application = linux.uninstall_application |
428 | 32 | start_control_panel = linux.start_control_panel | ||
429 | 31 | 33 | ||
430 | === modified file 'ubuntuone_installer/gui/qt/utils/linux.py' | |||
431 | --- ubuntuone_installer/gui/qt/utils/linux.py 2011-08-23 17:27:56 +0000 | |||
432 | +++ ubuntuone_installer/gui/qt/utils/linux.py 2011-08-29 12:42:23 +0000 | |||
433 | @@ -18,7 +18,13 @@ | |||
434 | 18 | 18 | ||
435 | 19 | """Utils Functions Linux specific.""" | 19 | """Utils Functions Linux specific.""" |
436 | 20 | 20 | ||
437 | 21 | import subprocess | ||
438 | 21 | 22 | ||
439 | 22 | def uninstall_application(): | 23 | def uninstall_application(): |
440 | 23 | """Uninstall Ubuntu One.""" | 24 | """Uninstall Ubuntu One.""" |
441 | 24 | pass | 25 | pass |
442 | 26 | |||
443 | 27 | |||
444 | 28 | def start_control_panel(): | ||
445 | 29 | """Start the control panel.""" | ||
446 | 30 | subprocess.Popen(["ubuntuone-control-panel-qt", ]) | ||
447 | 25 | 31 | ||
448 | === modified file 'ubuntuone_installer/gui/qt/utils/tests/test_windows.py' | |||
449 | --- ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-08-26 18:41:33 +0000 | |||
450 | +++ ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-08-29 12:42:23 +0000 | |||
451 | @@ -54,6 +54,6 @@ | |||
452 | 54 | self.assertTrue(self._called[0][0] is None) | 54 | self.assertTrue(self._called[0][0] is None) |
453 | 55 | self.assertTrue("uninstall.exe" in self._called[0][2]) | 55 | self.assertTrue("uninstall.exe" in self._called[0][2]) |
454 | 56 | self.assertTrue('runas' == self._called[0][1]) | 56 | self.assertTrue('runas' == self._called[0][1]) |
456 | 57 | self.assertTrue('--mode=qt' == self._called[0][3]) | 57 | self.assertTrue('--mode qt' == self._called[0][3]) |
457 | 58 | self.assertTrue('' == self._called[0][4]) | 58 | self.assertTrue('' == self._called[0][4]) |
458 | 59 | self.assertTrue(0 == self._called[0][5]) | 59 | self.assertTrue(0 == self._called[0][5]) |
459 | 60 | 60 | ||
460 | === modified file 'ubuntuone_installer/gui/qt/utils/windows.py' | |||
461 | --- ubuntuone_installer/gui/qt/utils/windows.py 2011-08-26 18:41:33 +0000 | |||
462 | +++ ubuntuone_installer/gui/qt/utils/windows.py 2011-08-29 12:42:23 +0000 | |||
463 | @@ -19,8 +19,9 @@ | |||
464 | 19 | """Utils Functions Windows specific.""" | 19 | """Utils Functions Windows specific.""" |
465 | 20 | 20 | ||
466 | 21 | 21 | ||
467 | 22 | import os | ||
468 | 23 | import subprocess | ||
469 | 22 | import sys | 24 | import sys |
470 | 23 | import os | ||
471 | 24 | 25 | ||
472 | 25 | import win32api | 26 | import win32api |
473 | 26 | 27 | ||
474 | @@ -36,3 +37,16 @@ | |||
475 | 36 | win32api.ShellExecute(None, 'runas', | 37 | win32api.ShellExecute(None, 'runas', |
476 | 37 | uninstall_path, | 38 | uninstall_path, |
477 | 38 | '--mode qt', '', 0) | 39 | '--mode qt', '', 0) |
478 | 40 | |||
479 | 41 | |||
480 | 42 | def start_control_panel(): | ||
481 | 43 | """Start the control panel.""" | ||
482 | 44 | # If we are in windows and "frozen", assume it's in | ||
483 | 45 | # the same folder as this .exe | ||
484 | 46 | if sys.platform == "win32" and hasattr(sys, "frozen"): | ||
485 | 47 | cp_path = os.path.join(os.path.dirname( | ||
486 | 48 | os.path.abspath(sys.executable)), | ||
487 | 49 | "ubuntuone-control-panel-qt.exe") | ||
488 | 50 | else: | ||
489 | 51 | cp_path = "ubuntuone-control-panel-qt" | ||
490 | 52 | subprocess.Popen([cp_path, ]) |
Looks good!