Merge lp:~diegosarmentero/ubuntu-sso-client/network-page into lp:ubuntu-sso-client

Proposed by Diego Sarmentero on 2012-05-11
Status: Merged
Approved by: Diego Sarmentero on 2012-05-14
Approved revision: 955
Merged at revision: 955
Proposed branch: lp:~diegosarmentero/ubuntu-sso-client/network-page
Merge into: lp:ubuntu-sso-client
Diff against target: 201 lines (+62/-16)
4 files modified
ubuntu_sso/qt/network_detection_page.py (+4/-5)
ubuntu_sso/qt/tests/test_network_detection.py (+10/-11)
ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py (+20/-0)
ubuntu_sso/qt/ubuntu_sso_wizard.py (+28/-0)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntu-sso-client/network-page
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve on 2012-05-14
Roberto Alsina (community) 2012-05-11 Approve on 2012-05-11
Review via email: mp+105517@code.launchpad.net

Commit Message

- Fixed: Check network connection when the wizard starts (LP: 996025)

To post a comment you must log in.
Roberto Alsina (ralsina) wrote :

+1

review: Approve
Manuel de la Peña (mandel) wrote :

Ran in all 3 supported platforms and all tests pass. Code looks ok.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/qt/network_detection_page.py'
2--- ubuntu_sso/qt/network_detection_page.py 2012-04-09 17:38:24 +0000
3+++ ubuntu_sso/qt/network_detection_page.py 2012-05-11 18:39:19 +0000
4@@ -29,7 +29,7 @@
5 """Pages from SSO."""
6
7 from twisted.internet import defer
8-from PyQt4 import QtGui
9+from PyQt4 import QtGui, QtCore
10
11 from ubuntu_sso import networkstate
12 from ubuntu_sso.logger import setup_logging
13@@ -51,6 +51,7 @@
14 """Widget to show if we don't detect a network connection."""
15
16 ui_class = network_detection_ui.Ui_Form
17+ connectionDetected = QtCore.pyqtSignal()
18
19 def __init__(self, *args, **kwargs):
20 super(NetworkDetectionPage, self).__init__(*args, **kwargs)
21@@ -64,7 +65,7 @@
22 def initializePage(self):
23 """Set UI details."""
24 logger.debug('initializePage - About to show NetworkDetectionPage')
25- self.wizard()._next_id = None
26+ self.wizard()._next_id = -1
27
28 self.setButtonText(QtGui.QWizard.CustomButton1, TRY_AGAIN_BUTTON)
29 self.setButtonText(QtGui.QWizard.CancelButton,
30@@ -94,9 +95,7 @@
31 if button_id == QtGui.QWizard.CustomButton1:
32 d = yield networkstate.is_machine_connected()
33 if d:
34- self.wizard()._next_id = self.wizard().SIGN_IN_PAGE_ID
35- self.wizard().next()
36- self.wizard()._next_id = None
37+ self.connectionDetected.emit()
38
39 def _set_translated_strings(self):
40 """Implement in each child."""
41
42=== modified file 'ubuntu_sso/qt/tests/test_network_detection.py'
43--- ubuntu_sso/qt/tests/test_network_detection.py 2012-04-09 17:38:24 +0000
44+++ ubuntu_sso/qt/tests/test_network_detection.py 2012-05-11 18:39:19 +0000
45@@ -32,6 +32,7 @@
46
47 from ubuntu_sso.qt import network_detection_page
48 from ubuntu_sso.qt.tests import (
49+ FakeSignal,
50 PageBaseTestCase,
51 FakeWizardButtonStyle,
52 )
53@@ -50,7 +51,7 @@
54 def test_initialize_page(self):
55 """Check Network detection initialize page."""
56 self.ui.initializePage()
57- self.assertEqual(self.wizard._next_id, None)
58+ self.assertEqual(self.wizard._next_id, -1)
59 self.assertTrue(('setButtonLayout', ([
60 QtGui.QWizard.Stretch,
61 QtGui.QWizard.CustomButton1,
62@@ -66,20 +67,18 @@
63 """Check try again method with connection."""
64 self.patch(network_detection_page.networkstate, 'is_machine_connected',
65 lambda: True)
66- self.wizard._next_id = -1
67- if 'next' in self.wizard.data:
68- self.wizard.data.pop('next')
69+ fake_signal = FakeSignal()
70+ fake_signal.target = self._set_called
71+ self.patch(self.ui, 'connectionDetected', fake_signal)
72 self.ui.try_again()
73- self.assertEqual(self.wizard._next_id, None)
74- self.assertTrue(self.wizard.data.get('next', False))
75+ self.assertEqual(self._called, ((), {}))
76
77 def test_try_again_without_connection(self):
78 """Check try again method without connection."""
79 self.patch(network_detection_page.networkstate, 'is_machine_connected',
80 lambda: False)
81- self.wizard._next_id = -1
82- if 'next' in self.wizard.data:
83- self.wizard.data.pop('next')
84+ fake_signal = FakeSignal()
85+ fake_signal.target = self._set_called
86+ self.patch(self.ui, 'connectionDetected', fake_signal)
87 self.ui.try_again()
88- self.assertEqual(self.wizard._next_id, -1)
89- self.assertFalse(self.wizard.data.get('next', False))
90+ self.assertFalse(self._called)
91
92=== modified file 'ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py'
93--- ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-04-09 17:38:24 +0000
94+++ ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-05-11 18:39:19 +0000
95@@ -56,6 +56,8 @@
96
97 @defer.inlineCallbacks
98 def setUp(self):
99+ self.patch(ubuntu_sso_wizard.networkstate, 'is_machine_connected',
100+ lambda: True)
101 yield super(UbuntuSSOClientGUITestCase, self).setUp()
102 self.patch(ubuntu_sso_wizard.sys, 'exit', self._set_called)
103
104@@ -119,6 +121,8 @@
105
106 @defer.inlineCallbacks
107 def setUp(self):
108+ self.patch(ubuntu_sso_wizard.networkstate, 'is_machine_connected',
109+ lambda: True)
110 self.patch(ubuntu_sso_wizard, 'LoadingOverlay', FakeOverlay)
111 yield super(UbuntuSSOWizardTestCase, self).setUp()
112
113@@ -183,8 +187,24 @@
114
115 def test_email_verification_page_params_from_setup(self):
116 """Tests that email_verification_page receives the proper params."""
117+ self.ui._next_id = self.ui.setup_account_page_id
118+ self.ui.next()
119 self.ui.setup_account.ui.email_edit.setText(EMAIL)
120 self.ui.setup_account.ui.password_edit.setText(PASSWORD)
121 self.ui.setup_account.on_user_registered(APP_NAME, {})
122 self.assertEqual(EMAIL, self.ui.email_verification.email)
123 self.assertEqual(PASSWORD, self.ui.email_verification.password)
124+
125+ def test_check_network_connection(self):
126+ """Test that _connection_detected is executed with connection."""
127+ self.patch(self.ui, "_connection_detected", self._set_called)
128+ self.ui.check_network_connection()
129+ self.assertEqual(self._called, ((), {}))
130+
131+ def test_check_network_connection_without_connection(self):
132+ """Test that _connection_detected is executed without connection."""
133+ self.patch(self.ui, "_connection_detected", self._set_called)
134+ self.patch(ubuntu_sso_wizard.networkstate, 'is_machine_connected',
135+ lambda: False)
136+ self.ui.check_network_connection()
137+ self.assertFalse(self._called)
138
139=== modified file 'ubuntu_sso/qt/ubuntu_sso_wizard.py'
140--- ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-04-09 17:38:24 +0000
141+++ ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-05-11 18:39:19 +0000
142@@ -36,8 +36,10 @@
143 QVBoxLayout,
144 QWizard,
145 )
146+from twisted.internet import defer
147
148 from ubuntu_sso import (
149+ networkstate,
150 USER_CANCELLATION,
151 USER_SUCCESS,
152 )
153@@ -48,6 +50,7 @@
154 from ubuntu_sso.qt.error_page import ErrorPage
155 from ubuntu_sso.qt.forgotten_password_page import ForgottenPasswordPage
156 from ubuntu_sso.qt.loadingoverlay import LoadingOverlay
157+from ubuntu_sso.qt.network_detection_page import NetworkDetectionPage
158 from ubuntu_sso.qt.reset_password_page import ResetPasswordPage
159 from ubuntu_sso.qt.setup_account_page import SetupAccountPage
160 from ubuntu_sso.qt.success_page import SuccessPage
161@@ -87,6 +90,10 @@
162 kwargs['app_name'] = self.app_name
163 kwargs['parent'] = self
164
165+ self.network_page = NetworkDetectionPage(self.app_name)
166+ self.network_page.connectionDetected.connect(self._connection_detected)
167+ self.addPage(self.network_page)
168+
169 # set the diff pages of the QWizard
170 if not self.login_only:
171 self.setup_account = SetupAccountPage(**kwargs)
172@@ -136,8 +143,29 @@
173 self.setMinimumSize(PREFERED_UI_SIZE['width'],
174 PREFERED_UI_SIZE['height'])
175
176+ @defer.inlineCallbacks
177+ def check_network_connection(self):
178+ """Check if the NetworkDetectionPage is needed to be shown."""
179+ d = yield networkstate.is_machine_connected()
180+ if d:
181+ self._connection_detected()
182+
183+ def _connection_detected(self):
184+ """Connection restablished, move to the proper page."""
185+ if self.login_only:
186+ self._next_id = self.current_user_page_id
187+ else:
188+ self._next_id = self.setup_account_page_id
189+ self.next()
190+ self._next_id = -1
191+
192 # pylint: disable=C0103
193
194+ def showEvent(self, event):
195+ """Check the network connection before the ui is shown."""
196+ super(UbuntuSSOWizard, self).showEvent(event)
197+ self.check_network_connection()
198+
199 def nextId(self):
200 """Return the id of the next page."""
201 return self._next_id

Subscribers

People subscribed via source and target branches