Merge lp:~diegosarmentero/ubuntuone-windows-installer/network-detect into lp:ubuntuone-windows-installer

Proposed by Diego Sarmentero
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 122
Merged at revision: 104
Proposed branch: lp:~diegosarmentero/ubuntuone-windows-installer/network-detect
Merge into: lp:ubuntuone-windows-installer
Diff against target: 519 lines (+345/-16)
5 files modified
ubuntuone_installer/gui/qt/gui.py (+47/-14)
ubuntuone_installer/gui/qt/network_detection.py (+76/-0)
ubuntuone_installer/gui/qt/tests/__init__.py (+19/-1)
ubuntuone_installer/gui/qt/tests/test_gui.py (+108/-1)
ubuntuone_installer/gui/qt/tests/test_network_detection.py (+95/-0)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-windows-installer/network-detect
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+77049@code.launchpad.net

Commit message

- Fixed: Missing page: No network detected (LP: #804610).

Description of the change

Fixed: Missing page: No network detected (LP: #804610).

To test in real life, you need to execute the installer with the "--installer param.
And configure the VM enabling the net adaptar for the traditional flow and then disabling the net adapter to see the Network Detection page.

To post a comment you must log in.
74. By Diego Sarmentero

- Fixed: There is no feedback on captcha loading/refreshing (LP: #852105).

75. By Diego Sarmentero

Fixed: LocalFoldersPage.get_info does not hide the overlay on backend error (LP: #828944).

76. By Manuel de la Peña

Provides a function that allows the installer to know if the old beta is installed in the system. The technique uses the msi lib and ctypes to check that the uid of the old beta is present in the system.

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

Question: does this branch depend on the sso/network-detect branch? Should I use that to test this one?

Reviewing it, the branch looks fine. Just one detail:
Is this copypasta? "Authors: Roberto Alsina <email address hidden>"

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

> Question: does this branch depend on the sso/network-detect branch? Should I
> use that to test this one?
>
> Reviewing it, the branch looks fine. Just one detail:
> Is this copypasta? "Authors: Roberto Alsina <email address hidden>"

Yes, this depends on the other branch.

And i forgot to include myself as an author (Roberto started a branch for this, and i took what he has to keep on this task).

77. By Alejandro J. Cura

Do a HEAD request on the server to get accurate timestamp (LP: #692597).

78. By Manuel de la Peña

Provides a function that can be used to uninstall the old beta of ubuntu one.

79. By Diego Sarmentero

Fixed: When running the wizard from the bundle, the "Skip tour" is the default button (LP: #845778).
Fixed: When running the wizard from the bundle, there is no default button in the first screen (LP: #848016).

80. By Diego Sarmentero

Fixed: Wizard is not closed on license agreement screen (LP: #835167).

81. By Manuel de la Peña

Provides a function that allows to migrate the data that was downloed by the previous beta.

82. By Manuel de la Peña

Fix the reactor installation by ensuring that tools does not install the reactor.

83. By Diego Sarmentero

Fixed Tests (LP: #882519).

84. By Natalia Bidart

Bump release for development.

85. By Diego Sarmentero

Fixed: Should call self.backend.connect_files as soon as valid credentials are created (LP: #852085).

86. By Diego Sarmentero

- Fixed: Process finished successfully (LP: #859743).

87. By Diego Sarmentero

Fixed: Successfull message after login says "TextLabel" (LP: #889255).

88. By Natalia Bidart

- Import qt4reactor properly (LP: #888722).

89. By Natalia Bidart

- Bump release for development.

90. By Manuel de la Peña

Changed the import from ubuntuone-dev-tools so that we do not use the deprecated API.

91. By Manuel de la Peña

Fixes the code that will call the autoupdate-windows.exe. The idea is that in the release the .exe will be in a diff location to avoid dll collisions.

92. By Diego Sarmentero

Fixed congratulations page (LP: #859711).

93. By Natalia Bidart

- Pass module for test to u1trial properly.

94. By Manuel de la Peña

Put all the different pieces of the migration together so that we perform the uninstall and migtration of the data if the user has the very old first beta.

95. By Diego Sarmentero

Fixed: When logging in with an no-yet-validated account, there is no useful message (LP: #851885).

96. By Diego Sarmentero

Fixed lint issues

97. By Roberto Alsina

Quote the paths for autostart.

98. By Roberto Alsina

Make UDF creation from the wizard work.

99. By Natalia Bidart

- Proper naming for the project (using ubuntuone-windows-installer now).

100. By Diego Sarmentero

Agree button modified to look as a default button.

101. By Roberto Alsina

Fix strings to:

1) Fix a grammar error
2) Mention Ubuntu One so the user knows what he's upgrading.

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

When trying to merged this branch into latest trunk, I get:

Warning: criss-cross merge encountered. See bzr help criss-cross.
 M ubuntuone_installer/gui/qt/tests/test_gui.py
Text conflict in ubuntuone_installer/gui/qt/tests/test_gui.py
1 conflicts encountered.

Can you please remove the criss-cross and resolve the conflict?

Thanks!!!

review: Needs Fixing
102. By Diego Sarmentero

Conflicts resolved

103. By Diego Sarmentero

Adding network_detection file

104. By Diego Sarmentero

Fixed custom button in License Page.

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

I'm getting this lint issue:

== Python Lint Notices ==

ubuntuone_installer/gui/qt/tests/__init__.py:
    178: [C0111, FakeWizardButtonStyle] Missing docstring

review: Needs Fixing
105. By Diego Sarmentero

New Network detection implementation.
Added more tests.

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

I have several tests not passing: http://pastebin.ubuntu.com/798185/

Also (this comes from trunk):

ubuntuone_installer/gui/qt/tests/__init__.py:
    178: [C0111, FakeWizardButtonStyle] Missing docstring

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

Running u1lint directly on this branch I'm getting these:

== Python Lint Notices ==

ubuntuone_installer/gui/qt/gui.py:
    200: [W0212, LicensePage.check_connection] Access to a protected member _next_id of a client class

ubuntuone_installer/gui/qt/tests/__init__.py:
    185: [C0103, FakeWizardButtonStyle.__init__] Invalid name "customButtonClicked" (should match [a-z_][a-z0-9_]{1,30}$)

ubuntuone_installer/gui/qt/tests/test_gui.py:
    154: [W0622, MainWindowTestCase.test_network_detection_connection_enabled] Redefining built-in 'id'
    166: [W0622, MainWindowTestCase.test_network_detection_connection_disabled] Redefining built-in 'id'
    178: [W0622, MainWindowTestCase.test_license_page_check_connection_no_button] Redefining built-in 'id'
    194: [W0622, MainWindowTestCase.test_license_page_check_connection_error] Redefining built-in 'id'
    216: [W0212, MainWindowTestCase.test_check_connection_with_connection] Access to a protected member _next_id of a client class
    225: [W0212, MainWindowTestCase.test_check_connection_with_no_connection] Access to a protected member _next_id of a client class
    237: [W0212, MainWindowTestCase.test_check_connection_with_exception] Access to a protected member _next_id of a client class

106. By Diego Sarmentero

Tests and lint issues fixed

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

- The new TestCase added in ubuntuone_installer/gui/tests/__init__.py is duplicated from ubuntuone_installer/tests/__init__.py, please use that instead.

- As far as I see, there are no test for the new module ubuntuone_installer/gui/qt/network_detection.py. There should be a new test file called ubuntuone_installer/gui/qt/tests/test_network_detection.py that tests that new module.

review: Needs Fixing
107. By Diego Sarmentero

Adding network_detection test case.

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

I'm getting all these lint issues:

== Python Lint Notices ==

ubuntuone_installer/gui/qt/tests/__init__.py:
    224: [C0111, FakeWizardButtonStyle.next] Missing docstring

ubuntuone_installer/gui/qt/tests/test_network_detection.py:
    40: [C0111, NetworkDetectionTestCase._get_wizard] Missing docstring
    46: [W0212, NetworkDetectionTestCase.test_initialize_page] Access to a protected member _next_id of a client class
    61: [W0212, NetworkDetectionTestCase.test_try_again_with_connection] Access to a protected member _next_id of a client class
    72: [W0212, NetworkDetectionTestCase.test_try_again_without_connection] Access to a protected member _next_id of a client class

review: Needs Fixing
108. By Diego Sarmentero

fixed lint issues.

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

This branch is looking lovely, thanks for working on it.

One issue:
138 + except Exception, reason:
...
140 + self.critical(reason.message, self.network_page)

I don't think that showing in the UI the exception message is the right thing
I think we should have a generic/custom error message that's translatable in the U1-win-installer code itself; something like "Cannot get network state" and log the exact reason.

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

Another thing, that may deserve a new bug: assertEqualPixmaps should be used from a common location, perhaps in sso.

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

The rest of the branch looks nice; as soon as the above is fixed, ping me and I'll run the tests.
Thanks!

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

> Another thing, that may deserve a new bug: assertEqualPixmaps should be used
> from a common location, perhaps in sso.

Bug created for this:
https://bugs.launchpad.net/ubuntu-sso-client/+bug/915281

109. By Diego Sarmentero

changing network state exception message.

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

The is an error in a test:

===============================================================================
[FAIL]
Traceback (most recent call last):
  File "E:\windows-installer\review_network-detect\ubuntuone_installer\gui\qt\te
sts\test_gui.py", line 196, in test_license_page_check_connection_error
    self.assertEqual(self.ui.form_errors_label.text(), 'Error...')
twisted.trial.unittest.FailTest: not equal:
a = PyQt4.QtCore.QString(u'The network state can not be detected.')
b = 'Error...'

ubuntuone_installer.gui.qt.tests.test_gui.MainWindowTestCase.test_license_page_c
heck_connection_error
-------------------------------------------------------------------------------

Please run the tests *every single time* before pushing a change, even if it's just a string change ;-). Thanks!

review: Needs Fixing
110. By Diego Sarmentero

Removing unnecessary tests.

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

The try: except: removed in the previous-to-last commit should not be removed, because if networkstate.is_machine_connected fails before returning a deferred, or if that deferred errbacks, then we should treat this as if the connection is present.

review: Needs Fixing
111. By Diego Sarmentero

Fixing some tests.

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

This branch is pratically ready, but when testing IRL, using the following scenario:

* with internet connection, open the installer. You should get the login/register screen. Do nothing for now.
* disable your internet connection from the "Network and Sharing Center".
* open the installer and confirm that the "no network" sreen is shown. Do not close the installer.
* re-enable your internet connection from the "Network and Sharing Center".
* in the opened installer, click "Try again". You will now have the login/register screen, as expected.
* click on the "Sign me with my existent account" button. Nothing happens, and console errors with:

2012-01-16 11:51:11,612:612.999916077 - ubuntu_sso.controllers - DEBUG - ChooseSignInController._set_next_existing QWizard::next: Page 1 already met

If I click on the "Sign me up" button, I get nothing in the UI and in the terminal:

2012-01-16 11:51:11,612:612.999916077 - ubuntu_sso.controllers - DEBUG - ChooseSignInController._set_next_existing
QWizard::next: Page 1 already met

review: Needs Fixing
112. By Diego Sarmentero

Fixed page navigation

113. By Diego Sarmentero

fixing sign in page navigation

114. By Diego Sarmentero

Merge and fixed tests.

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

So, now when I open the wizard with no arguments, I get the network detection page even if I have a valid connection.

review: Needs Fixing
115. By Diego Sarmentero

Reordering wizard pages.

116. By Diego Sarmentero

Adding test to check that network detection page is not the first or second one.

117. By Diego Sarmentero

Fixing comment

118. By Diego Sarmentero

Fixing case in comment

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

Looks good, but the "Try Again" button is not the default button when starting the installer without any option. See screenshot http://ubuntuone.com/0BEoQHRLiR0r9PI3sGHA2l

Could you please add that, so we're consistent with the page when running with the --installer swicth?

review: Needs Fixing
119. By Diego Sarmentero

Fixed try again button style.

120. By Diego Sarmentero

Adding Test for try again button properties

121. By Diego Sarmentero

removed unnecessary methods.

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

Looks good!
And works as expected.

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

As discussed on IRC, setMinimum(Height|Width) should not be changed to setFixed(Height|Width)

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

The rest looks fine, I'm about to approve this branch pending the fix just above.

122. By Diego Sarmentero

Changing back setFixed to setMinimum

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

A long time ago, in a repository far far away... this branch started!
It's nice to see it finally landing!

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 2012-01-09 21:50:40 +0000
+++ ubuntuone_installer/gui/qt/gui.py 2012-01-26 14:48:26 +0000
@@ -18,8 +18,10 @@
1818
19import gettext19import gettext
2020
21from twisted.internet import defer
21from PyQt4 import QtGui, QtCore22from PyQt4 import QtGui, QtCore
2223
24from ubuntu_sso import networkstate
23from ubuntu_sso.qt.gui import (25from ubuntu_sso.qt.gui import (
24 SSOWizardPage,26 SSOWizardPage,
25 EmailVerificationPage,27 EmailVerificationPage,
@@ -74,6 +76,7 @@
74from ubuntuone_installer.gui.qt.folders import FoldersPage76from ubuntuone_installer.gui.qt.folders import FoldersPage
75from ubuntuone_installer.gui.qt.forgotten import ForgottenPasswordController77from ubuntuone_installer.gui.qt.forgotten import ForgottenPasswordController
76from ubuntuone_installer.gui.qt.local_folders import LocalFoldersPage78from ubuntuone_installer.gui.qt.local_folders import LocalFoldersPage
79from ubuntuone_installer.gui.qt.network_detection import NetworkDetectionPage
77from ubuntuone_installer.gui.qt.preferences import PreferencesPage80from ubuntuone_installer.gui.qt.preferences import PreferencesPage
78from ubuntuone_installer.gui.qt.sync_now_or_later import SyncNowOrLaterPage81from ubuntuone_installer.gui.qt.sync_now_or_later import SyncNowOrLaterPage
79from ubuntuone_installer.gui.qt.setup_account import SetupAccountPage82from ubuntuone_installer.gui.qt.setup_account import SetupAccountPage
@@ -151,7 +154,6 @@
151 """Wizard Page that displays the license info and links to the GPL."""154 """Wizard Page that displays the license info and links to the GPL."""
152155
153 def __init__(self, parent=None):156 def __init__(self, parent=None):
154 self._next_id = None
155 super(LicensePage, self).__init__(license_ui.Ui_Form(), None, parent)157 super(LicensePage, self).__init__(license_ui.Ui_Form(), None, parent)
156 self.header.setVisible(False)158 self.header.setVisible(False)
157 self.ui.textBrowser.setHtml(qt.LICENSE_CONTENT)159 self.ui.textBrowser.setHtml(qt.LICENSE_CONTENT)
@@ -163,7 +165,7 @@
163 def initializePage(self):165 def initializePage(self):
164 """Setup UI details."""166 """Setup UI details."""
165 # Set the right texts and connections for buttons167 # Set the right texts and connections for buttons
166 self.setButtonText(QtGui.QWizard.NextButton, _("Agree && continue"))168 self.setButtonText(QtGui.QWizard.CustomButton1, _("Agree && continue"))
167 self.setButtonText(QtGui.QWizard.CancelButton,169 self.setButtonText(QtGui.QWizard.CancelButton,
168 _("Disagree && uninstall"))170 _("Disagree && uninstall"))
169171
@@ -179,19 +181,30 @@
179 QtGui.QWizard.CancelButton,181 QtGui.QWizard.CancelButton,
180 QtGui.QWizard.BackButton,182 QtGui.QWizard.BackButton,
181 QtGui.QWizard.Stretch,183 QtGui.QWizard.Stretch,
182 QtGui.QWizard.NextButton,184 QtGui.QWizard.CustomButton1])
183 QtGui.QWizard.FinishButton])
184185
185 self.agree_button = self.wizard().button(QtGui.QWizard.NextButton)186 self.agree_button = self.wizard().button(QtGui.QWizard.CustomButton1)
186 self.agree_button.setDefault(True)187 self.agree_button.setDefault(True)
187 self.agree_button.style().unpolish(self.agree_button)188 self.agree_button.style().unpolish(self.agree_button)
188 self.agree_button.style().polish(self.agree_button)189 self.agree_button.style().polish(self.agree_button)
190 self.wizard().customButtonClicked.connect(self.check_connection)
191
192 # pylint: disable=W0212
193 @defer.inlineCallbacks
194 def check_connection(self, button_id):
195 """Decide next ID based on network detection."""
196 if button_id == QtGui.QWizard.CustomButton1:
197 connected = yield self.wizard().check_connection()
198 if connected:
199 self.next = self.wizard().SIGN_IN_PAGE_ID
200 else:
201 self.next = self.wizard()._next_id
202 self.wizard().next()
203 # pylint: enable=W0212
189204
190 def nextId(self):205 def nextId(self):
191 """Return next page's ID."""206 """Return the next page ID."""
192 if self._next_id is None:207 return self.next
193 return self.wizard().SIGNIN_PAGE
194 return self._next_id
195208
196209
197class SignInPage(SSOWizardPage):210class SignInPage(SSOWizardPage):
@@ -394,6 +407,7 @@
394 # pylint: disable=C0103407 # pylint: disable=C0103
395 self.license_page = LicensePage()408 self.license_page = LicensePage()
396 self.LICENSE_PAGE = self.addPage(self.license_page)409 self.LICENSE_PAGE = self.addPage(self.license_page)
410 self.network_page = NetworkDetectionPage()
397411
398 #SSO Pages412 #SSO Pages
399 title_page = TITLE_STYLE % SIGN_IN413 title_page = TITLE_STYLE % SIGN_IN
@@ -450,7 +464,8 @@
450 self.reset_password.ui.reset_password_button.clicked.connect(464 self.reset_password.ui.reset_password_button.clicked.connect(
451 self.overlay.show)465 self.overlay.show)
452466
453 self.SIGNIN_PAGE = self.addPage(self.sign_in_page)467 self.SIGN_IN_PAGE_ID = self.addPage(self.sign_in_page)
468 self.NETWORK_DETECTION_PAGE_ID = self.addPage(self.network_page)
454 self.setup_account_page_id = self.addPage(self.setup_account)469 self.setup_account_page_id = self.addPage(self.setup_account)
455 self.email_verification_page_id = self.addPage(self.email_verification)470 self.email_verification_page_id = self.addPage(self.email_verification)
456 self.current_user_page_id = self.addPage(self.current_user)471 self.current_user_page_id = self.addPage(self.current_user)
@@ -478,15 +493,23 @@
478 # Set Wizard buttons style493 # Set Wizard buttons style
479 self.button(QtGui.QWizard.NextButton).setDefault(True)494 self.button(QtGui.QWizard.NextButton).setDefault(True)
480495
496 self.set_start_page(installing)
497
498 # Invalid name "closeEvent"
499 # pylint: disable=C0103
500
501 @defer.inlineCallbacks
502 def set_start_page(self, installing):
503 """Set the Wizard start page based in some conditions."""
504 connected = yield self.check_connection()
481 if installing:505 if installing:
482 self.setStartId(self.LICENSE_PAGE)506 self.setStartId(self.LICENSE_PAGE)
483 else:507 elif connected:
484 self.setStartId(self.SIGNIN_PAGE)508 self.setStartId(self.SIGNIN_PAGE)
509 else:
510 self.setStartId(self._next_id)
485 self.restart()511 self.restart()
486512
487 # Invalid name "closeEvent"
488 # pylint: disable=C0103
489
490 def critical(self, message, page=None):513 def critical(self, message, page=None):
491 """Show a message at the bottom of the page on form errors."""514 """Show a message at the bottom of the page on form errors."""
492 self.overlay.hide()515 self.overlay.hide()
@@ -513,6 +536,16 @@
513 else:536 else:
514 return QtGui.QWizard.nextId(self)537 return QtGui.QWizard.nextId(self)
515538
539 @defer.inlineCallbacks
540 def check_connection(self):
541 """Return is machine is connected, False set Network Page as next."""
542 # pylint: disable=W0703
543 connected = yield networkstate.is_machine_connected()
544 if not connected:
545 self._next_id = self.NETWORK_DETECTION_PAGE_ID
546 defer.returnValue(connected)
547 # pylint: enable=W0703
548
516 def login_success_slot(self):549 def login_success_slot(self):
517 """Called on successful login."""550 """Called on successful login."""
518 self._next_id = self.SUCCESS_PAGE551 self._next_id = self.SUCCESS_PAGE
519552
=== added file 'ubuntuone_installer/gui/qt/network_detection.py'
--- ubuntuone_installer/gui/qt/network_detection.py 1970-01-01 00:00:00 +0000
+++ ubuntuone_installer/gui/qt/network_detection.py 2012-01-26 14:48:26 +0000
@@ -0,0 +1,76 @@
1# -*- coding: utf-8 *-*
2#
3# Copyright 2011 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""Widget to show if we don't detect a network connection."""
18
19import gettext
20
21from twisted.internet import defer
22from PyQt4 import QtGui
23
24from ubuntu_sso import networkstate
25
26from ubuntuone_installer.gui.qt.ui import network_detection_ui
27
28_ = gettext.gettext
29
30
31class NetworkDetectionPage(QtGui.QWizardPage):
32
33 """Widget to show if we don't detect a network connection."""
34
35 def __init__(self, parent=None):
36 super(NetworkDetectionPage, self).__init__(parent)
37 self.setTitle(_("Installing Ubuntu One"))
38 self.ui = network_detection_ui.Ui_Form()
39 self.ui.setupUi(self)
40 self.btn_try_again = None
41
42 # pylint: disable=C0103
43 def initializePage(self):
44 """Set UI details."""
45 self.wizard()._next_id = None
46
47 self.setButtonText(QtGui.QWizard.CustomButton1, _("Try again"))
48 self.setButtonText(QtGui.QWizard.CancelButton,
49 _("Close window and set up later"))
50 self.wizard().setButtonLayout([
51 QtGui.QWizard.Stretch,
52 QtGui.QWizard.CustomButton1,
53 QtGui.QWizard.CancelButton,
54 ])
55
56 try:
57 self.wizard().customButtonClicked.disconnect()
58 except TypeError:
59 pass
60
61 self.btn_try_again = self.wizard().button(QtGui.QWizard.CustomButton1)
62 self.btn_try_again.setDefault(True)
63 self.btn_try_again.style().unpolish(self.btn_try_again)
64 self.btn_try_again.style().polish(self.btn_try_again)
65 self.wizard().customButtonClicked.connect(self.try_again)
66 # pylint: enable=C0103
67
68 @defer.inlineCallbacks
69 def try_again(self, button_id=QtGui.QWizard.CustomButton1):
70 """Test the connection again."""
71 if button_id == QtGui.QWizard.CustomButton1:
72 d = yield networkstate.is_machine_connected()
73 if d:
74 self.wizard()._next_id = self.wizard().SIGN_IN_PAGE_ID
75 self.wizard().next()
76 self.wizard()._next_id = None
077
=== modified file 'ubuntuone_installer/gui/qt/tests/__init__.py'
--- ubuntuone_installer/gui/qt/tests/__init__.py 2012-01-03 15:00:57 +0000
+++ ubuntuone_installer/gui/qt/tests/__init__.py 2012-01-26 14:48:26 +0000
@@ -156,6 +156,7 @@
156 self.overlay = FakeOverlay()156 self.overlay = FakeOverlay()
157 self.called = []157 self.called = []
158 self.buttons = {}158 self.buttons = {}
159 self._next_id = -1
159160
160 # Invalid name "setButtonLayout", "setOption"161 # Invalid name "setButtonLayout", "setOption"
161 # pylint: disable=C0103162 # pylint: disable=C0103
@@ -177,11 +178,16 @@
177178
178class FakeWizardButtonStyle(FakeWizard):179class FakeWizardButtonStyle(FakeWizard):
179180
181 """Fake Wizard with button style implementation."""
182
183 SIGN_IN_PAGE_ID = 1
184
185 # pylint: disable=C0103
180 def __init__(self):186 def __init__(self):
181 super(FakeWizardButtonStyle, self).__init__()187 super(FakeWizardButtonStyle, self).__init__()
182 self.data = {}188 self.data = {}
189 self.customButtonClicked = self
183190
184 # pylint: disable=C0103
185 def setDefault(self, value):191 def setDefault(self, value):
186 """Fake setDefault for button."""192 """Fake setDefault for button."""
187 self.data['default'] = value193 self.data['default'] = value
@@ -191,6 +197,14 @@
191 return self.data['default']197 return self.data['default']
192 # pylint: enable=C0103198 # pylint: enable=C0103
193199
200 def connect(self, func):
201 """Fake customButtonClicked connect."""
202 self.data['connect'] = func
203
204 def disconnect(self, func):
205 """Fake customButtonClicked disconnect."""
206 self.data['disconnect'] = func
207
194 def button(self, button_id):208 def button(self, button_id):
195 """Fake the functionality of button on QWizard class."""209 """Fake the functionality of button on QWizard class."""
196 return self210 return self
@@ -207,6 +221,10 @@
207 """Fake unpolish."""221 """Fake unpolish."""
208 self.data['unpolish'] = button222 self.data['unpolish'] = button
209223
224 def next(self):
225 """Fake next for wizard."""
226 self.data['next'] = True
227
210228
211class FakeWizardPage(object):229class FakeWizardPage(object):
212230
213231
=== modified file 'ubuntuone_installer/gui/qt/tests/test_gui.py'
--- ubuntuone_installer/gui/qt/tests/test_gui.py 2012-01-03 15:00:57 +0000
+++ ubuntuone_installer/gui/qt/tests/test_gui.py 2012-01-26 14:48:26 +0000
@@ -129,10 +129,21 @@
129 self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel)129 self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel)
130 self.patch(gui.qt.utils, "add_syncdaemon_to_autostart", NO_OP)130 self.patch(gui.qt.utils, "add_syncdaemon_to_autostart", NO_OP)
131 self.patch(gui.backend, "ControlBackend", FakeBackend)131 self.patch(gui.backend, "ControlBackend", FakeBackend)
132 self.patch(gui.networkstate, "is_machine_connected",
133 lambda: defer.succeed(True))
132 yield super(MainWindowTestCase, self).setUp()134 yield super(MainWindowTestCase, self).setUp()
133 setup_page = self.ui.page(self.ui.setup_account_page_id)135 setup_page = self.ui.page(self.ui.setup_account_page_id)
134 setup_page.initializePage()136 setup_page.initializePage()
135137
138 def test_check_network_id(self):
139 """Check that the Network Detect page is not the first one."""
140 win = gui.MainWindow()
141 # Check that NETWORK_DETECTION_PAGE_ID is greater than 1,
142 # this means that is not the first or second page, which should be
143 # LICENSE and SIGN_IN.
144 # (SIGN_IN will be the first running without --install)
145 self.assertTrue(win.NETWORK_DETECTION_PAGE_ID > 1)
146
136 # pylint: disable=E1101147 # pylint: disable=E1101
137 def test_setup_account_controller_params(self):148 def test_setup_account_controller_params(self):
138 """Test with SetupAccountController params."""149 """Test with SetupAccountController params."""
@@ -141,6 +152,93 @@
141 self.assertEqual(val, win)152 self.assertEqual(val, win)
142 self.assertEqual(win.setup_controller.args[0], ())153 self.assertEqual(win.setup_controller.args[0], ())
143154
155 def test_network_detection_connection_enabled(self):
156 """Test the flow of the pages without connection."""
157 self.patch(gui.networkstate, "is_machine_connected",
158 lambda: defer.succeed(True))
159 license_page = self.ui.page(self.ui.LICENSE_PAGE)
160 self.ui.setStartId(self.ui.LICENSE_PAGE)
161 self.ui.restart()
162 self.ui.show()
163 self.addCleanup(self.ui.hide)
164 license_page.check_connection(QtGui.QWizard.CustomButton1)
165 page_id = license_page.next
166 self.assertEqual(page_id, self.ui.SIGN_IN_PAGE_ID)
167
168 def test_network_detection_connection_disabled(self):
169 """Test the flow of the pages with connection."""
170 self.patch(gui.networkstate, "is_machine_connected",
171 lambda: defer.succeed(False))
172 license_page = self.ui.page(self.ui.LICENSE_PAGE)
173 self.ui.setStartId(self.ui.LICENSE_PAGE)
174 self.ui.restart()
175 self.ui.show()
176 self.addCleanup(self.ui.hide)
177 license_page.check_connection(QtGui.QWizard.CustomButton1)
178 page_id = license_page.next
179 self.assertEqual(page_id, self.ui.NETWORK_DETECTION_PAGE_ID)
180
181 def test_license_page_check_connection_no_button(self):
182 """Check the state of next when another button is pressed."""
183 license_page = self.ui.page(self.ui.LICENSE_PAGE)
184 self.ui.setStartId(self.ui.LICENSE_PAGE)
185 self.ui.restart()
186 self.ui.show()
187 self.addCleanup(self.ui.hide)
188 license_page.next = -1
189 license_page.check_connection(QtGui.QWizard.NextButton)
190 page_id = license_page.next
191 self.assertEqual(page_id, -1)
192
193 def test_network_detection_retry_fail(self):
194 """Test the flow of the pages when the retry button is pressed."""
195 self.patch(gui.networkstate, "is_machine_connected",
196 lambda: defer.succeed(False))
197 network_page = self.ui.page(self.ui.NETWORK_DETECTION_PAGE_ID)
198 self.ui.setStartId(self.ui.NETWORK_DETECTION_PAGE_ID)
199 self.ui.restart()
200 self.ui.show()
201 self.addCleanup(self.ui.hide)
202 network_page.try_again()
203 self.assertEqual(self.ui.currentId(),
204 self.ui.NETWORK_DETECTION_PAGE_ID)
205
206 # pylint: disable=W0212
207 @defer.inlineCallbacks
208 def test_check_connection_with_connection(self):
209 """Test the check_connection function with connection = True."""
210 self.patch(gui.networkstate, "is_machine_connected",
211 lambda: defer.succeed(True))
212 self.ui._next_id = -1
213 connected = yield self.ui.check_connection()
214 self.assertNotEqual(self.ui._next_id,
215 self.ui.NETWORK_DETECTION_PAGE_ID)
216 self.assertTrue(connected)
217
218 @defer.inlineCallbacks
219 def test_check_connection_with_no_connection(self):
220 """Test the check_connection function with connection = False."""
221 self.patch(gui.networkstate, "is_machine_connected",
222 lambda: defer.succeed(False))
223 connected = yield self.ui.check_connection()
224 self.assertEqual(self.ui._next_id, self.ui.NETWORK_DETECTION_PAGE_ID)
225 self.assertFalse(connected)
226 self.assertFalse(False)
227 # pylint: enable=W0212
228
229 def test_network_detection_retry_works(self):
230 """Test the flow of the pages when the retry button is pressed."""
231 self.patch(gui.networkstate, "is_machine_connected",
232 lambda: defer.succeed(True))
233 network_page = self.ui.page(self.ui.NETWORK_DETECTION_PAGE_ID)
234 self.ui.setStartId(self.ui.NETWORK_DETECTION_PAGE_ID)
235 self.ui.restart()
236 self.ui.show()
237 self.addCleanup(self.ui.hide)
238 network_page.try_again()
239 self.assertNotEqual(self.ui.currentId(),
240 self.ui.NETWORK_DETECTION_PAGE_ID)
241
144 def test_current_user_controller_params(self):242 def test_current_user_controller_params(self):
145 """Test with CurrentUserController params."""243 """Test with CurrentUserController params."""
146 win = gui.MainWindow()244 win = gui.MainWindow()
@@ -183,11 +281,20 @@
183 unicode(self.ui.sign_in_page.ui.message_label.text()),281 unicode(self.ui.sign_in_page.ui.message_label.text()),
184 u"")282 u"")
185283
186 def test_without_flag(self):284 def test_without_flag_connected(self):
187 """test with flag activated."""285 """test with flag activated."""
286 self.patch(gui.networkstate, "is_machine_connected",
287 lambda: defer.succeed(True))
188 win = gui.MainWindow()288 win = gui.MainWindow()
189 self.assertEqual(win.startId(), win.SIGNIN_PAGE)289 self.assertEqual(win.startId(), win.SIGNIN_PAGE)
190290
291 def test_without_flag_disconnected(self):
292 """test with flag activated."""
293 self.patch(gui.networkstate, "is_machine_connected",
294 lambda: defer.succeed(False))
295 win = gui.MainWindow()
296 self.assertEqual(win.startId(), win.NETWORK_DETECTION_PAGE_ID)
297
191 def test_initialize_page(self):298 def test_initialize_page(self):
192 """Check the initializePage to ensure proper widgets visibility."""299 """Check the initializePage to ensure proper widgets visibility."""
193 setup_page = self.ui.page(self.ui.setup_account_page_id)300 setup_page = self.ui.page(self.ui.setup_account_page_id)
194301
=== added file 'ubuntuone_installer/gui/qt/tests/test_network_detection.py'
--- ubuntuone_installer/gui/qt/tests/test_network_detection.py 1970-01-01 00:00:00 +0000
+++ ubuntuone_installer/gui/qt/tests/test_network_detection.py 2012-01-26 14:48:26 +0000
@@ -0,0 +1,95 @@
1# -*- coding: utf-8 -*-
2
3# Copyright 2012 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""The test suite for Network Detection UI."""
18
19from twisted.internet import defer
20
21from PyQt4 import QtGui
22
23from ubuntuone_installer.gui.qt import network_detection
24from ubuntuone_installer.gui.qt.tests import (
25 BaseTestCase,
26 FakeWizardButtonStyle,
27)
28
29
30class NetworkDetectionTestCase(BaseTestCase):
31
32 """Test the CurrentUserController."""
33
34 @defer.inlineCallbacks
35 def setUp(self):
36 """Initialize this test instance."""
37 yield super(NetworkDetectionTestCase, self).setUp()
38 self.wizard = FakeWizardButtonStyle()
39 self.network_detection_page = network_detection.NetworkDetectionPage()
40 self.patch(self.network_detection_page, 'wizard', self._get_wizard)
41
42 def _get_wizard(self):
43 """Fake wizard method for wizard page."""
44 return self.wizard
45
46 # pylint: disable=W0212
47 def test_initialize_page(self):
48 """Check Network detection initialize page."""
49 self.network_detection_page.initializePage()
50 self.assertEqual(self.wizard._next_id, None)
51 self.assertTrue(('setButtonLayout', ([
52 QtGui.QWizard.Stretch,
53 QtGui.QWizard.CustomButton1,
54 QtGui.QWizard.CancelButton], {})),
55 self.wizard.called)
56
57 def test_initialize_page_button_property(self):
58 """Test the Try Again button properties."""
59 self.patch(self.network_detection_page,
60 "wizard", FakeWizardButtonStyle)
61 self.network_detection_page.initializePage()
62 self.assertTrue(self.network_detection_page.btn_try_again.isDefault())
63 self.assertTrue(
64 'polish' in self.network_detection_page.btn_try_again.data)
65 self.assertTrue(
66 'unpolish' in self.network_detection_page.btn_try_again.data)
67 self.assertEqual(
68 self.network_detection_page.btn_try_again.data['polish'],
69 self.network_detection_page.btn_try_again)
70 self.assertEqual(
71 self.network_detection_page.btn_try_again.data['unpolish'],
72 self.network_detection_page.btn_try_again)
73
74 def test_try_again_with_connection(self):
75 """Check try again method with connection."""
76 self.patch(network_detection.networkstate, 'is_machine_connected',
77 lambda: True)
78 self.wizard._next_id = -1
79 if 'next' in self.wizard.data:
80 self.wizard.data.pop('next')
81 self.network_detection_page.try_again()
82 self.assertEqual(self.wizard._next_id, None)
83 self.assertTrue(self.wizard.data.get('next', False))
84
85 def test_try_again_without_connection(self):
86 """Check try again method without connection."""
87 self.patch(network_detection.networkstate, 'is_machine_connected',
88 lambda: False)
89 self.wizard._next_id = -1
90 if 'next' in self.wizard.data:
91 self.wizard.data.pop('next')
92 self.network_detection_page.try_again()
93 self.assertEqual(self.wizard._next_id, -1)
94 self.assertFalse(self.wizard.data.get('next', False))
95 # pylint: enable=W0212

Subscribers

People subscribed via source and target branches