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
1=== modified file 'ubuntuone_installer/gui/qt/gui.py'
2--- ubuntuone_installer/gui/qt/gui.py 2012-01-09 21:50:40 +0000
3+++ ubuntuone_installer/gui/qt/gui.py 2012-01-26 14:48:26 +0000
4@@ -18,8 +18,10 @@
5
6 import gettext
7
8+from twisted.internet import defer
9 from PyQt4 import QtGui, QtCore
10
11+from ubuntu_sso import networkstate
12 from ubuntu_sso.qt.gui import (
13 SSOWizardPage,
14 EmailVerificationPage,
15@@ -74,6 +76,7 @@
16 from ubuntuone_installer.gui.qt.folders import FoldersPage
17 from ubuntuone_installer.gui.qt.forgotten import ForgottenPasswordController
18 from ubuntuone_installer.gui.qt.local_folders import LocalFoldersPage
19+from ubuntuone_installer.gui.qt.network_detection import NetworkDetectionPage
20 from ubuntuone_installer.gui.qt.preferences import PreferencesPage
21 from ubuntuone_installer.gui.qt.sync_now_or_later import SyncNowOrLaterPage
22 from ubuntuone_installer.gui.qt.setup_account import SetupAccountPage
23@@ -151,7 +154,6 @@
24 """Wizard Page that displays the license info and links to the GPL."""
25
26 def __init__(self, parent=None):
27- self._next_id = None
28 super(LicensePage, self).__init__(license_ui.Ui_Form(), None, parent)
29 self.header.setVisible(False)
30 self.ui.textBrowser.setHtml(qt.LICENSE_CONTENT)
31@@ -163,7 +165,7 @@
32 def initializePage(self):
33 """Setup UI details."""
34 # Set the right texts and connections for buttons
35- self.setButtonText(QtGui.QWizard.NextButton, _("Agree && continue"))
36+ self.setButtonText(QtGui.QWizard.CustomButton1, _("Agree && continue"))
37 self.setButtonText(QtGui.QWizard.CancelButton,
38 _("Disagree && uninstall"))
39
40@@ -179,19 +181,30 @@
41 QtGui.QWizard.CancelButton,
42 QtGui.QWizard.BackButton,
43 QtGui.QWizard.Stretch,
44- QtGui.QWizard.NextButton,
45- QtGui.QWizard.FinishButton])
46+ QtGui.QWizard.CustomButton1])
47
48- self.agree_button = self.wizard().button(QtGui.QWizard.NextButton)
49+ self.agree_button = self.wizard().button(QtGui.QWizard.CustomButton1)
50 self.agree_button.setDefault(True)
51 self.agree_button.style().unpolish(self.agree_button)
52 self.agree_button.style().polish(self.agree_button)
53+ self.wizard().customButtonClicked.connect(self.check_connection)
54+
55+ # pylint: disable=W0212
56+ @defer.inlineCallbacks
57+ def check_connection(self, button_id):
58+ """Decide next ID based on network detection."""
59+ if button_id == QtGui.QWizard.CustomButton1:
60+ connected = yield self.wizard().check_connection()
61+ if connected:
62+ self.next = self.wizard().SIGN_IN_PAGE_ID
63+ else:
64+ self.next = self.wizard()._next_id
65+ self.wizard().next()
66+ # pylint: enable=W0212
67
68 def nextId(self):
69- """Return next page's ID."""
70- if self._next_id is None:
71- return self.wizard().SIGNIN_PAGE
72- return self._next_id
73+ """Return the next page ID."""
74+ return self.next
75
76
77 class SignInPage(SSOWizardPage):
78@@ -394,6 +407,7 @@
79 # pylint: disable=C0103
80 self.license_page = LicensePage()
81 self.LICENSE_PAGE = self.addPage(self.license_page)
82+ self.network_page = NetworkDetectionPage()
83
84 #SSO Pages
85 title_page = TITLE_STYLE % SIGN_IN
86@@ -450,7 +464,8 @@
87 self.reset_password.ui.reset_password_button.clicked.connect(
88 self.overlay.show)
89
90- self.SIGNIN_PAGE = self.addPage(self.sign_in_page)
91+ self.SIGN_IN_PAGE_ID = self.addPage(self.sign_in_page)
92+ self.NETWORK_DETECTION_PAGE_ID = self.addPage(self.network_page)
93 self.setup_account_page_id = self.addPage(self.setup_account)
94 self.email_verification_page_id = self.addPage(self.email_verification)
95 self.current_user_page_id = self.addPage(self.current_user)
96@@ -478,15 +493,23 @@
97 # Set Wizard buttons style
98 self.button(QtGui.QWizard.NextButton).setDefault(True)
99
100+ self.set_start_page(installing)
101+
102+ # Invalid name "closeEvent"
103+ # pylint: disable=C0103
104+
105+ @defer.inlineCallbacks
106+ def set_start_page(self, installing):
107+ """Set the Wizard start page based in some conditions."""
108+ connected = yield self.check_connection()
109 if installing:
110 self.setStartId(self.LICENSE_PAGE)
111- else:
112+ elif connected:
113 self.setStartId(self.SIGNIN_PAGE)
114+ else:
115+ self.setStartId(self._next_id)
116 self.restart()
117
118- # Invalid name "closeEvent"
119- # pylint: disable=C0103
120-
121 def critical(self, message, page=None):
122 """Show a message at the bottom of the page on form errors."""
123 self.overlay.hide()
124@@ -513,6 +536,16 @@
125 else:
126 return QtGui.QWizard.nextId(self)
127
128+ @defer.inlineCallbacks
129+ def check_connection(self):
130+ """Return is machine is connected, False set Network Page as next."""
131+ # pylint: disable=W0703
132+ connected = yield networkstate.is_machine_connected()
133+ if not connected:
134+ self._next_id = self.NETWORK_DETECTION_PAGE_ID
135+ defer.returnValue(connected)
136+ # pylint: enable=W0703
137+
138 def login_success_slot(self):
139 """Called on successful login."""
140 self._next_id = self.SUCCESS_PAGE
141
142=== added file 'ubuntuone_installer/gui/qt/network_detection.py'
143--- ubuntuone_installer/gui/qt/network_detection.py 1970-01-01 00:00:00 +0000
144+++ ubuntuone_installer/gui/qt/network_detection.py 2012-01-26 14:48:26 +0000
145@@ -0,0 +1,76 @@
146+# -*- coding: utf-8 *-*
147+#
148+# Copyright 2011 Canonical Ltd.
149+#
150+# This program is free software: you can redistribute it and/or modify it
151+# under the terms of the GNU General Public License version 3, as published
152+# by the Free Software Foundation.
153+#
154+# This program is distributed in the hope that it will be useful, but
155+# WITHOUT ANY WARRANTY; without even the implied warranties of
156+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
157+# PURPOSE. See the GNU General Public License for more details.
158+#
159+# You should have received a copy of the GNU General Public License along
160+# with this program. If not, see <http://www.gnu.org/licenses/>.
161+
162+"""Widget to show if we don't detect a network connection."""
163+
164+import gettext
165+
166+from twisted.internet import defer
167+from PyQt4 import QtGui
168+
169+from ubuntu_sso import networkstate
170+
171+from ubuntuone_installer.gui.qt.ui import network_detection_ui
172+
173+_ = gettext.gettext
174+
175+
176+class NetworkDetectionPage(QtGui.QWizardPage):
177+
178+ """Widget to show if we don't detect a network connection."""
179+
180+ def __init__(self, parent=None):
181+ super(NetworkDetectionPage, self).__init__(parent)
182+ self.setTitle(_("Installing Ubuntu One"))
183+ self.ui = network_detection_ui.Ui_Form()
184+ self.ui.setupUi(self)
185+ self.btn_try_again = None
186+
187+ # pylint: disable=C0103
188+ def initializePage(self):
189+ """Set UI details."""
190+ self.wizard()._next_id = None
191+
192+ self.setButtonText(QtGui.QWizard.CustomButton1, _("Try again"))
193+ self.setButtonText(QtGui.QWizard.CancelButton,
194+ _("Close window and set up later"))
195+ self.wizard().setButtonLayout([
196+ QtGui.QWizard.Stretch,
197+ QtGui.QWizard.CustomButton1,
198+ QtGui.QWizard.CancelButton,
199+ ])
200+
201+ try:
202+ self.wizard().customButtonClicked.disconnect()
203+ except TypeError:
204+ pass
205+
206+ self.btn_try_again = self.wizard().button(QtGui.QWizard.CustomButton1)
207+ self.btn_try_again.setDefault(True)
208+ self.btn_try_again.style().unpolish(self.btn_try_again)
209+ self.btn_try_again.style().polish(self.btn_try_again)
210+ self.wizard().customButtonClicked.connect(self.try_again)
211+ # pylint: enable=C0103
212+
213+ @defer.inlineCallbacks
214+ def try_again(self, button_id=QtGui.QWizard.CustomButton1):
215+ """Test the connection again."""
216+ if button_id == QtGui.QWizard.CustomButton1:
217+ d = yield networkstate.is_machine_connected()
218+ if d:
219+ self.wizard()._next_id = self.wizard().SIGN_IN_PAGE_ID
220+ self.wizard().next()
221+ self.wizard()._next_id = None
222
223=== modified file 'ubuntuone_installer/gui/qt/tests/__init__.py'
224--- ubuntuone_installer/gui/qt/tests/__init__.py 2012-01-03 15:00:57 +0000
225+++ ubuntuone_installer/gui/qt/tests/__init__.py 2012-01-26 14:48:26 +0000
226@@ -156,6 +156,7 @@
227 self.overlay = FakeOverlay()
228 self.called = []
229 self.buttons = {}
230+ self._next_id = -1
231
232 # Invalid name "setButtonLayout", "setOption"
233 # pylint: disable=C0103
234@@ -177,11 +178,16 @@
235
236 class FakeWizardButtonStyle(FakeWizard):
237
238+ """Fake Wizard with button style implementation."""
239+
240+ SIGN_IN_PAGE_ID = 1
241+
242+ # pylint: disable=C0103
243 def __init__(self):
244 super(FakeWizardButtonStyle, self).__init__()
245 self.data = {}
246+ self.customButtonClicked = self
247
248- # pylint: disable=C0103
249 def setDefault(self, value):
250 """Fake setDefault for button."""
251 self.data['default'] = value
252@@ -191,6 +197,14 @@
253 return self.data['default']
254 # pylint: enable=C0103
255
256+ def connect(self, func):
257+ """Fake customButtonClicked connect."""
258+ self.data['connect'] = func
259+
260+ def disconnect(self, func):
261+ """Fake customButtonClicked disconnect."""
262+ self.data['disconnect'] = func
263+
264 def button(self, button_id):
265 """Fake the functionality of button on QWizard class."""
266 return self
267@@ -207,6 +221,10 @@
268 """Fake unpolish."""
269 self.data['unpolish'] = button
270
271+ def next(self):
272+ """Fake next for wizard."""
273+ self.data['next'] = True
274+
275
276 class FakeWizardPage(object):
277
278
279=== modified file 'ubuntuone_installer/gui/qt/tests/test_gui.py'
280--- ubuntuone_installer/gui/qt/tests/test_gui.py 2012-01-03 15:00:57 +0000
281+++ ubuntuone_installer/gui/qt/tests/test_gui.py 2012-01-26 14:48:26 +0000
282@@ -129,10 +129,21 @@
283 self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel)
284 self.patch(gui.qt.utils, "add_syncdaemon_to_autostart", NO_OP)
285 self.patch(gui.backend, "ControlBackend", FakeBackend)
286+ self.patch(gui.networkstate, "is_machine_connected",
287+ lambda: defer.succeed(True))
288 yield super(MainWindowTestCase, self).setUp()
289 setup_page = self.ui.page(self.ui.setup_account_page_id)
290 setup_page.initializePage()
291
292+ def test_check_network_id(self):
293+ """Check that the Network Detect page is not the first one."""
294+ win = gui.MainWindow()
295+ # Check that NETWORK_DETECTION_PAGE_ID is greater than 1,
296+ # this means that is not the first or second page, which should be
297+ # LICENSE and SIGN_IN.
298+ # (SIGN_IN will be the first running without --install)
299+ self.assertTrue(win.NETWORK_DETECTION_PAGE_ID > 1)
300+
301 # pylint: disable=E1101
302 def test_setup_account_controller_params(self):
303 """Test with SetupAccountController params."""
304@@ -141,6 +152,93 @@
305 self.assertEqual(val, win)
306 self.assertEqual(win.setup_controller.args[0], ())
307
308+ def test_network_detection_connection_enabled(self):
309+ """Test the flow of the pages without connection."""
310+ self.patch(gui.networkstate, "is_machine_connected",
311+ lambda: defer.succeed(True))
312+ license_page = self.ui.page(self.ui.LICENSE_PAGE)
313+ self.ui.setStartId(self.ui.LICENSE_PAGE)
314+ self.ui.restart()
315+ self.ui.show()
316+ self.addCleanup(self.ui.hide)
317+ license_page.check_connection(QtGui.QWizard.CustomButton1)
318+ page_id = license_page.next
319+ self.assertEqual(page_id, self.ui.SIGN_IN_PAGE_ID)
320+
321+ def test_network_detection_connection_disabled(self):
322+ """Test the flow of the pages with connection."""
323+ self.patch(gui.networkstate, "is_machine_connected",
324+ lambda: defer.succeed(False))
325+ license_page = self.ui.page(self.ui.LICENSE_PAGE)
326+ self.ui.setStartId(self.ui.LICENSE_PAGE)
327+ self.ui.restart()
328+ self.ui.show()
329+ self.addCleanup(self.ui.hide)
330+ license_page.check_connection(QtGui.QWizard.CustomButton1)
331+ page_id = license_page.next
332+ self.assertEqual(page_id, self.ui.NETWORK_DETECTION_PAGE_ID)
333+
334+ def test_license_page_check_connection_no_button(self):
335+ """Check the state of next when another button is pressed."""
336+ license_page = self.ui.page(self.ui.LICENSE_PAGE)
337+ self.ui.setStartId(self.ui.LICENSE_PAGE)
338+ self.ui.restart()
339+ self.ui.show()
340+ self.addCleanup(self.ui.hide)
341+ license_page.next = -1
342+ license_page.check_connection(QtGui.QWizard.NextButton)
343+ page_id = license_page.next
344+ self.assertEqual(page_id, -1)
345+
346+ def test_network_detection_retry_fail(self):
347+ """Test the flow of the pages when the retry button is pressed."""
348+ self.patch(gui.networkstate, "is_machine_connected",
349+ lambda: defer.succeed(False))
350+ network_page = self.ui.page(self.ui.NETWORK_DETECTION_PAGE_ID)
351+ self.ui.setStartId(self.ui.NETWORK_DETECTION_PAGE_ID)
352+ self.ui.restart()
353+ self.ui.show()
354+ self.addCleanup(self.ui.hide)
355+ network_page.try_again()
356+ self.assertEqual(self.ui.currentId(),
357+ self.ui.NETWORK_DETECTION_PAGE_ID)
358+
359+ # pylint: disable=W0212
360+ @defer.inlineCallbacks
361+ def test_check_connection_with_connection(self):
362+ """Test the check_connection function with connection = True."""
363+ self.patch(gui.networkstate, "is_machine_connected",
364+ lambda: defer.succeed(True))
365+ self.ui._next_id = -1
366+ connected = yield self.ui.check_connection()
367+ self.assertNotEqual(self.ui._next_id,
368+ self.ui.NETWORK_DETECTION_PAGE_ID)
369+ self.assertTrue(connected)
370+
371+ @defer.inlineCallbacks
372+ def test_check_connection_with_no_connection(self):
373+ """Test the check_connection function with connection = False."""
374+ self.patch(gui.networkstate, "is_machine_connected",
375+ lambda: defer.succeed(False))
376+ connected = yield self.ui.check_connection()
377+ self.assertEqual(self.ui._next_id, self.ui.NETWORK_DETECTION_PAGE_ID)
378+ self.assertFalse(connected)
379+ self.assertFalse(False)
380+ # pylint: enable=W0212
381+
382+ def test_network_detection_retry_works(self):
383+ """Test the flow of the pages when the retry button is pressed."""
384+ self.patch(gui.networkstate, "is_machine_connected",
385+ lambda: defer.succeed(True))
386+ network_page = self.ui.page(self.ui.NETWORK_DETECTION_PAGE_ID)
387+ self.ui.setStartId(self.ui.NETWORK_DETECTION_PAGE_ID)
388+ self.ui.restart()
389+ self.ui.show()
390+ self.addCleanup(self.ui.hide)
391+ network_page.try_again()
392+ self.assertNotEqual(self.ui.currentId(),
393+ self.ui.NETWORK_DETECTION_PAGE_ID)
394+
395 def test_current_user_controller_params(self):
396 """Test with CurrentUserController params."""
397 win = gui.MainWindow()
398@@ -183,11 +281,20 @@
399 unicode(self.ui.sign_in_page.ui.message_label.text()),
400 u"")
401
402- def test_without_flag(self):
403+ def test_without_flag_connected(self):
404 """test with flag activated."""
405+ self.patch(gui.networkstate, "is_machine_connected",
406+ lambda: defer.succeed(True))
407 win = gui.MainWindow()
408 self.assertEqual(win.startId(), win.SIGNIN_PAGE)
409
410+ def test_without_flag_disconnected(self):
411+ """test with flag activated."""
412+ self.patch(gui.networkstate, "is_machine_connected",
413+ lambda: defer.succeed(False))
414+ win = gui.MainWindow()
415+ self.assertEqual(win.startId(), win.NETWORK_DETECTION_PAGE_ID)
416+
417 def test_initialize_page(self):
418 """Check the initializePage to ensure proper widgets visibility."""
419 setup_page = self.ui.page(self.ui.setup_account_page_id)
420
421=== added file 'ubuntuone_installer/gui/qt/tests/test_network_detection.py'
422--- ubuntuone_installer/gui/qt/tests/test_network_detection.py 1970-01-01 00:00:00 +0000
423+++ ubuntuone_installer/gui/qt/tests/test_network_detection.py 2012-01-26 14:48:26 +0000
424@@ -0,0 +1,95 @@
425+# -*- coding: utf-8 -*-
426+
427+# Copyright 2012 Canonical Ltd.
428+#
429+# This program is free software: you can redistribute it and/or modify it
430+# under the terms of the GNU General Public License version 3, as published
431+# by the Free Software Foundation.
432+#
433+# This program is distributed in the hope that it will be useful, but
434+# WITHOUT ANY WARRANTY; without even the implied warranties of
435+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
436+# PURPOSE. See the GNU General Public License for more details.
437+#
438+# You should have received a copy of the GNU General Public License along
439+# with this program. If not, see <http://www.gnu.org/licenses/>.
440+
441+"""The test suite for Network Detection UI."""
442+
443+from twisted.internet import defer
444+
445+from PyQt4 import QtGui
446+
447+from ubuntuone_installer.gui.qt import network_detection
448+from ubuntuone_installer.gui.qt.tests import (
449+ BaseTestCase,
450+ FakeWizardButtonStyle,
451+)
452+
453+
454+class NetworkDetectionTestCase(BaseTestCase):
455+
456+ """Test the CurrentUserController."""
457+
458+ @defer.inlineCallbacks
459+ def setUp(self):
460+ """Initialize this test instance."""
461+ yield super(NetworkDetectionTestCase, self).setUp()
462+ self.wizard = FakeWizardButtonStyle()
463+ self.network_detection_page = network_detection.NetworkDetectionPage()
464+ self.patch(self.network_detection_page, 'wizard', self._get_wizard)
465+
466+ def _get_wizard(self):
467+ """Fake wizard method for wizard page."""
468+ return self.wizard
469+
470+ # pylint: disable=W0212
471+ def test_initialize_page(self):
472+ """Check Network detection initialize page."""
473+ self.network_detection_page.initializePage()
474+ self.assertEqual(self.wizard._next_id, None)
475+ self.assertTrue(('setButtonLayout', ([
476+ QtGui.QWizard.Stretch,
477+ QtGui.QWizard.CustomButton1,
478+ QtGui.QWizard.CancelButton], {})),
479+ self.wizard.called)
480+
481+ def test_initialize_page_button_property(self):
482+ """Test the Try Again button properties."""
483+ self.patch(self.network_detection_page,
484+ "wizard", FakeWizardButtonStyle)
485+ self.network_detection_page.initializePage()
486+ self.assertTrue(self.network_detection_page.btn_try_again.isDefault())
487+ self.assertTrue(
488+ 'polish' in self.network_detection_page.btn_try_again.data)
489+ self.assertTrue(
490+ 'unpolish' in self.network_detection_page.btn_try_again.data)
491+ self.assertEqual(
492+ self.network_detection_page.btn_try_again.data['polish'],
493+ self.network_detection_page.btn_try_again)
494+ self.assertEqual(
495+ self.network_detection_page.btn_try_again.data['unpolish'],
496+ self.network_detection_page.btn_try_again)
497+
498+ def test_try_again_with_connection(self):
499+ """Check try again method with connection."""
500+ self.patch(network_detection.networkstate, 'is_machine_connected',
501+ lambda: True)
502+ self.wizard._next_id = -1
503+ if 'next' in self.wizard.data:
504+ self.wizard.data.pop('next')
505+ self.network_detection_page.try_again()
506+ self.assertEqual(self.wizard._next_id, None)
507+ self.assertTrue(self.wizard.data.get('next', False))
508+
509+ def test_try_again_without_connection(self):
510+ """Check try again method without connection."""
511+ self.patch(network_detection.networkstate, 'is_machine_connected',
512+ lambda: False)
513+ self.wizard._next_id = -1
514+ if 'next' in self.wizard.data:
515+ self.wizard.data.pop('next')
516+ self.network_detection_page.try_again()
517+ self.assertEqual(self.wizard._next_id, -1)
518+ self.assertFalse(self.wizard.data.get('next', False))
519+ # pylint: enable=W0212

Subscribers

People subscribed via source and target branches