Merge lp:~nataliabidart/ubuntu-sso-client/use-login-only into lp:ubuntu-sso-client
- use-login-only
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 899 |
Merged at revision: | 888 |
Proposed branch: | lp:~nataliabidart/ubuntu-sso-client/use-login-only |
Merge into: | lp:ubuntu-sso-client |
Diff against target: |
2912 lines (+562/-1252) 28 files modified
data/qt/choose_sign_in.ui (+0/-163) run-tests.bat (+1/-1) ubuntu_sso/qt/current_user_sign_in_page.py (+9/-18) ubuntu_sso/qt/email_verification_page.py (+18/-21) ubuntu_sso/qt/error_page.py (+11/-4) ubuntu_sso/qt/forgotten_password_page.py (+13/-20) ubuntu_sso/qt/loadingoverlay.py (+4/-11) ubuntu_sso/qt/network_detection_page.py (+17/-8) ubuntu_sso/qt/reset_password_page.py (+22/-29) ubuntu_sso/qt/setup_account_page.py (+66/-68) ubuntu_sso/qt/sign_in_page.py (+0/-97) ubuntu_sso/qt/sso_wizard_page.py (+51/-18) ubuntu_sso/qt/success_page.py (+13/-4) ubuntu_sso/qt/tests/__init__.py (+89/-37) ubuntu_sso/qt/tests/test_current_user_sign_in_page.py (+4/-70) ubuntu_sso/qt/tests/test_email_verification.py (+16/-66) ubuntu_sso/qt/tests/test_enchanced_line_edit.py (+2/-5) ubuntu_sso/qt/tests/test_error_page.py (+26/-0) ubuntu_sso/qt/tests/test_forgotten_password.py (+7/-59) ubuntu_sso/qt/tests/test_loadingoverlay.py (+8/-8) ubuntu_sso/qt/tests/test_network_detection.py (+19/-33) ubuntu_sso/qt/tests/test_reset_password.py (+19/-48) ubuntu_sso/qt/tests/test_setup_account.py (+19/-58) ubuntu_sso/qt/tests/test_sign_in_page.py (+0/-69) ubuntu_sso/qt/tests/test_sso_wizard_page.py (+12/-96) ubuntu_sso/qt/tests/test_success_page.py (+26/-0) ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py (+24/-48) ubuntu_sso/qt/ubuntu_sso_wizard.py (+66/-193) |
To merge this branch: | bzr merge lp:~nataliabidart/ubuntu-sso-client/use-login-only |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Diego Sarmentero (community) | Approve | ||
Roberto Alsina (community) | Approve | ||
Review via email: mp+94455@code.launchpad.net |
Description of the change
To post a comment you must log in.
- 890. By Natalia Bidart
-
- Also remove choose_sign_in.ui file (no longer needed in this project).
- 891. By Natalia Bidart
-
Merged trunk in.
- 892. By Natalia Bidart
-
- Fixed window tests run.
- 893. By Natalia Bidart
-
Movind the line_edit connects to _connect_ui method.
- 894. By Natalia Bidart
-
Merged dependency branch in.
- 895. By Natalia Bidart
-
Making test pass.
- 896. By Natalia Bidart
-
Merged trunk in.
- 897. By Natalia Bidart
-
Fixing another test.
- 898. By Natalia Bidart
-
Lint fixes.
- 899. By Natalia Bidart
-
Fixed pep8 issues.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file 'data/qt/choose_sign_in.ui' | |||
2 | --- data/qt/choose_sign_in.ui 2012-02-22 16:58:08 +0000 | |||
3 | +++ data/qt/choose_sign_in.ui 1970-01-01 00:00:00 +0000 | |||
4 | @@ -1,163 +0,0 @@ | |||
5 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
6 | 2 | <ui version="4.0"> | ||
7 | 3 | <class>ChooseSignInPage</class> | ||
8 | 4 | <widget class="QWizardPage" name="ChooseSignInPage"> | ||
9 | 5 | <property name="geometry"> | ||
10 | 6 | <rect> | ||
11 | 7 | <x>0</x> | ||
12 | 8 | <y>0</y> | ||
13 | 9 | <width>432</width> | ||
14 | 10 | <height>387</height> | ||
15 | 11 | </rect> | ||
16 | 12 | </property> | ||
17 | 13 | <layout class="QVBoxLayout" name="verticalLayout_2"> | ||
18 | 14 | <property name="leftMargin"> | ||
19 | 15 | <number>0</number> | ||
20 | 16 | </property> | ||
21 | 17 | <property name="topMargin"> | ||
22 | 18 | <number>0</number> | ||
23 | 19 | </property> | ||
24 | 20 | <property name="rightMargin"> | ||
25 | 21 | <number>0</number> | ||
26 | 22 | </property> | ||
27 | 23 | <item> | ||
28 | 24 | <layout class="QHBoxLayout" name="horizontalLayout_2"> | ||
29 | 25 | <item> | ||
30 | 26 | <widget class="QLabel" name="image_label"> | ||
31 | 27 | <property name="sizePolicy"> | ||
32 | 28 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
33 | 29 | <horstretch>0</horstretch> | ||
34 | 30 | <verstretch>0</verstretch> | ||
35 | 31 | </sizepolicy> | ||
36 | 32 | </property> | ||
37 | 33 | <property name="minimumSize"> | ||
38 | 34 | <size> | ||
39 | 35 | <width>400</width> | ||
40 | 36 | <height>150</height> | ||
41 | 37 | </size> | ||
42 | 38 | </property> | ||
43 | 39 | <property name="text"> | ||
44 | 40 | <string/> | ||
45 | 41 | </property> | ||
46 | 42 | <property name="textFormat"> | ||
47 | 43 | <enum>Qt::PlainText</enum> | ||
48 | 44 | </property> | ||
49 | 45 | <property name="alignment"> | ||
50 | 46 | <set>Qt::AlignCenter</set> | ||
51 | 47 | </property> | ||
52 | 48 | <property name="wordWrap"> | ||
53 | 49 | <bool>true</bool> | ||
54 | 50 | </property> | ||
55 | 51 | </widget> | ||
56 | 52 | </item> | ||
57 | 53 | </layout> | ||
58 | 54 | </item> | ||
59 | 55 | <item> | ||
60 | 56 | <widget class="QLabel" name="message_label"> | ||
61 | 57 | <property name="font"> | ||
62 | 58 | <font> | ||
63 | 59 | <pointsize>11</pointsize> | ||
64 | 60 | <weight>50</weight> | ||
65 | 61 | <bold>false</bold> | ||
66 | 62 | </font> | ||
67 | 63 | </property> | ||
68 | 64 | <property name="text"> | ||
69 | 65 | <string notr="true">Congratulations, app_name is installed!</string> | ||
70 | 66 | </property> | ||
71 | 67 | <property name="alignment"> | ||
72 | 68 | <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> | ||
73 | 69 | </property> | ||
74 | 70 | </widget> | ||
75 | 71 | </item> | ||
76 | 72 | <item> | ||
77 | 73 | <spacer name="verticalSpacer_3"> | ||
78 | 74 | <property name="orientation"> | ||
79 | 75 | <enum>Qt::Vertical</enum> | ||
80 | 76 | </property> | ||
81 | 77 | <property name="sizeType"> | ||
82 | 78 | <enum>QSizePolicy::Fixed</enum> | ||
83 | 79 | </property> | ||
84 | 80 | <property name="sizeHint" stdset="0"> | ||
85 | 81 | <size> | ||
86 | 82 | <width>20</width> | ||
87 | 83 | <height>30</height> | ||
88 | 84 | </size> | ||
89 | 85 | </property> | ||
90 | 86 | </spacer> | ||
91 | 87 | </item> | ||
92 | 88 | <item> | ||
93 | 89 | <layout class="QHBoxLayout" name="horizontalLayout"> | ||
94 | 90 | <item> | ||
95 | 91 | <spacer name="horizontalSpacer_2"> | ||
96 | 92 | <property name="orientation"> | ||
97 | 93 | <enum>Qt::Horizontal</enum> | ||
98 | 94 | </property> | ||
99 | 95 | <property name="sizeHint" stdset="0"> | ||
100 | 96 | <size> | ||
101 | 97 | <width>20</width> | ||
102 | 98 | <height>20</height> | ||
103 | 99 | </size> | ||
104 | 100 | </property> | ||
105 | 101 | </spacer> | ||
106 | 102 | </item> | ||
107 | 103 | <item> | ||
108 | 104 | <layout class="QVBoxLayout" name="verticalLayout"> | ||
109 | 105 | <item> | ||
110 | 106 | <widget class="QPushButton" name="existing_account_button"> | ||
111 | 107 | <property name="text"> | ||
112 | 108 | <string notr="true"/> | ||
113 | 109 | </property> | ||
114 | 110 | </widget> | ||
115 | 111 | </item> | ||
116 | 112 | <item> | ||
117 | 113 | <widget class="QPushButton" name="setup_account_button"> | ||
118 | 114 | <property name="text"> | ||
119 | 115 | <string notr="true"/> | ||
120 | 116 | </property> | ||
121 | 117 | </widget> | ||
122 | 118 | </item> | ||
123 | 119 | <item> | ||
124 | 120 | <widget class="QPushButton" name="cancel_button"> | ||
125 | 121 | <property name="text"> | ||
126 | 122 | <string notr="true"/> | ||
127 | 123 | </property> | ||
128 | 124 | </widget> | ||
129 | 125 | </item> | ||
130 | 126 | </layout> | ||
131 | 127 | </item> | ||
132 | 128 | <item> | ||
133 | 129 | <spacer name="horizontalSpacer"> | ||
134 | 130 | <property name="orientation"> | ||
135 | 131 | <enum>Qt::Horizontal</enum> | ||
136 | 132 | </property> | ||
137 | 133 | <property name="sizeType"> | ||
138 | 134 | <enum>QSizePolicy::Expanding</enum> | ||
139 | 135 | </property> | ||
140 | 136 | <property name="sizeHint" stdset="0"> | ||
141 | 137 | <size> | ||
142 | 138 | <width>20</width> | ||
143 | 139 | <height>20</height> | ||
144 | 140 | </size> | ||
145 | 141 | </property> | ||
146 | 142 | </spacer> | ||
147 | 143 | </item> | ||
148 | 144 | </layout> | ||
149 | 145 | </item> | ||
150 | 146 | <item> | ||
151 | 147 | <spacer name="verticalSpacer_2"> | ||
152 | 148 | <property name="orientation"> | ||
153 | 149 | <enum>Qt::Vertical</enum> | ||
154 | 150 | </property> | ||
155 | 151 | <property name="sizeHint" stdset="0"> | ||
156 | 152 | <size> | ||
157 | 153 | <width>20</width> | ||
158 | 154 | <height>50</height> | ||
159 | 155 | </size> | ||
160 | 156 | </property> | ||
161 | 157 | </spacer> | ||
162 | 158 | </item> | ||
163 | 159 | </layout> | ||
164 | 160 | </widget> | ||
165 | 161 | <resources/> | ||
166 | 162 | <connections/> | ||
167 | 163 | </ui> | ||
168 | 164 | 0 | ||
169 | === modified file 'run-tests.bat' | |||
170 | --- run-tests.bat 2012-01-31 19:02:36 +0000 | |||
171 | +++ run-tests.bat 2012-02-24 17:28:19 +0000 | |||
172 | @@ -99,7 +99,7 @@ | |||
173 | 99 | "%PYTHONEXEPATH%\python.exe" setup.py build | 99 | "%PYTHONEXEPATH%\python.exe" setup.py build |
174 | 100 | ECHO Running tests | 100 | ECHO Running tests |
175 | 101 | :: execute the tests with a number of ignored linux only modules | 101 | :: execute the tests with a number of ignored linux only modules |
177 | 102 | "%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" -i "test_linux.py, test_txsecrets.py" -p "ubuntu_sso\gtk" --reactor=qt4 --gui %PARAMS% ubuntu_sso | 102 | "%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" -i "test_linux.py, test_txsecrets.py, test_qt.py, test_glib.py" -p "ubuntu_sso\gtk" --reactor=qt4 --gui %PARAMS% ubuntu_sso |
178 | 103 | :: Clean the build from the setupt.py | 103 | :: Clean the build from the setupt.py |
179 | 104 | ECHO Cleaning the generated code | 104 | ECHO Cleaning the generated code |
180 | 105 | "%PYTHONEXEPATH%\python.exe" setup.py clean | 105 | "%PYTHONEXEPATH%\python.exe" setup.py clean |
181 | 106 | 106 | ||
182 | === modified file 'ubuntu_sso/qt/current_user_sign_in_page.py' | |||
183 | --- ubuntu_sso/qt/current_user_sign_in_page.py 2012-02-18 15:02:49 +0000 | |||
184 | +++ ubuntu_sso/qt/current_user_sign_in_page.py 2012-02-24 17:28:19 +0000 | |||
185 | @@ -19,12 +19,12 @@ | |||
186 | 19 | from functools import partial | 19 | from functools import partial |
187 | 20 | 20 | ||
188 | 21 | from PyQt4 import QtGui, QtCore | 21 | from PyQt4 import QtGui, QtCore |
189 | 22 | from twisted.internet import defer | ||
190 | 23 | 22 | ||
191 | 24 | from ubuntu_sso import NO_OP | 23 | from ubuntu_sso import NO_OP |
192 | 24 | from ubuntu_sso.logger import setup_logging | ||
193 | 25 | from ubuntu_sso.qt import build_general_error_message | 25 | from ubuntu_sso.qt import build_general_error_message |
196 | 26 | from ubuntu_sso.qt.gui import SSOWizardPage | 26 | from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage |
197 | 27 | from ubuntu_sso.logger import setup_logging | 27 | from ubuntu_sso.qt.ui.current_user_sign_in_ui import Ui_CurrentUserSignInPage |
198 | 28 | from ubuntu_sso.utils.ui import ( | 28 | from ubuntu_sso.utils.ui import ( |
199 | 29 | CANCEL_BUTTON, | 29 | CANCEL_BUTTON, |
200 | 30 | EMAIL_LABEL, | 30 | EMAIL_LABEL, |
201 | @@ -45,15 +45,15 @@ | |||
202 | 45 | class CurrentUserSignInPage(SSOWizardPage): | 45 | class CurrentUserSignInPage(SSOWizardPage): |
203 | 46 | """Wizard Page that lets a current user Sign into Ubuntu Single Sign On.""" | 46 | """Wizard Page that lets a current user Sign into Ubuntu Single Sign On.""" |
204 | 47 | 47 | ||
205 | 48 | ui_class = Ui_CurrentUserSignInPage | ||
206 | 48 | userLoggedIn = QtCore.pyqtSignal('QString', 'QString') | 49 | userLoggedIn = QtCore.pyqtSignal('QString', 'QString') |
207 | 49 | passwordForgotten = QtCore.pyqtSignal() | 50 | passwordForgotten = QtCore.pyqtSignal() |
208 | 50 | userNotValidated = QtCore.pyqtSignal('QString', 'QString') | 51 | userNotValidated = QtCore.pyqtSignal('QString', 'QString') |
209 | 51 | 52 | ||
215 | 52 | def __init__(self, ui, ping_url, *args, **kwargs): | 53 | @property |
216 | 53 | super(CurrentUserSignInPage, self).__init__(ui, *args, **kwargs) | 54 | def _signals(self): |
217 | 54 | self.ping_url = ping_url | 55 | """The signals to connect to the backend.""" |
218 | 55 | 56 | result = { | |
214 | 56 | self._signals = { | ||
219 | 57 | 'LoggedIn': | 57 | 'LoggedIn': |
220 | 58 | self._filter_by_app_name(self.on_logged_in), | 58 | self._filter_by_app_name(self.on_logged_in), |
221 | 59 | 'LoginError': | 59 | 'LoginError': |
222 | @@ -61,7 +61,7 @@ | |||
223 | 61 | 'UserNotValidated': | 61 | 'UserNotValidated': |
224 | 62 | self._filter_by_app_name(self.on_user_not_validated), | 62 | self._filter_by_app_name(self.on_user_not_validated), |
225 | 63 | } | 63 | } |
227 | 64 | self.setup_page() | 64 | return result |
228 | 65 | 65 | ||
229 | 66 | def on_user_not_validated(self, *args): | 66 | def on_user_not_validated(self, *args): |
230 | 67 | """Show the validate email page.""" | 67 | """Show the validate email page.""" |
231 | @@ -69,15 +69,6 @@ | |||
232 | 69 | password = unicode(self.ui.password_edit.text()) | 69 | password = unicode(self.ui.password_edit.text()) |
233 | 70 | self.userNotValidated.emit(email, password) | 70 | self.userNotValidated.emit(email, password) |
234 | 71 | 71 | ||
235 | 72 | @defer.inlineCallbacks | ||
236 | 73 | def setup_page(self): | ||
237 | 74 | """Setup the widget components.""" | ||
238 | 75 | self.backend = yield self.get_backend() | ||
239 | 76 | self._set_translated_strings() | ||
240 | 77 | # lets add call backs to be execute for the calls we are interested | ||
241 | 78 | self._setup_signals() | ||
242 | 79 | self._connect_ui() | ||
243 | 80 | |||
244 | 81 | # Invalid names of Qt-inherited methods | 72 | # Invalid names of Qt-inherited methods |
245 | 82 | # pylint: disable=C0103 | 73 | # pylint: disable=C0103 |
246 | 83 | 74 | ||
247 | 84 | 75 | ||
248 | === modified file 'ubuntu_sso/qt/email_verification_page.py' | |||
249 | --- ubuntu_sso/qt/email_verification_page.py 2012-02-22 16:58:08 +0000 | |||
250 | +++ ubuntu_sso/qt/email_verification_page.py 2012-02-24 17:28:19 +0000 | |||
251 | @@ -19,19 +19,19 @@ | |||
252 | 19 | from functools import partial | 19 | from functools import partial |
253 | 20 | 20 | ||
254 | 21 | from PyQt4 import QtCore | 21 | from PyQt4 import QtCore |
255 | 22 | from twisted.internet import defer | ||
256 | 23 | 22 | ||
257 | 24 | from ubuntu_sso import NO_OP | 23 | from ubuntu_sso import NO_OP |
258 | 24 | from ubuntu_sso.logger import setup_logging | ||
259 | 25 | from ubuntu_sso.qt import build_general_error_message | 25 | from ubuntu_sso.qt import build_general_error_message |
262 | 26 | from ubuntu_sso.qt.gui import SSOWizardPage | 26 | from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage |
263 | 27 | from ubuntu_sso.logger import setup_logging | 27 | from ubuntu_sso.qt.ui.email_verification_ui import Ui_EmailVerificationPage |
264 | 28 | from ubuntu_sso.utils.ui import ( | 28 | from ubuntu_sso.utils.ui import ( |
265 | 29 | ERROR_EMAIL_TOKEN, | ||
266 | 29 | NEXT, | 30 | NEXT, |
267 | 30 | VERIFICATION_CODE, | 31 | VERIFICATION_CODE, |
268 | 31 | VERIFY_EMAIL_TITLE, | 32 | VERIFY_EMAIL_TITLE, |
269 | 32 | VERIFY_EMAIL_CONTENT, | 33 | VERIFY_EMAIL_CONTENT, |
270 | 33 | ) | 34 | ) |
271 | 34 | from ubuntu_sso.utils.ui import ERROR_EMAIL_TOKEN | ||
272 | 35 | 35 | ||
273 | 36 | 36 | ||
274 | 37 | logger = setup_logging('ubuntu_sso.email_verification_page') | 37 | logger = setup_logging('ubuntu_sso.email_verification_page') |
275 | @@ -40,27 +40,24 @@ | |||
276 | 40 | class EmailVerificationPage(SSOWizardPage): | 40 | class EmailVerificationPage(SSOWizardPage): |
277 | 41 | """Widget used to input the email verification code.""" | 41 | """Widget used to input the email verification code.""" |
278 | 42 | 42 | ||
279 | 43 | ui_class = Ui_EmailVerificationPage | ||
280 | 43 | registrationSuccess = QtCore.pyqtSignal('QString', 'QString') | 44 | registrationSuccess = QtCore.pyqtSignal('QString', 'QString') |
281 | 44 | 45 | ||
285 | 45 | def __init__(self, ui, ping_url, *args, **kwargs): | 46 | def __init__(self, *args, **kwargs): |
283 | 46 | super(EmailVerificationPage, self).__init__(ui, *args, **kwargs) | ||
284 | 47 | self.ping_url = ping_url | ||
286 | 48 | self.email = '' | 47 | self.email = '' |
287 | 49 | self.password = '' | 48 | self.password = '' |
289 | 50 | self._signals = { | 49 | super(EmailVerificationPage, self).__init__(*args, **kwargs) |
290 | 50 | |||
291 | 51 | @property | ||
292 | 52 | def _signals(self): | ||
293 | 53 | """The signals to connect to the backend.""" | ||
294 | 54 | result = { | ||
295 | 51 | 'EmailValidated': | 55 | 'EmailValidated': |
296 | 52 | self._filter_by_app_name(self.on_email_validated), | 56 | self._filter_by_app_name(self.on_email_validated), |
297 | 53 | 'EmailValidationError': | 57 | 'EmailValidationError': |
298 | 54 | self._filter_by_app_name(self.on_email_validation_error), | 58 | self._filter_by_app_name(self.on_email_validation_error), |
299 | 55 | } | 59 | } |
308 | 56 | self.setup_page() | 60 | return result |
301 | 57 | |||
302 | 58 | @defer.inlineCallbacks | ||
303 | 59 | def setup_page(self): | ||
304 | 60 | """Setup the ui components.""" | ||
305 | 61 | self.backend = yield self.get_backend() | ||
306 | 62 | self._setup_signals() | ||
307 | 63 | self._connect_ui_elements() | ||
309 | 64 | 61 | ||
310 | 65 | @property | 62 | @property |
311 | 66 | def verification_code(self): | 63 | def verification_code(self): |
312 | @@ -72,9 +69,9 @@ | |||
313 | 72 | """Return the button that move to the next stage.""" | 69 | """Return the button that move to the next stage.""" |
314 | 73 | return self.ui.next_button | 70 | return self.ui.next_button |
315 | 74 | 71 | ||
317 | 75 | def _connect_ui_elements(self): | 72 | def _connect_ui(self): |
318 | 76 | """Set the connection of signals.""" | 73 | """Set the connection of signals.""" |
320 | 77 | logger.debug('EmailVerificationController._connect_ui_elements') | 74 | logger.debug('EmailVerificationController._connect_ui') |
321 | 78 | self.ui.verification_code_edit.textChanged.connect( | 75 | self.ui.verification_code_edit.textChanged.connect( |
322 | 79 | self.validate_form) | 76 | self.validate_form) |
323 | 80 | self.next_button.clicked.connect(self.validate_email) | 77 | self.next_button.clicked.connect(self.validate_email) |
324 | @@ -89,7 +86,7 @@ | |||
325 | 89 | self.next_button.style().unpolish(self.next_button) | 86 | self.next_button.style().unpolish(self.next_button) |
326 | 90 | self.next_button.style().polish(self.next_button) | 87 | self.next_button.style().polish(self.next_button) |
327 | 91 | 88 | ||
329 | 92 | def _set_titles(self): | 89 | def _set_translated_strings(self): |
330 | 93 | """Set the different titles.""" | 90 | """Set the different titles.""" |
331 | 94 | logger.debug('EmailVerificationController._set_titles') | 91 | logger.debug('EmailVerificationController._set_titles') |
332 | 95 | self.header.set_title(VERIFY_EMAIL_TITLE) | 92 | self.header.set_title(VERIFY_EMAIL_TITLE) |
333 | @@ -104,9 +101,9 @@ | |||
334 | 104 | """This class needs to have a public set_titles. | 101 | """This class needs to have a public set_titles. |
335 | 105 | 102 | ||
336 | 106 | Since the subtitle contains data that is only known after SetupAccount | 103 | Since the subtitle contains data that is only known after SetupAccount |
338 | 107 | and _set_titles is only called on initialization. | 104 | and _set_translated_strings is only called on initialization. |
339 | 108 | """ | 105 | """ |
341 | 109 | self._set_titles() | 106 | self._set_translated_strings() |
342 | 110 | 107 | ||
343 | 111 | def validate_email(self): | 108 | def validate_email(self): |
344 | 112 | """Call the next action.""" | 109 | """Call the next action.""" |
345 | 113 | 110 | ||
346 | === modified file 'ubuntu_sso/qt/error_page.py' | |||
347 | --- ubuntu_sso/qt/error_page.py 2012-02-07 18:59:36 +0000 | |||
348 | +++ ubuntu_sso/qt/error_page.py 2012-02-24 17:28:19 +0000 | |||
349 | @@ -16,14 +16,21 @@ | |||
350 | 16 | 16 | ||
351 | 17 | """Email Verification page UI.""" | 17 | """Email Verification page UI.""" |
352 | 18 | 18 | ||
354 | 19 | from ubuntu_sso.qt.gui import SSOWizardPage | 19 | from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage |
355 | 20 | from ubuntu_sso.qt.ui.error_message_ui import Ui_ErrorPage | ||
356 | 20 | from ubuntu_sso.utils.ui import ERROR | 21 | from ubuntu_sso.utils.ui import ERROR |
357 | 21 | 22 | ||
358 | 22 | 23 | ||
359 | 23 | class ErrorPage(SSOWizardPage): | 24 | class ErrorPage(SSOWizardPage): |
360 | 24 | """Widget used to show the diff errors.""" | 25 | """Widget used to show the diff errors.""" |
361 | 25 | 26 | ||
364 | 26 | def __init__(self, ui, *args, **kwargs): | 27 | ui_class = Ui_ErrorPage |
365 | 27 | super(ErrorPage, self).__init__(ui, *args, **kwargs) | 28 | next = None |
366 | 29 | |||
367 | 30 | def _set_translated_strings(self): | ||
368 | 31 | """Set the translated strings.""" | ||
369 | 32 | self.ui.error_message_label.setText(ERROR) | ||
370 | 33 | |||
371 | 34 | def _connect_ui(self): | ||
372 | 35 | """Connect the buttons to perform actions.""" | ||
373 | 28 | self.next = -1 | 36 | self.next = -1 |
374 | 29 | self.ui.error_message_label.setText(ERROR) | ||
375 | 30 | 37 | ||
376 | === modified file 'ubuntu_sso/qt/forgotten_password_page.py' | |||
377 | --- ubuntu_sso/qt/forgotten_password_page.py 2012-02-16 14:13:36 +0000 | |||
378 | +++ ubuntu_sso/qt/forgotten_password_page.py 2012-02-24 17:28:19 +0000 | |||
379 | @@ -19,10 +19,10 @@ | |||
380 | 19 | from functools import partial | 19 | from functools import partial |
381 | 20 | 20 | ||
382 | 21 | from PyQt4 import QtCore | 21 | from PyQt4 import QtCore |
383 | 22 | from twisted.internet import defer | ||
384 | 23 | 22 | ||
385 | 24 | from ubuntu_sso import NO_OP | 23 | from ubuntu_sso import NO_OP |
387 | 25 | from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage | 24 | from ubuntu_sso.qt.sso_wizard_page import SSOWizardEnhancedEditPage |
388 | 25 | from ubuntu_sso.qt.ui.forgotten_password_ui import Ui_ForgottenPasswordPage | ||
389 | 26 | from ubuntu_sso.utils.ui import ( | 26 | from ubuntu_sso.utils.ui import ( |
390 | 27 | EMAIL_LABEL, | 27 | EMAIL_LABEL, |
391 | 28 | is_correct_email, | 28 | is_correct_email, |
392 | @@ -37,29 +37,19 @@ | |||
393 | 37 | class ForgottenPasswordPage(SSOWizardEnhancedEditPage): | 37 | class ForgottenPasswordPage(SSOWizardEnhancedEditPage): |
394 | 38 | """Widget used to deal with users that forgot the password.""" | 38 | """Widget used to deal with users that forgot the password.""" |
395 | 39 | 39 | ||
396 | 40 | ui_class = Ui_ForgottenPasswordPage | ||
397 | 40 | passwordResetTokenSent = QtCore.pyqtSignal() | 41 | passwordResetTokenSent = QtCore.pyqtSignal() |
398 | 41 | 42 | ||
402 | 42 | def __init__(self, ui, *args, **kwargs): | 43 | @property |
403 | 43 | super(ForgottenPasswordPage, self).__init__(ui, *args, **kwargs) | 44 | def _signals(self): |
404 | 44 | self._signals = { | 45 | """The signals to connect to the backend.""" |
405 | 46 | result = { | ||
406 | 45 | 'PasswordResetTokenSent': | 47 | 'PasswordResetTokenSent': |
407 | 46 | self._filter_by_app_name(self.on_password_reset_token_sent), | 48 | self._filter_by_app_name(self.on_password_reset_token_sent), |
408 | 47 | 'PasswordResetError': | 49 | 'PasswordResetError': |
409 | 48 | self._filter_by_app_name(self.on_password_reset_error), | 50 | self._filter_by_app_name(self.on_password_reset_error), |
410 | 49 | } | 51 | } |
424 | 50 | self.setup_page() | 52 | return result |
412 | 51 | |||
413 | 52 | @defer.inlineCallbacks | ||
414 | 53 | def setup_page(self): | ||
415 | 54 | """Setup the widget components.""" | ||
416 | 55 | self.backend = yield self.get_backend() | ||
417 | 56 | self._setup_signals() | ||
418 | 57 | # hide the error label | ||
419 | 58 | self.try_again_widget.setVisible(False) | ||
420 | 59 | self._set_translated_strings() | ||
421 | 60 | self._connect_ui() | ||
422 | 61 | self._set_enhanced_line_edit() | ||
423 | 62 | self._register_fields() | ||
425 | 63 | 53 | ||
426 | 64 | @property | 54 | @property |
427 | 65 | def email_widget(self): | 55 | def email_widget(self): |
428 | @@ -144,8 +134,13 @@ | |||
429 | 144 | self.email_address_line_edit.textChanged.connect(self._validate) | 134 | self.email_address_line_edit.textChanged.connect(self._validate) |
430 | 145 | 135 | ||
431 | 146 | self.send_button.clicked.connect(self.request_new_password) | 136 | self.send_button.clicked.connect(self.request_new_password) |
432 | 137 | |||
433 | 138 | self.try_again_widget.setVisible(False) | ||
434 | 147 | self.try_again_button.clicked.connect(self.on_try_again) | 139 | self.try_again_button.clicked.connect(self.on_try_again) |
435 | 148 | 140 | ||
436 | 141 | self._set_enhanced_line_edit() | ||
437 | 142 | self._register_fields() | ||
438 | 143 | |||
439 | 149 | def request_new_password(self): | 144 | def request_new_password(self): |
440 | 150 | """Send the request password operation.""" | 145 | """Send the request password operation.""" |
441 | 151 | args = (self.app_name, self.email_address) | 146 | args = (self.app_name, self.email_address) |
442 | @@ -171,13 +166,11 @@ | |||
443 | 171 | self.try_again_widget.setVisible(False) | 166 | self.try_again_widget.setVisible(False) |
444 | 172 | self.email_widget.setVisible(True) | 167 | self.email_widget.setVisible(True) |
445 | 173 | 168 | ||
446 | 174 | # pylint: disable=W0212 | ||
447 | 175 | def on_password_reset_token_sent(self, app_name, result): | 169 | def on_password_reset_token_sent(self, app_name, result): |
448 | 176 | """Action taken when we managed to get the password reset done.""" | 170 | """Action taken when we managed to get the password reset done.""" |
449 | 177 | # ignore the result and move to the reset page | 171 | # ignore the result and move to the reset page |
450 | 178 | self.overlay.hide() | 172 | self.overlay.hide() |
451 | 179 | self.passwordResetTokenSent.emit() | 173 | self.passwordResetTokenSent.emit() |
452 | 180 | # pylint: enable=W0212 | ||
453 | 181 | 174 | ||
454 | 182 | def on_password_reset_error(self, app_name, error): | 175 | def on_password_reset_error(self, app_name, error): |
455 | 183 | """Action taken when there was an error requesting the reset.""" | 176 | """Action taken when there was an error requesting the reset.""" |
456 | 184 | 177 | ||
457 | === modified file 'ubuntu_sso/qt/loadingoverlay.py' | |||
458 | --- ubuntu_sso/qt/loadingoverlay.py 2012-02-22 16:58:08 +0000 | |||
459 | +++ ubuntu_sso/qt/loadingoverlay.py 2012-02-24 17:28:19 +0000 | |||
460 | @@ -1,5 +1,5 @@ | |||
461 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
463 | 2 | 2 | # | |
464 | 3 | # Copyright 2012 Canonical Ltd. | 3 | # Copyright 2012 Canonical Ltd. |
465 | 4 | # | 4 | # |
466 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
467 | @@ -45,7 +45,7 @@ | |||
468 | 45 | 45 | ||
469 | 46 | self.ui.label.setText(LOADING_OVERLAY) | 46 | self.ui.label.setText(LOADING_OVERLAY) |
470 | 47 | 47 | ||
472 | 48 | # Invalid name "paintEvent" | 48 | # Invalid name "paintEvent", "eventFilter", "showEvent", "timerEvent" |
473 | 49 | # pylint: disable=C0103 | 49 | # pylint: disable=C0103 |
474 | 50 | 50 | ||
475 | 51 | def paintEvent(self, event): | 51 | def paintEvent(self, event): |
476 | @@ -60,9 +60,6 @@ | |||
477 | 60 | painter.end() | 60 | painter.end() |
478 | 61 | QtGui.QFrame.paintEvent(self, event) | 61 | QtGui.QFrame.paintEvent(self, event) |
479 | 62 | 62 | ||
480 | 63 | # Invalid name "eventFilter" | ||
481 | 64 | # pylint: disable=C0103 | ||
482 | 65 | |||
483 | 66 | def eventFilter(self, obj, event): | 63 | def eventFilter(self, obj, event): |
484 | 67 | """Filter events from Frame content to draw the dot animation.""" | 64 | """Filter events from Frame content to draw the dot animation.""" |
485 | 68 | if getattr(self, 'ui', None) is not None and \ | 65 | if getattr(self, 'ui', None) is not None and \ |
486 | @@ -99,9 +96,6 @@ | |||
487 | 99 | painter.end() | 96 | painter.end() |
488 | 100 | return False | 97 | return False |
489 | 101 | 98 | ||
490 | 102 | # Invalid name "showEvent" | ||
491 | 103 | # pylint: disable=C0103 | ||
492 | 104 | |||
493 | 105 | def showEvent(self, event): | 99 | def showEvent(self, event): |
494 | 106 | """Start the dot animation.""" | 100 | """Start the dot animation.""" |
495 | 107 | self.ui.frm_box.installEventFilter(self) | 101 | self.ui.frm_box.installEventFilter(self) |
496 | @@ -112,9 +106,6 @@ | |||
497 | 112 | if not self.timer: | 106 | if not self.timer: |
498 | 113 | self.timer = self.startTimer(200) | 107 | self.timer = self.startTimer(200) |
499 | 114 | 108 | ||
500 | 115 | # Invalid name "timerEvent" | ||
501 | 116 | # pylint: disable=C0103 | ||
502 | 117 | |||
503 | 118 | def timerEvent(self, event): | 109 | def timerEvent(self, event): |
504 | 119 | """Execute a loop to update the dot animation.""" | 110 | """Execute a loop to update the dot animation.""" |
505 | 120 | if self.counter in (0, 4): | 111 | if self.counter in (0, 4): |
506 | @@ -124,3 +115,5 @@ | |||
507 | 124 | else: | 115 | else: |
508 | 125 | self.counter -= 1 | 116 | self.counter -= 1 |
509 | 126 | self.update() | 117 | self.update() |
510 | 118 | |||
511 | 119 | # pylint: enable=C0103 | ||
512 | 127 | 120 | ||
513 | === modified file 'ubuntu_sso/qt/network_detection_page.py' | |||
514 | --- ubuntu_sso/qt/network_detection_page.py 2012-02-22 16:58:08 +0000 | |||
515 | +++ ubuntu_sso/qt/network_detection_page.py 2012-02-24 17:28:19 +0000 | |||
516 | @@ -1,5 +1,5 @@ | |||
517 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
519 | 2 | 2 | # | |
520 | 3 | # Copyright 2012 Canonical Ltd. | 3 | # Copyright 2012 Canonical Ltd. |
521 | 4 | # | 4 | # |
522 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
523 | @@ -21,6 +21,7 @@ | |||
524 | 21 | 21 | ||
525 | 22 | from ubuntu_sso import networkstate | 22 | from ubuntu_sso import networkstate |
526 | 23 | 23 | ||
527 | 24 | from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage | ||
528 | 24 | from ubuntu_sso.qt.ui import network_detection_ui | 25 | from ubuntu_sso.qt.ui import network_detection_ui |
529 | 25 | from ubuntu_sso.utils.ui import ( | 26 | from ubuntu_sso.utils.ui import ( |
530 | 26 | CLOSE_AND_SETUP_LATER, | 27 | CLOSE_AND_SETUP_LATER, |
531 | @@ -30,21 +31,21 @@ | |||
532 | 30 | ) | 31 | ) |
533 | 31 | 32 | ||
534 | 32 | 33 | ||
536 | 33 | class NetworkDetectionPage(QtGui.QWizardPage): | 34 | class NetworkDetectionPage(SSOWizardPage): |
537 | 34 | 35 | ||
538 | 35 | """Widget to show if we don't detect a network connection.""" | 36 | """Widget to show if we don't detect a network connection.""" |
539 | 36 | 37 | ||
546 | 37 | def __init__(self, app_name, banner_pixmap=None, parent=None): | 38 | ui_class = network_detection_ui.Ui_Form |
547 | 38 | super(NetworkDetectionPage, self).__init__(parent) | 39 | |
548 | 39 | self.app_name = app_name | 40 | def __init__(self, *args, **kwargs): |
549 | 40 | self.setTitle(NETWORK_DETECTION_TITLE) | 41 | super(NetworkDetectionPage, self).__init__(*args, **kwargs) |
550 | 41 | self.ui = network_detection_ui.Ui_Form() | 42 | banner_pixmap = kwargs.pop('banner_pixmap', None) |
545 | 42 | self.ui.setupUi(self) | ||
551 | 43 | if banner_pixmap is not None: | 43 | if banner_pixmap is not None: |
552 | 44 | self.ui.image_label.setPixmap(banner_pixmap) | 44 | self.ui.image_label.setPixmap(banner_pixmap) |
553 | 45 | self.btn_try_again = None | 45 | self.btn_try_again = None |
554 | 46 | 46 | ||
555 | 47 | # pylint: disable=C0103 | 47 | # pylint: disable=C0103 |
556 | 48 | |||
557 | 48 | def initializePage(self): | 49 | def initializePage(self): |
558 | 49 | """Set UI details.""" | 50 | """Set UI details.""" |
559 | 50 | self.wizard()._next_id = None | 51 | self.wizard()._next_id = None |
560 | @@ -70,6 +71,7 @@ | |||
561 | 70 | self.btn_try_again.style().unpolish(self.btn_try_again) | 71 | self.btn_try_again.style().unpolish(self.btn_try_again) |
562 | 71 | self.btn_try_again.style().polish(self.btn_try_again) | 72 | self.btn_try_again.style().polish(self.btn_try_again) |
563 | 72 | self.wizard().customButtonClicked.connect(self.try_again) | 73 | self.wizard().customButtonClicked.connect(self.try_again) |
564 | 74 | |||
565 | 73 | # pylint: enable=C0103 | 75 | # pylint: enable=C0103 |
566 | 74 | 76 | ||
567 | 75 | @defer.inlineCallbacks | 77 | @defer.inlineCallbacks |
568 | @@ -81,3 +83,10 @@ | |||
569 | 81 | self.wizard()._next_id = self.wizard().SIGN_IN_PAGE_ID | 83 | self.wizard()._next_id = self.wizard().SIGN_IN_PAGE_ID |
570 | 82 | self.wizard().next() | 84 | self.wizard().next() |
571 | 83 | self.wizard()._next_id = None | 85 | self.wizard()._next_id = None |
572 | 86 | |||
573 | 87 | def _set_translated_strings(self): | ||
574 | 88 | """Implement in each child.""" | ||
575 | 89 | self.setTitle(NETWORK_DETECTION_TITLE) | ||
576 | 90 | |||
577 | 91 | def _connect_ui(self): | ||
578 | 92 | """Implement in each child.""" | ||
579 | 84 | 93 | ||
580 | === modified file 'ubuntu_sso/qt/reset_password_page.py' | |||
581 | --- ubuntu_sso/qt/reset_password_page.py 2012-02-16 14:13:36 +0000 | |||
582 | +++ ubuntu_sso/qt/reset_password_page.py 2012-02-24 17:28:19 +0000 | |||
583 | @@ -18,15 +18,14 @@ | |||
584 | 18 | 18 | ||
585 | 19 | from functools import partial | 19 | from functools import partial |
586 | 20 | 20 | ||
589 | 21 | from PyQt4.QtCore import SIGNAL | 21 | from PyQt4.QtCore import SIGNAL, pyqtSignal |
588 | 22 | from PyQt4.QtCore import pyqtSignal | ||
590 | 23 | from PyQt4.QtGui import QApplication | 22 | from PyQt4.QtGui import QApplication |
591 | 24 | from twisted.internet import defer | ||
592 | 25 | 23 | ||
593 | 26 | from ubuntu_sso import NO_OP | 24 | from ubuntu_sso import NO_OP |
597 | 27 | from ubuntu_sso.qt import build_general_error_message | 25 | from ubuntu_sso.logger import setup_logging |
598 | 28 | from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage | 26 | from ubuntu_sso.qt import build_general_error_message, common |
599 | 29 | from ubuntu_sso.qt import common | 27 | from ubuntu_sso.qt.sso_wizard_page import SSOWizardEnhancedEditPage |
600 | 28 | from ubuntu_sso.qt.ui.reset_password_ui import Ui_ResetPasswordPage | ||
601 | 30 | from ubuntu_sso.utils.ui import ( | 29 | from ubuntu_sso.utils.ui import ( |
602 | 31 | is_min_required_password, | 30 | is_min_required_password, |
603 | 32 | PASSWORD1_ENTRY, | 31 | PASSWORD1_ENTRY, |
604 | @@ -37,7 +36,6 @@ | |||
605 | 37 | RESET_TITLE, | 36 | RESET_TITLE, |
606 | 38 | RESET_SUBTITLE, | 37 | RESET_SUBTITLE, |
607 | 39 | ) | 38 | ) |
608 | 40 | from ubuntu_sso.logger import setup_logging | ||
609 | 41 | 39 | ||
610 | 42 | 40 | ||
611 | 43 | logger = setup_logging('ubuntu_sso.reset_password_page') | 41 | logger = setup_logging('ubuntu_sso.reset_password_page') |
612 | @@ -46,35 +44,19 @@ | |||
613 | 46 | class ResetPasswordPage(SSOWizardEnhancedEditPage): | 44 | class ResetPasswordPage(SSOWizardEnhancedEditPage): |
614 | 47 | """Widget used to allow the user change his password.""" | 45 | """Widget used to allow the user change his password.""" |
615 | 48 | 46 | ||
616 | 47 | ui_class = Ui_ResetPasswordPage | ||
617 | 49 | passwordChanged = pyqtSignal('QString') | 48 | passwordChanged = pyqtSignal('QString') |
618 | 50 | 49 | ||
631 | 51 | def __init__(self, ui, app_name=None, parent=None): | 50 | @property |
632 | 52 | """Create a new instance.""" | 51 | def _signals(self): |
633 | 53 | super(ResetPasswordPage, self).__init__(ui, app_name, parent) | 52 | """The signals to connect to the backend.""" |
634 | 54 | self.ui.password_line_edit.textEdited.connect( | 53 | result = { |
623 | 55 | lambda: common.password_assistance(self.ui.password_line_edit, | ||
624 | 56 | self.ui.password_assistance, | ||
625 | 57 | common.NORMAL)) | ||
626 | 58 | self.ui.confirm_password_line_edit.textEdited.connect( | ||
627 | 59 | lambda: common.password_check_match(self.ui.password_line_edit, | ||
628 | 60 | self.ui.confirm_password_line_edit, | ||
629 | 61 | self.ui.password_assistance)) | ||
630 | 62 | self._signals = { | ||
635 | 63 | 'PasswordChanged': | 54 | 'PasswordChanged': |
636 | 64 | self._filter_by_app_name(self.on_password_changed), | 55 | self._filter_by_app_name(self.on_password_changed), |
637 | 65 | 'PasswordChangeError': | 56 | 'PasswordChangeError': |
638 | 66 | self._filter_by_app_name(self.on_password_change_error), | 57 | self._filter_by_app_name(self.on_password_change_error), |
639 | 67 | } | 58 | } |
650 | 68 | self.setup_page() | 59 | return result |
641 | 69 | |||
642 | 70 | @defer.inlineCallbacks | ||
643 | 71 | def setup_page(self): | ||
644 | 72 | """Setup the widget components.""" | ||
645 | 73 | self.backend = yield self.get_backend() | ||
646 | 74 | self._setup_signals() | ||
647 | 75 | self._set_translated_strings() | ||
648 | 76 | self._connect_ui() | ||
649 | 77 | self._add_line_edits_validations() | ||
651 | 78 | 60 | ||
652 | 79 | def focus_changed(self, old, now): | 61 | def focus_changed(self, old, now): |
653 | 80 | """Check who has the focus to activate password popups if necessary.""" | 62 | """Check who has the focus to activate password popups if necessary.""" |
654 | @@ -136,6 +118,15 @@ | |||
655 | 136 | 118 | ||
656 | 137 | def _connect_ui(self): | 119 | def _connect_ui(self): |
657 | 138 | """Connect the different ui signals.""" | 120 | """Connect the different ui signals.""" |
658 | 121 | self.ui.password_line_edit.textEdited.connect( | ||
659 | 122 | lambda: common.password_assistance(self.ui.password_line_edit, | ||
660 | 123 | self.ui.password_assistance, | ||
661 | 124 | common.NORMAL)) | ||
662 | 125 | self.ui.confirm_password_line_edit.textEdited.connect( | ||
663 | 126 | lambda: common.password_check_match(self.ui.password_line_edit, | ||
664 | 127 | self.ui.confirm_password_line_edit, | ||
665 | 128 | self.ui.password_assistance)) | ||
666 | 129 | |||
667 | 139 | self.ui.reset_password_button.clicked.connect( | 130 | self.ui.reset_password_button.clicked.connect( |
668 | 140 | self.set_new_password) | 131 | self.set_new_password) |
669 | 141 | self.ui.reset_code_line_edit.textChanged.connect(self._validate) | 132 | self.ui.reset_code_line_edit.textChanged.connect(self._validate) |
670 | @@ -143,6 +134,8 @@ | |||
671 | 143 | self.ui.confirm_password_line_edit.textChanged.connect( | 134 | self.ui.confirm_password_line_edit.textChanged.connect( |
672 | 144 | self._validate) | 135 | self._validate) |
673 | 145 | 136 | ||
674 | 137 | self._add_line_edits_validations() | ||
675 | 138 | |||
676 | 146 | def _validate(self): | 139 | def _validate(self): |
677 | 147 | """Enable the submit button if data is valid.""" | 140 | """Enable the submit button if data is valid.""" |
678 | 148 | enabled = True | 141 | enabled = True |
679 | 149 | 142 | ||
680 | === modified file 'ubuntu_sso/qt/setup_account_page.py' | |||
681 | --- ubuntu_sso/qt/setup_account_page.py 2012-02-24 14:58:30 +0000 | |||
682 | +++ ubuntu_sso/qt/setup_account_page.py 2012-02-24 17:28:19 +0000 | |||
683 | @@ -29,13 +29,16 @@ | |||
684 | 29 | # pylint: enable=F0401 | 29 | # pylint: enable=F0401 |
685 | 30 | 30 | ||
686 | 31 | from PyQt4 import QtGui, QtCore | 31 | from PyQt4 import QtGui, QtCore |
687 | 32 | from twisted.internet import defer | ||
688 | 33 | 32 | ||
689 | 34 | from ubuntu_sso import NO_OP | 33 | from ubuntu_sso import NO_OP |
694 | 35 | from ubuntu_sso.qt import build_general_error_message | 34 | from ubuntu_sso.logger import setup_logging |
695 | 36 | from ubuntu_sso.qt import common | 35 | from ubuntu_sso.qt import ( |
696 | 37 | from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage | 36 | build_general_error_message, |
697 | 38 | from ubuntu_sso.qt import enhanced_check_box | 37 | common, |
698 | 38 | enhanced_check_box, | ||
699 | 39 | ) | ||
700 | 40 | from ubuntu_sso.qt.sso_wizard_page import SSOWizardEnhancedEditPage | ||
701 | 41 | from ubuntu_sso.qt.ui.setup_account_ui import Ui_SetUpAccountPage | ||
702 | 39 | from ubuntu_sso.utils.ui import ( | 42 | from ubuntu_sso.utils.ui import ( |
703 | 40 | AGREE_TO_PRIVACY_POLICY, | 43 | AGREE_TO_PRIVACY_POLICY, |
704 | 41 | AGREE_TO_TERMS, | 44 | AGREE_TO_TERMS, |
705 | @@ -71,12 +74,10 @@ | |||
706 | 71 | TERMS_TEXT, | 74 | TERMS_TEXT, |
707 | 72 | TITLE, | 75 | TITLE, |
708 | 73 | ) | 76 | ) |
709 | 74 | from ubuntu_sso.logger import setup_logging | ||
710 | 75 | 77 | ||
711 | 76 | 78 | ||
712 | 77 | logger = setup_logging('ubuntu_sso.setup_account_page') | 79 | logger = setup_logging('ubuntu_sso.setup_account_page') |
713 | 78 | 80 | ||
714 | 79 | # pylint: disable=C0103 | ||
715 | 80 | ERROR = u'<font color="#df2d1f"><b> %s </b></font>' | 81 | ERROR = u'<font color="#df2d1f"><b> %s </b></font>' |
716 | 81 | TITLE_STYLE = "<span style=\"font-size:24px\">%s</span>" | 82 | TITLE_STYLE = "<span style=\"font-size:24px\">%s</span>" |
717 | 82 | 83 | ||
718 | @@ -92,47 +93,21 @@ | |||
719 | 92 | class SetupAccountPage(SSOWizardEnhancedEditPage): | 93 | class SetupAccountPage(SSOWizardEnhancedEditPage): |
720 | 93 | """Customized Setup Account page for SSO.""" | 94 | """Customized Setup Account page for SSO.""" |
721 | 94 | 95 | ||
722 | 96 | ui_class = Ui_SetUpAccountPage | ||
723 | 95 | userRegistered = QtCore.pyqtSignal('QString', 'QString') | 97 | userRegistered = QtCore.pyqtSignal('QString', 'QString') |
724 | 96 | 98 | ||
728 | 97 | def __init__(self, ui, subtitle, toc_link, policy_link, *args, **kwargs): | 99 | def __init__(self, *args, **kwargs): |
729 | 98 | super(SetupAccountPage, self).__init__(ui, *args, **kwargs) | 100 | self.captcha_file = None |
727 | 99 | self._subtitle = subtitle | ||
730 | 100 | self.captcha_id = None | 101 | self.captcha_id = None |
763 | 101 | self.captcha_file = None | 102 | self.captcha_received = False |
732 | 102 | self.ui.captcha_view.setPixmap(QtGui.QPixmap()) | ||
733 | 103 | self.ui.password_edit.textEdited.connect( | ||
734 | 104 | lambda: common.password_assistance(self.ui.password_edit, | ||
735 | 105 | self.ui.password_assistance, | ||
736 | 106 | common.NORMAL)) | ||
737 | 107 | |||
738 | 108 | if toc_link: | ||
739 | 109 | terms_links = TERMS_LINK.format(toc_link=toc_link, | ||
740 | 110 | terms_text=TERMS_TEXT) | ||
741 | 111 | if policy_link: | ||
742 | 112 | privacy_policy_link = PRIVACY_POLICY_LINK.format( | ||
743 | 113 | policy_link=policy_link, | ||
744 | 114 | privacy_policy_text=PRIVACY_POLICY_TEXT) | ||
745 | 115 | |||
746 | 116 | terms = '' | ||
747 | 117 | if toc_link and policy_link: | ||
748 | 118 | terms = AGREE_TO_TERMS_AND_PRIVACY_POLICY.format( | ||
749 | 119 | app_name=self.app_name, | ||
750 | 120 | terms_and_conditions=terms_links, | ||
751 | 121 | privacy_policy=privacy_policy_link) | ||
752 | 122 | elif toc_link: | ||
753 | 123 | terms = AGREE_TO_TERMS.format(app_name=self.app_name, | ||
754 | 124 | terms_and_conditions=terms_links) | ||
755 | 125 | elif policy_link: | ||
756 | 126 | terms = AGREE_TO_PRIVACY_POLICY.format(app_name=self.app_name, | ||
757 | 127 | privacy_policy=privacy_policy_link) | ||
758 | 128 | |||
759 | 129 | self.terms_checkbox = enhanced_check_box.EnhancedCheckBox(terms) | ||
760 | 130 | self.ui.hlayout_check.addWidget(self.terms_checkbox) | ||
761 | 131 | self.terms_checkbox.setVisible(bool(toc_link or policy_link)) | ||
762 | 132 | |||
764 | 133 | self.set_up_button = None | 103 | self.set_up_button = None |
767 | 134 | self.captcha_received = False | 104 | self.terms_checkbox = None |
768 | 135 | self._signals = { | 105 | super(SetupAccountPage, self).__init__(*args, **kwargs) |
769 | 106 | |||
770 | 107 | @property | ||
771 | 108 | def _signals(self): | ||
772 | 109 | """The signals to connect to the backend.""" | ||
773 | 110 | result = { | ||
774 | 136 | 'CaptchaGenerated': | 111 | 'CaptchaGenerated': |
775 | 137 | self._filter_by_app_name(self.on_captcha_generated), | 112 | self._filter_by_app_name(self.on_captcha_generated), |
776 | 138 | 'CaptchaGenerationError': | 113 | 'CaptchaGenerationError': |
777 | @@ -142,31 +117,16 @@ | |||
778 | 142 | 'UserRegistrationError': | 117 | 'UserRegistrationError': |
779 | 143 | self._filter_by_app_name(self.on_user_registration_error), | 118 | self._filter_by_app_name(self.on_user_registration_error), |
780 | 144 | } | 119 | } |
795 | 145 | self.setup_page() | 120 | return result |
782 | 146 | |||
783 | 147 | @defer.inlineCallbacks | ||
784 | 148 | def setup_page(self): | ||
785 | 149 | """Setup the widget components.""" | ||
786 | 150 | # request the backend to be used with the ui | ||
787 | 151 | self.backend = yield self.get_backend() | ||
788 | 152 | # set the callbacks for the captcha generation | ||
789 | 153 | self._setup_signals() | ||
790 | 154 | self._connect_ui_elements() | ||
791 | 155 | self._refresh_captcha() | ||
792 | 156 | self._set_translated_strings() | ||
793 | 157 | self._set_line_edits_validations() | ||
794 | 158 | self._register_fields() | ||
796 | 159 | 121 | ||
797 | 160 | # Invalid name "initializePage" | 122 | # Invalid name "initializePage" |
798 | 161 | # pylint: disable=C0103 | 123 | # pylint: disable=C0103 |
799 | 162 | 124 | ||
800 | 163 | def initializePage(self): | 125 | def initializePage(self): |
801 | 164 | """Setup UI details.""" | 126 | """Setup UI details.""" |
802 | 165 | # We need to override some texts from SSO | ||
803 | 166 | # to match our spec | ||
804 | 167 | title_page = TITLE_STYLE % TITLE.format(app_name=self.app_name) | 127 | title_page = TITLE_STYLE % TITLE.format(app_name=self.app_name) |
805 | 168 | self.setTitle(title_page) | 128 | self.setTitle(title_page) |
807 | 169 | self.setSubTitle(self._subtitle) | 129 | self.setSubTitle(self.help_text) |
808 | 170 | # Set Setup Account button | 130 | # Set Setup Account button |
809 | 171 | self.wizard().setOption(QtGui.QWizard.HaveCustomButton3, True) | 131 | self.wizard().setOption(QtGui.QWizard.HaveCustomButton3, True) |
810 | 172 | try: | 132 | try: |
811 | @@ -199,7 +159,8 @@ | |||
812 | 199 | self.ui.confirm_email_assistance.setVisible(False) | 159 | self.ui.confirm_email_assistance.setVisible(False) |
813 | 200 | self.ui.password_assistance.setVisible(False) | 160 | self.ui.password_assistance.setVisible(False) |
814 | 201 | self.ui.refresh_label.setVisible(True) | 161 | self.ui.refresh_label.setVisible(True) |
816 | 202 | #pylint: enable=C0103 | 162 | |
817 | 163 | # pylint: enable=C0103 | ||
818 | 203 | 164 | ||
819 | 204 | def _set_translated_strings(self): | 165 | def _set_translated_strings(self): |
820 | 205 | """Set the strings.""" | 166 | """Set the strings.""" |
821 | @@ -218,6 +179,33 @@ | |||
822 | 218 | self.ui.refresh_label.setText(CAPTCHA_RELOAD_MESSAGE % | 179 | self.ui.refresh_label.setText(CAPTCHA_RELOAD_MESSAGE % |
823 | 219 | {'reload_link': link}) | 180 | {'reload_link': link}) |
824 | 220 | 181 | ||
825 | 182 | if self.tc_url: | ||
826 | 183 | terms_links = TERMS_LINK.format(toc_link=self.tc_url, | ||
827 | 184 | terms_text=TERMS_TEXT) | ||
828 | 185 | if self.policy_url: | ||
829 | 186 | privacy_policy_link = PRIVACY_POLICY_LINK.format( | ||
830 | 187 | policy_link=self.policy_url, | ||
831 | 188 | privacy_policy_text=PRIVACY_POLICY_TEXT) | ||
832 | 189 | |||
833 | 190 | terms = '' | ||
834 | 191 | if self.tc_url and self.policy_url: | ||
835 | 192 | terms = AGREE_TO_TERMS_AND_PRIVACY_POLICY.format( | ||
836 | 193 | app_name=self.app_name, | ||
837 | 194 | terms_and_conditions=terms_links, | ||
838 | 195 | privacy_policy=privacy_policy_link) | ||
839 | 196 | elif self.tc_url: | ||
840 | 197 | terms = AGREE_TO_TERMS.format(app_name=self.app_name, | ||
841 | 198 | terms_and_conditions=terms_links) | ||
842 | 199 | elif self.policy_url: | ||
843 | 200 | terms = AGREE_TO_PRIVACY_POLICY.format(app_name=self.app_name, | ||
844 | 201 | privacy_policy=privacy_policy_link) | ||
845 | 202 | |||
846 | 203 | self.terms_checkbox = enhanced_check_box.EnhancedCheckBox(terms) | ||
847 | 204 | self.ui.hlayout_check.addWidget(self.terms_checkbox) | ||
848 | 205 | self.terms_checkbox.setVisible(bool(self.tc_url or self.policy_url)) | ||
849 | 206 | |||
850 | 207 | self._register_fields() | ||
851 | 208 | |||
852 | 221 | def _set_line_edits_validations(self): | 209 | def _set_line_edits_validations(self): |
853 | 222 | """Set the validations to be performed on the edits.""" | 210 | """Set the validations to be performed on the edits.""" |
854 | 223 | logger.debug('SetUpAccountPage._set_line_edits_validations') | 211 | logger.debug('SetUpAccountPage._set_line_edits_validations') |
855 | @@ -240,9 +228,17 @@ | |||
856 | 240 | self.ui.password_edit.textChanged.connect( | 228 | self.ui.password_edit.textChanged.connect( |
857 | 241 | self.ui.confirm_password_edit.textChanged.emit) | 229 | self.ui.confirm_password_edit.textChanged.emit) |
858 | 242 | 230 | ||
860 | 243 | def _connect_ui_elements(self): | 231 | def _connect_ui(self): |
861 | 244 | """Set the connection of signals.""" | 232 | """Set the connection of signals.""" |
863 | 245 | logger.debug('SetUpAccountPage._connect_ui_elements') | 233 | logger.debug('SetUpAccountPage._connect_ui') |
864 | 234 | self._set_line_edits_validations() | ||
865 | 235 | |||
866 | 236 | self.ui.captcha_view.setPixmap(QtGui.QPixmap()) | ||
867 | 237 | self.ui.password_edit.textEdited.connect( | ||
868 | 238 | lambda: common.password_assistance(self.ui.password_edit, | ||
869 | 239 | self.ui.password_assistance, | ||
870 | 240 | common.NORMAL)) | ||
871 | 241 | |||
872 | 246 | self.ui.refresh_label.linkActivated.connect(lambda url: \ | 242 | self.ui.refresh_label.linkActivated.connect(lambda url: \ |
873 | 247 | self._refresh_captcha()) | 243 | self._refresh_captcha()) |
874 | 248 | # We need to check if we enable the button on many signals | 244 | # We need to check if we enable the button on many signals |
875 | @@ -257,6 +253,8 @@ | |||
876 | 257 | self._enable_setup_button) | 253 | self._enable_setup_button) |
877 | 258 | self.terms_checkbox.stateChanged.connect(self._enable_setup_button) | 254 | self.terms_checkbox.stateChanged.connect(self._enable_setup_button) |
878 | 259 | 255 | ||
879 | 256 | self._refresh_captcha() | ||
880 | 257 | |||
881 | 260 | def _enable_setup_button(self): | 258 | def _enable_setup_button(self): |
882 | 261 | """Only enable the setup button if the form is valid.""" | 259 | """Only enable the setup button if the form is valid.""" |
883 | 262 | name = unicode(self.ui.name_edit.text()).strip() | 260 | name = unicode(self.ui.name_edit.text()).strip() |
884 | @@ -393,7 +391,6 @@ | |||
885 | 393 | self.message_box.critical(self, self.app_name, '\n'.join(messages)) | 391 | self.message_box.critical(self, self.app_name, '\n'.join(messages)) |
886 | 394 | return condition | 392 | return condition |
887 | 395 | 393 | ||
888 | 396 | # pylint: disable=W0212 | ||
889 | 397 | def set_next_validation(self): | 394 | def set_next_validation(self): |
890 | 398 | """Set the validation as the next page.""" | 395 | """Set the validation as the next page.""" |
891 | 399 | logger.debug('SetUpAccountPage.set_next_validation') | 396 | logger.debug('SetUpAccountPage.set_next_validation') |
892 | @@ -413,7 +410,6 @@ | |||
893 | 413 | f(*args, reply_handler=NO_OP, error_handler=error_handler) | 410 | f(*args, reply_handler=NO_OP, error_handler=error_handler) |
894 | 414 | # Update validation page's title, which contains the email | 411 | # Update validation page's title, which contains the email |
895 | 415 | self.userRegistered.emit(email, password) | 412 | self.userRegistered.emit(email, password) |
896 | 416 | # pylint: enable=W0212 | ||
897 | 417 | 413 | ||
898 | 418 | def is_correct_email(self, email_address): | 414 | def is_correct_email(self, email_address): |
899 | 419 | """Return if the email is correct.""" | 415 | """Return if the email is correct.""" |
900 | @@ -484,7 +480,8 @@ | |||
901 | 484 | label.setText(ERROR % msg) | 480 | label.setText(ERROR % msg) |
902 | 485 | label.setVisible(True) | 481 | label.setVisible(True) |
903 | 486 | 482 | ||
905 | 487 | #pylint: disable=C0103 | 483 | # pylint: disable=C0103 |
906 | 484 | |||
907 | 488 | def showEvent(self, event): | 485 | def showEvent(self, event): |
908 | 489 | """Set set_up_button as default button when the page is shown.""" | 486 | """Set set_up_button as default button when the page is shown.""" |
909 | 490 | # This method should stays here because if we move it to initializePage | 487 | # This method should stays here because if we move it to initializePage |
910 | @@ -514,7 +511,8 @@ | |||
911 | 514 | except TypeError: | 511 | except TypeError: |
912 | 515 | pass | 512 | pass |
913 | 516 | super(SetupAccountPage, self).hideEvent(event) | 513 | super(SetupAccountPage, self).hideEvent(event) |
915 | 517 | #pylint: enable=C0103 | 514 | |
916 | 515 | # pylint: enable=C0103 | ||
917 | 518 | 516 | ||
918 | 519 | def on_captcha_refreshing(self): | 517 | def on_captcha_refreshing(self): |
919 | 520 | """Show overlay when captcha is refreshing.""" | 518 | """Show overlay when captcha is refreshing.""" |
920 | 521 | 519 | ||
921 | === removed file 'ubuntu_sso/qt/sign_in_page.py' | |||
922 | --- ubuntu_sso/qt/sign_in_page.py 2012-02-17 18:43:17 +0000 | |||
923 | +++ ubuntu_sso/qt/sign_in_page.py 1970-01-01 00:00:00 +0000 | |||
924 | @@ -1,97 +0,0 @@ | |||
925 | 1 | # -*- coding: utf-8 -*- | ||
926 | 2 | # | ||
927 | 3 | # Copyright 2012 Canonical Ltd. | ||
928 | 4 | # | ||
929 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
930 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
931 | 7 | # by the Free Software Foundation. | ||
932 | 8 | # | ||
933 | 9 | # This program is distributed in the hope that it will be useful, but | ||
934 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
935 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
936 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
937 | 13 | # | ||
938 | 14 | # You should have received a copy of the GNU General Public License along | ||
939 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
940 | 16 | |||
941 | 17 | """Page to allow the user to sign in.""" | ||
942 | 18 | |||
943 | 19 | from PyQt4 import QtGui, QtCore | ||
944 | 20 | |||
945 | 21 | from ubuntu_sso.qt.gui import SSOWizardPage | ||
946 | 22 | from ubuntu_sso.logger import setup_logging | ||
947 | 23 | from ubuntu_sso.utils.ui import ( | ||
948 | 24 | CLOSE_AND_SETUP_LATER, | ||
949 | 25 | EXISTING_ACCOUNT_CHOICE_BUTTON, | ||
950 | 26 | SET_UP_ACCOUNT_CHOICE_BUTTON, | ||
951 | 27 | ) | ||
952 | 28 | |||
953 | 29 | |||
954 | 30 | logger = setup_logging('ubuntu_sso.sing_in_page') | ||
955 | 31 | |||
956 | 32 | |||
957 | 33 | class SignInPage(SSOWizardPage): | ||
958 | 34 | """Wizard Page that lets the user Sign into Ubuntu Single Sign On.""" | ||
959 | 35 | |||
960 | 36 | existingAccountSelected = QtCore.pyqtSignal() | ||
961 | 37 | newAccountSelected = QtCore.pyqtSignal() | ||
962 | 38 | singInCanceled = QtCore.pyqtSignal() | ||
963 | 39 | |||
964 | 40 | def __init__(self, ui, image_pixmap, *args, **kwargs): | ||
965 | 41 | super(SignInPage, self).__init__(ui, *args, **kwargs) | ||
966 | 42 | self.ui.image_label.setPixmap(image_pixmap) | ||
967 | 43 | self._set_up_translated_strings() | ||
968 | 44 | self._connect_buttons() | ||
969 | 45 | |||
970 | 46 | def _set_up_translated_strings(self): | ||
971 | 47 | """Set the correct strings for the UI.""" | ||
972 | 48 | logger.debug('SingInPage._set_up_translated_strings') | ||
973 | 49 | self.ui.message_label.setText('') | ||
974 | 50 | self.ui.existing_account_button.setText( | ||
975 | 51 | EXISTING_ACCOUNT_CHOICE_BUTTON) | ||
976 | 52 | self.ui.setup_account_button.setText( | ||
977 | 53 | SET_UP_ACCOUNT_CHOICE_BUTTON) | ||
978 | 54 | |||
979 | 55 | def _connect_buttons(self): | ||
980 | 56 | """Connect the buttons to the actions to perform.""" | ||
981 | 57 | logger.debug('SingInPage._connect_buttons') | ||
982 | 58 | self.ui.existing_account_button.clicked.connect( | ||
983 | 59 | self._set_next_existing) | ||
984 | 60 | self.ui.setup_account_button.clicked.connect(self._set_next_new) | ||
985 | 61 | |||
986 | 62 | def _set_next_existing(self): | ||
987 | 63 | """Set the next id and fire signal.""" | ||
988 | 64 | logger.debug('SignInPage._set_next_existing') | ||
989 | 65 | self.existingAccountSelected.emit() | ||
990 | 66 | |||
991 | 67 | def _set_next_new(self): | ||
992 | 68 | """Set the next id and fire signal.""" | ||
993 | 69 | logger.debug('SignInPage._set_next_new') | ||
994 | 70 | self.newAccountSelected.emit() | ||
995 | 71 | |||
996 | 72 | # Invalid names of Qt-inherited methods | ||
997 | 73 | # pylint: disable=C0103 | ||
998 | 74 | |||
999 | 75 | def initializePage(self): | ||
1000 | 76 | """Setup UI details.""" | ||
1001 | 77 | self.ui.cancel_button.setText(CLOSE_AND_SETUP_LATER) | ||
1002 | 78 | self.ui.cancel_button.clicked.connect(self.singInCanceled.emit) | ||
1003 | 79 | # Layout without custom button 1, | ||
1004 | 80 | # without finish button | ||
1005 | 81 | # without cancel | ||
1006 | 82 | self.wizard().setButtonLayout([ | ||
1007 | 83 | QtGui.QWizard.Stretch, | ||
1008 | 84 | QtGui.QWizard.NextButton]) | ||
1009 | 85 | |||
1010 | 86 | def showEvent(self, event): | ||
1011 | 87 | """Set existing_account_button as default when the page is shown.""" | ||
1012 | 88 | super(SignInPage, self).showEvent(event) | ||
1013 | 89 | self.ui.existing_account_button.setDefault(True) | ||
1014 | 90 | self.ui.existing_account_button.style().unpolish( | ||
1015 | 91 | self.ui.existing_account_button) | ||
1016 | 92 | self.ui.existing_account_button.style().polish( | ||
1017 | 93 | self.ui.existing_account_button) | ||
1018 | 94 | |||
1019 | 95 | def nextId(self): | ||
1020 | 96 | """Provide the next id.""" | ||
1021 | 97 | return self.next | ||
1022 | 98 | 0 | ||
1023 | === renamed file 'ubuntu_sso/qt/gui.py' => 'ubuntu_sso/qt/sso_wizard_page.py' | |||
1024 | --- ubuntu_sso/qt/gui.py 2012-02-23 20:16:46 +0000 | |||
1025 | +++ ubuntu_sso/qt/sso_wizard_page.py 2012-02-24 17:28:19 +0000 | |||
1026 | @@ -35,13 +35,13 @@ | |||
1027 | 35 | from twisted.internet import defer | 35 | from twisted.internet import defer |
1028 | 36 | 36 | ||
1029 | 37 | from ubuntu_sso import main | 37 | from ubuntu_sso import main |
1030 | 38 | from ubuntu_sso.logger import setup_logging | ||
1031 | 38 | from ubuntu_sso.qt import PREFERED_UI_SIZE | 39 | from ubuntu_sso.qt import PREFERED_UI_SIZE |
1032 | 39 | from ubuntu_sso.qt.loadingoverlay import LoadingOverlay | 40 | from ubuntu_sso.qt.loadingoverlay import LoadingOverlay |
1033 | 40 | from ubuntu_sso.logger import setup_logging | ||
1034 | 41 | from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR | 41 | from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR |
1035 | 42 | 42 | ||
1036 | 43 | 43 | ||
1038 | 44 | logger = setup_logging('ubuntu_sso.gui') | 44 | logger = setup_logging('ubuntu_sso.sso_wizard_page') |
1039 | 45 | 45 | ||
1040 | 46 | 46 | ||
1041 | 47 | class Header(QFrame): | 47 | class Header(QFrame): |
1042 | @@ -92,32 +92,53 @@ | |||
1043 | 92 | class SSOWizardPage(QWizardPage): | 92 | class SSOWizardPage(QWizardPage): |
1044 | 93 | """Root class for all wizard pages.""" | 93 | """Root class for all wizard pages.""" |
1045 | 94 | 94 | ||
1047 | 95 | def __init__(self, ui, app_name=None, title='', subtitle='', parent=None): | 95 | ui_class = None |
1048 | 96 | _signals = {} # override in children | ||
1049 | 97 | |||
1050 | 98 | def __init__(self, app_name, **kwargs): | ||
1051 | 96 | """Create a new instance.""" | 99 | """Create a new instance.""" |
1055 | 97 | super(SSOWizardPage, self).__init__(parent) | 100 | parent = kwargs.pop('parent', None) |
1056 | 98 | self.ui = ui | 101 | super(SSOWizardPage, self).__init__(parent=parent) |
1057 | 99 | self.ui.setupUi(self) | 102 | |
1058 | 103 | self.ui = None | ||
1059 | 104 | if self.ui_class is not None: | ||
1060 | 105 | # self.ui_class is not callable, pylint: disable=E1102 | ||
1061 | 106 | self.ui = self.ui_class() | ||
1062 | 107 | self.ui.setupUi(self) | ||
1063 | 108 | |||
1064 | 100 | self.overlay = LoadingOverlay(self) | 109 | self.overlay = LoadingOverlay(self) |
1065 | 101 | self.overlay.hide() | 110 | self.overlay.hide() |
1066 | 111 | |||
1067 | 112 | # store common useful data provided by the app | ||
1068 | 102 | self.app_name = app_name | 113 | self.app_name = app_name |
1069 | 114 | self.ping_url = kwargs.get('ping_url', '') | ||
1070 | 115 | self.tc_url = kwargs.get('tc_url', '') | ||
1071 | 116 | self.policy_url = kwargs.get('policy_url', '') | ||
1072 | 117 | self.help_text = kwargs.get('help_text', '') | ||
1073 | 118 | |||
1074 | 103 | self.header = Header() | 119 | self.header = Header() |
1077 | 104 | self.header.set_title(title) | 120 | self.header.set_title(title='') |
1078 | 105 | self.header.set_subtitle(subtitle) | 121 | self.header.set_subtitle(subtitle='') |
1079 | 106 | self.layout().insertWidget(0, self.header) | 122 | self.layout().insertWidget(0, self.header) |
1080 | 123 | |||
1081 | 107 | self.message_box = QMessageBox | 124 | self.message_box = QMessageBox |
1082 | 108 | self._signals = {} | ||
1083 | 109 | self._signals_receivers = {} | 125 | self._signals_receivers = {} |
1084 | 110 | self.backend = None | 126 | self.backend = None |
1085 | 111 | 127 | ||
1086 | 128 | self.setup_page() | ||
1087 | 129 | |||
1088 | 112 | @defer.inlineCallbacks | 130 | @defer.inlineCallbacks |
1095 | 113 | def get_backend(self): | 131 | def setup_page(self): |
1096 | 114 | """Return the backend used by the controller.""" | 132 | """Setup the widget components.""" |
1097 | 115 | if self.backend is None: | 133 | client = yield main.get_sso_client() |
1098 | 116 | client = yield main.get_sso_client() | 134 | self.backend = client.sso_login |
1099 | 117 | self.backend = client.sso_login | 135 | |
1100 | 118 | defer.returnValue(self.backend) | 136 | self._setup_signals() |
1101 | 137 | self._set_translated_strings() | ||
1102 | 138 | self._connect_ui() | ||
1103 | 119 | 139 | ||
1104 | 120 | # pylint: disable=C0103 | 140 | # pylint: disable=C0103 |
1105 | 141 | |||
1106 | 121 | def resizeEvent(self, event): | 142 | def resizeEvent(self, event): |
1107 | 122 | """Resize the overlay to fit all the widget.""" | 143 | """Resize the overlay to fit all the widget.""" |
1108 | 123 | QWizardPage.resizeEvent(self, event) | 144 | QWizardPage.resizeEvent(self, event) |
1109 | @@ -130,6 +151,7 @@ | |||
1110 | 130 | def setSubTitle(self, subtitle=''): | 151 | def setSubTitle(self, subtitle=''): |
1111 | 131 | """Set the Wizard Page Subtitle.""" | 152 | """Set the Wizard Page Subtitle.""" |
1112 | 132 | self.header.set_subtitle(subtitle) | 153 | self.header.set_subtitle(subtitle) |
1113 | 154 | |||
1114 | 133 | # pylint: enable=C0103 | 155 | # pylint: enable=C0103 |
1115 | 134 | 156 | ||
1116 | 135 | def _filter_by_app_name(self, f): | 157 | def _filter_by_app_name(self, f): |
1117 | @@ -160,6 +182,14 @@ | |||
1118 | 160 | match = self.backend.connect_to_signal(signal, method) | 182 | match = self.backend.connect_to_signal(signal, method) |
1119 | 161 | self._signals_receivers[signal] = match | 183 | self._signals_receivers[signal] = match |
1120 | 162 | 184 | ||
1121 | 185 | def _set_translated_strings(self): | ||
1122 | 186 | """Implement in each child.""" | ||
1123 | 187 | raise NotImplementedError() | ||
1124 | 188 | |||
1125 | 189 | def _connect_ui(self): | ||
1126 | 190 | """Implement in each child.""" | ||
1127 | 191 | raise NotImplementedError() | ||
1128 | 192 | |||
1129 | 163 | def _handle_error(self, remote_call, handler, error): | 193 | def _handle_error(self, remote_call, handler, error): |
1130 | 164 | """Handle any error when calling the remote backend.""" | 194 | """Handle any error when calling the remote backend.""" |
1131 | 165 | logger.error('Remote call %r failed with: %r', remote_call, error) | 195 | logger.error('Remote call %r failed with: %r', remote_call, error) |
1132 | @@ -210,11 +240,14 @@ | |||
1133 | 210 | class SSOWizardEnhancedEditPage(SSOWizardPage): | 240 | class SSOWizardEnhancedEditPage(SSOWizardPage): |
1134 | 211 | """Page that contains enhanced line edits.""" | 241 | """Page that contains enhanced line edits.""" |
1135 | 212 | 242 | ||
1137 | 213 | def __init__(self, ui, app_name=None, parent=None): | 243 | # Method '_connect_ui', '_set_translated_strings' is abstract in class |
1138 | 244 | # 'SSOWizardPage' but is not overridden | ||
1139 | 245 | # pylint: disable=W0223 | ||
1140 | 246 | |||
1141 | 247 | def __init__(self, *args, **kwargs): | ||
1142 | 214 | """Create a new instance.""" | 248 | """Create a new instance.""" |
1143 | 215 | self._enhanced_edits = {} | 249 | self._enhanced_edits = {} |
1146 | 216 | super(SSOWizardEnhancedEditPage, self).__init__(ui, | 250 | super(SSOWizardEnhancedEditPage, self).__init__(*args, **kwargs) |
1145 | 217 | app_name=app_name, parent=parent) | ||
1147 | 218 | 251 | ||
1148 | 219 | def set_line_edit_validation_rule(self, edit, cb): | 252 | def set_line_edit_validation_rule(self, edit, cb): |
1149 | 220 | """Set a new enhanced edit so that we can show an icon.""" | 253 | """Set a new enhanced edit so that we can show an icon.""" |
1150 | 221 | 254 | ||
1151 | === modified file 'ubuntu_sso/qt/success_page.py' | |||
1152 | --- ubuntu_sso/qt/success_page.py 2012-02-13 18:08:13 +0000 | |||
1153 | +++ ubuntu_sso/qt/success_page.py 2012-02-24 17:28:19 +0000 | |||
1154 | @@ -16,15 +16,24 @@ | |||
1155 | 16 | 16 | ||
1156 | 17 | """Success page UI.""" | 17 | """Success page UI.""" |
1157 | 18 | 18 | ||
1159 | 19 | from ubuntu_sso.qt.gui import SSOWizardPage | 19 | from PyQt4 import QtGui |
1160 | 20 | |||
1161 | 21 | from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage | ||
1162 | 22 | from ubuntu_sso.qt.ui.success_message_ui import Ui_SuccessPage | ||
1163 | 20 | from ubuntu_sso.utils.ui import SUCCESS | 23 | from ubuntu_sso.utils.ui import SUCCESS |
1164 | 21 | 24 | ||
1165 | 22 | 25 | ||
1166 | 23 | class SuccessPage(SSOWizardPage): | 26 | class SuccessPage(SSOWizardPage): |
1167 | 24 | """Page used to display success message.""" | 27 | """Page used to display success message.""" |
1168 | 25 | 28 | ||
1172 | 26 | def __init__(self, ui, image_pixmap, *args, **kwargs): | 29 | ui_class = Ui_SuccessPage |
1173 | 27 | super(SuccessPage, self).__init__(ui, *args, **kwargs) | 30 | |
1174 | 28 | self.ui.image_label.setPixmap(image_pixmap) | 31 | def _set_translated_strings(self): |
1175 | 32 | """Set proper strings to widgets.""" | ||
1176 | 33 | # we may want to customize the image_label in some future | ||
1177 | 34 | self.ui.image_label.setPixmap(QtGui.QPixmap()) | ||
1178 | 29 | message = SUCCESS % {'app_name': self.app_name} | 35 | message = SUCCESS % {'app_name': self.app_name} |
1179 | 30 | self.ui.success_message_body.setText(message) | 36 | self.ui.success_message_body.setText(message) |
1180 | 37 | |||
1181 | 38 | def _connect_ui(self): | ||
1182 | 39 | """Nothing to connect.""" | ||
1183 | 31 | 40 | ||
1184 | === modified file 'ubuntu_sso/qt/tests/__init__.py' | |||
1185 | --- ubuntu_sso/qt/tests/__init__.py 2012-02-15 17:33:40 +0000 | |||
1186 | +++ ubuntu_sso/qt/tests/__init__.py 2012-02-24 17:28:19 +0000 | |||
1187 | @@ -19,20 +19,30 @@ | |||
1188 | 19 | from PyQt4 import QtGui, QtCore | 19 | from PyQt4 import QtGui, QtCore |
1189 | 20 | from twisted.internet import defer | 20 | from twisted.internet import defer |
1190 | 21 | from twisted.trial.unittest import TestCase | 21 | from twisted.trial.unittest import TestCase |
1191 | 22 | from ubuntu_sso.qt import loadingoverlay | ||
1192 | 23 | 22 | ||
1196 | 24 | from ubuntu_sso import ( | 23 | from ubuntu_sso import main, NO_OP |
1197 | 25 | main, | 24 | from ubuntu_sso.qt import sso_wizard_page |
1198 | 26 | NO_OP, | 25 | from ubuntu_sso.tests import ( |
1199 | 26 | APP_NAME, | ||
1200 | 27 | HELP_TEXT, | ||
1201 | 28 | PING_URL, | ||
1202 | 29 | POLICY_URL, | ||
1203 | 30 | TC_URL, | ||
1204 | 31 | WINDOW_ID, | ||
1205 | 27 | ) | 32 | ) |
1206 | 28 | 33 | ||
1207 | 34 | KWARGS = dict(app_name=APP_NAME, help_text=HELP_TEXT, ping_url=PING_URL, | ||
1208 | 35 | policy_url=POLICY_URL, tc_url=TC_URL, window_id=WINDOW_ID) | ||
1209 | 36 | |||
1210 | 37 | # is ok to access private method/attrs in tests | ||
1211 | 38 | # pylint: disable=W0212 | ||
1212 | 39 | |||
1213 | 29 | 40 | ||
1214 | 30 | class FakedObject(object): | 41 | class FakedObject(object): |
1215 | 31 | """Fake an object, record every call.""" | 42 | """Fake an object, record every call.""" |
1216 | 32 | 43 | ||
1217 | 33 | next_result = None | 44 | next_result = None |
1220 | 34 | exposed_methods = ['connect_to_signal', | 45 | exposed_methods = [] |
1219 | 35 | 'generate_captcha', 'request_password_reset_token'] | ||
1221 | 36 | 46 | ||
1222 | 37 | def __init__(self, *args, **kwargs): | 47 | def __init__(self, *args, **kwargs): |
1223 | 38 | self._args = args | 48 | self._args = args |
1224 | @@ -52,10 +62,26 @@ | |||
1225 | 52 | return inner | 62 | return inner |
1226 | 53 | 63 | ||
1227 | 54 | 64 | ||
1228 | 65 | class FakedSSOLoginBackend(FakedObject): | ||
1229 | 66 | """A faked sso_login backend.""" | ||
1230 | 67 | |||
1231 | 68 | exposed_methods = [ | ||
1232 | 69 | 'connect_to_signal', | ||
1233 | 70 | 'generate_captcha', | ||
1234 | 71 | 'login', | ||
1235 | 72 | 'login_and_ping', | ||
1236 | 73 | 'register_user', | ||
1237 | 74 | 'request_password_reset_token', | ||
1238 | 75 | 'set_new_password', | ||
1239 | 76 | 'validate_email', | ||
1240 | 77 | 'validate_email_and_ping', | ||
1241 | 78 | ] | ||
1242 | 79 | |||
1243 | 80 | |||
1244 | 55 | class FakedBackend(object): | 81 | class FakedBackend(object): |
1245 | 56 | """A faked backend.""" | 82 | """A faked backend.""" |
1246 | 57 | 83 | ||
1248 | 58 | sso_login = FakedObject() | 84 | sso_login = FakedSSOLoginBackend() |
1249 | 59 | 85 | ||
1250 | 60 | 86 | ||
1251 | 61 | class FakePageUiStyle(object): | 87 | class FakePageUiStyle(object): |
1252 | @@ -203,7 +229,7 @@ | |||
1253 | 203 | self.overlay = FakeOverlay() | 229 | self.overlay = FakeOverlay() |
1254 | 204 | self.local_folders_page = FakeWizardPage() | 230 | self.local_folders_page = FakeWizardPage() |
1255 | 205 | self.folders_page = FakeWizardPage() | 231 | self.folders_page = FakeWizardPage() |
1257 | 206 | self.app_name = 'app_name' | 232 | self.app_name = APP_NAME |
1258 | 207 | 233 | ||
1259 | 208 | def show(self): | 234 | def show(self): |
1260 | 209 | """Fake method.""" | 235 | """Fake method.""" |
1261 | @@ -250,6 +276,7 @@ | |||
1262 | 250 | 276 | ||
1263 | 251 | 277 | ||
1264 | 252 | class FakeWizard(object): | 278 | class FakeWizard(object): |
1265 | 279 | |||
1266 | 253 | """Replace wizard() function on wizard pages.""" | 280 | """Replace wizard() function on wizard pages.""" |
1267 | 254 | 281 | ||
1268 | 255 | customButtonClicked = QtCore.QObject() | 282 | customButtonClicked = QtCore.QObject() |
1269 | @@ -374,6 +401,12 @@ | |||
1270 | 374 | class BaseTestCase(TestCase): | 401 | class BaseTestCase(TestCase): |
1271 | 375 | """The base test case.""" | 402 | """The base test case.""" |
1272 | 376 | 403 | ||
1273 | 404 | kwargs = None | ||
1274 | 405 | ui_class = None | ||
1275 | 406 | ui_signals = () | ||
1276 | 407 | ui_backend_signals = () | ||
1277 | 408 | ui_wizard_class = FakeWizard | ||
1278 | 409 | |||
1279 | 377 | @defer.inlineCallbacks | 410 | @defer.inlineCallbacks |
1280 | 378 | def setUp(self): | 411 | def setUp(self): |
1281 | 379 | yield super(BaseTestCase, self).setUp() | 412 | yield super(BaseTestCase, self).setUp() |
1282 | @@ -383,11 +416,31 @@ | |||
1283 | 383 | self.patch(main, 'get_sso_client', | 416 | self.patch(main, 'get_sso_client', |
1284 | 384 | lambda *a: defer.succeed(backend)) | 417 | lambda *a: defer.succeed(backend)) |
1285 | 385 | 418 | ||
1286 | 419 | self.patch(sso_wizard_page, 'LoadingOverlay', FakeOverlay) | ||
1287 | 420 | |||
1288 | 421 | self.app_name = APP_NAME | ||
1289 | 422 | self.ping_url = PING_URL | ||
1290 | 423 | self.signals_results = [] | ||
1291 | 424 | |||
1292 | 425 | # self.ui_class is not callable | ||
1293 | 426 | # pylint: disable=E1102, C0103, W0212 | ||
1294 | 427 | self.ui = None | ||
1295 | 428 | self.wizard = None | ||
1296 | 429 | if self.ui_class is not None: | ||
1297 | 430 | kwargs = dict(KWARGS) if self.kwargs is None else self.kwargs | ||
1298 | 431 | self.ui = self.ui_class(**kwargs) | ||
1299 | 432 | |||
1300 | 433 | for signal in self.ui_signals: | ||
1301 | 434 | self.patch(self.ui_class, signal, FakeSignal()) | ||
1302 | 435 | |||
1303 | 436 | if self.ui_wizard_class is not None: | ||
1304 | 437 | self.wizard = self.ui_wizard_class() | ||
1305 | 438 | self.patch(self.ui, 'wizard', lambda: self.wizard) | ||
1306 | 439 | |||
1307 | 386 | def _set_called(self, *args, **kwargs): | 440 | def _set_called(self, *args, **kwargs): |
1308 | 387 | """Store 'args' and 'kwargs' for test assertions.""" | 441 | """Store 'args' and 'kwargs' for test assertions.""" |
1309 | 388 | self._called = (args, kwargs) | 442 | self._called = (args, kwargs) |
1310 | 389 | 443 | ||
1311 | 390 | # pylint: disable=E1101, W0212 | ||
1312 | 391 | def assert_backend_called(self, method, *args, **kwargs): | 444 | def assert_backend_called(self, method, *args, **kwargs): |
1313 | 392 | """Check that 'method(*args, **kwargs)' was called in the backend.""" | 445 | """Check that 'method(*args, **kwargs)' was called in the backend.""" |
1314 | 393 | self.assertIn(method, self.ui.backend._called) | 446 | self.assertIn(method, self.ui.backend._called) |
1315 | @@ -402,34 +455,6 @@ | |||
1316 | 402 | self.assertEqual(error_handler.func, self.ui._handle_error) | 455 | self.assertEqual(error_handler.func, self.ui._handle_error) |
1317 | 403 | 456 | ||
1318 | 404 | self.assertEqual(call[1], kwargs) | 457 | self.assertEqual(call[1], kwargs) |
1319 | 405 | # pylint: enable=E1101, W0212 | ||
1320 | 406 | |||
1321 | 407 | |||
1322 | 408 | class BaseTestCaseUI(TestCase): | ||
1323 | 409 | """Base Test Case.""" | ||
1324 | 410 | |||
1325 | 411 | class_ui = None | ||
1326 | 412 | kwargs = {} | ||
1327 | 413 | |||
1328 | 414 | @defer.inlineCallbacks | ||
1329 | 415 | def setUp(self): | ||
1330 | 416 | yield super(BaseTestCaseUI, self).setUp() | ||
1331 | 417 | # self.class_ui is not callable | ||
1332 | 418 | # pylint: disable=E1102, C0103, W0212 | ||
1333 | 419 | self.ui = None | ||
1334 | 420 | self._called = False | ||
1335 | 421 | if self.class_ui is not None: | ||
1336 | 422 | self.ui = self.class_ui(**self.kwargs) | ||
1337 | 423 | |||
1338 | 424 | if hasattr(self.ui, 'backend'): | ||
1339 | 425 | # clean backend calls | ||
1340 | 426 | self.ui.backend._called.clear() | ||
1341 | 427 | |||
1342 | 428 | self.patch(loadingoverlay, 'LoadingOverlay', FakeOverlay) | ||
1343 | 429 | |||
1344 | 430 | def _set_called(self, *args, **kwargs): | ||
1345 | 431 | """Store 'args' and 'kwargs' for test assertions.""" | ||
1346 | 432 | self._called = (args, kwargs) | ||
1347 | 433 | 458 | ||
1348 | 434 | def get_pixmap_data(self, pixmap): | 459 | def get_pixmap_data(self, pixmap): |
1349 | 435 | """Get the raw data of a QPixmap.""" | 460 | """Get the raw data of a QPixmap.""" |
1350 | @@ -446,3 +471,30 @@ | |||
1351 | 446 | d1 = self.get_pixmap_data(pixmap1) | 471 | d1 = self.get_pixmap_data(pixmap1) |
1352 | 447 | d2 = self.get_pixmap_data(pixmap2) | 472 | d2 = self.get_pixmap_data(pixmap2) |
1353 | 448 | self.assertEqual(d1, d2) | 473 | self.assertEqual(d1, d2) |
1354 | 474 | |||
1355 | 475 | # pylint: enable=C0103 | ||
1356 | 476 | |||
1357 | 477 | @defer.inlineCallbacks | ||
1358 | 478 | def test_setup_page(self): | ||
1359 | 479 | """Test the backend signal connection.""" | ||
1360 | 480 | if self.ui is None or getattr(self.ui, 'setup_page', None) is None: | ||
1361 | 481 | return | ||
1362 | 482 | |||
1363 | 483 | called = [] | ||
1364 | 484 | self.patch(self.ui, '_setup_signals', | ||
1365 | 485 | lambda *a: called.append('_setup_signals')) | ||
1366 | 486 | self.patch(self.ui, '_connect_ui', | ||
1367 | 487 | lambda *a: called.append('_connect_ui')) | ||
1368 | 488 | self.patch(self.ui, '_set_translated_strings', | ||
1369 | 489 | lambda *a: called.append('_set_translated_strings')) | ||
1370 | 490 | |||
1371 | 491 | yield self.ui.setup_page() | ||
1372 | 492 | |||
1373 | 493 | self.assertEqual(self.ui.backend, self.sso_login_backend) | ||
1374 | 494 | |||
1375 | 495 | for signal in self.ui_backend_signals: | ||
1376 | 496 | self.assertIn(signal, self.ui._signals) | ||
1377 | 497 | self.assertTrue(callable(self.ui._signals[signal])) | ||
1378 | 498 | |||
1379 | 499 | expected = ['_setup_signals', '_set_translated_strings', '_connect_ui'] | ||
1380 | 500 | self.assertEqual(expected, called) | ||
1381 | 449 | 501 | ||
1382 | === modified file 'ubuntu_sso/qt/tests/test_current_user_sign_in_page.py' | |||
1383 | --- ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-02-16 18:40:41 +0000 | |||
1384 | +++ ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-02-24 17:28:19 +0000 | |||
1385 | @@ -17,78 +17,22 @@ | |||
1386 | 17 | """Tests for the Setup Account page Qt UI.""" | 17 | """Tests for the Setup Account page Qt UI.""" |
1387 | 18 | 18 | ||
1388 | 19 | from PyQt4 import QtGui, QtCore | 19 | from PyQt4 import QtGui, QtCore |
1389 | 20 | from twisted.internet import defer | ||
1390 | 21 | 20 | ||
1391 | 22 | from ubuntu_sso.qt import gui | ||
1392 | 23 | from ubuntu_sso.qt import current_user_sign_in_page | 21 | from ubuntu_sso.qt import current_user_sign_in_page |
1393 | 24 | from ubuntu_sso.qt.tests import ( | 22 | from ubuntu_sso.qt.tests import ( |
1394 | 25 | BaseTestCase, | 23 | BaseTestCase, |
1395 | 26 | FakedBackend, | ||
1396 | 27 | FakedObject, | ||
1397 | 28 | FakeOverlay, | ||
1398 | 29 | FakePageUiStyle, | 24 | FakePageUiStyle, |
1399 | 30 | FakeSignal, | ||
1400 | 31 | FakeWizard, | ||
1401 | 32 | FakeWizardButtonStyle, | 25 | FakeWizardButtonStyle, |
1402 | 33 | ) | 26 | ) |
1403 | 34 | from ubuntu_sso.qt.ui import current_user_sign_in_ui | ||
1404 | 35 | 27 | ||
1405 | 36 | 28 | ||
1406 | 37 | # pylint: disable=W0212 | 29 | # pylint: disable=W0212 |
1407 | 38 | class CurrentUserSignInTestCase(BaseTestCase): | 30 | class CurrentUserSignInTestCase(BaseTestCase): |
1408 | 39 | """Test the SetupAccountPage code.""" | 31 | """Test the SetupAccountPage code.""" |
1409 | 40 | 32 | ||
1461 | 41 | @defer.inlineCallbacks | 33 | ui_class = current_user_sign_in_page.CurrentUserSignInPage |
1462 | 42 | def setUp(self): | 34 | ui_signals = ('userLoggedIn', 'passwordForgotten', 'userNotValidated') |
1463 | 43 | yield super(CurrentUserSignInTestCase, self).setUp() | 35 | ui_backend_signals = ('LoggedIn', 'LoginError', 'UserNotValidated') |
1413 | 44 | self.patch(gui, "LoadingOverlay", FakeOverlay) | ||
1414 | 45 | self.patch(gui.main, "get_sso_client", FakedBackend) | ||
1415 | 46 | self.signals_results = [] | ||
1416 | 47 | self.patch(current_user_sign_in_page.CurrentUserSignInPage, | ||
1417 | 48 | "userLoggedIn", FakeSignal()) | ||
1418 | 49 | self.patch(current_user_sign_in_page.CurrentUserSignInPage, | ||
1419 | 50 | "passwordForgotten", FakeSignal()) | ||
1420 | 51 | self.patch(current_user_sign_in_page.CurrentUserSignInPage, | ||
1421 | 52 | "userNotValidated", FakeSignal()) | ||
1422 | 53 | self.app_name = 'my_app' | ||
1423 | 54 | self.ui = current_user_sign_in_page.CurrentUserSignInPage( | ||
1424 | 55 | current_user_sign_in_ui.Ui_CurrentUserSignInPage(), | ||
1425 | 56 | '', | ||
1426 | 57 | app_name=self.app_name, | ||
1427 | 58 | parent=None) | ||
1428 | 59 | self.wizard = FakeWizard() | ||
1429 | 60 | self.patch(self.ui, 'wizard', lambda: self.wizard) | ||
1430 | 61 | |||
1431 | 62 | def test_init(self): | ||
1432 | 63 | """Test the construction of the object.""" | ||
1433 | 64 | self.assertIn('LoggedIn', self.ui._signals) | ||
1434 | 65 | self.assertIn('LoginError', self.ui._signals) | ||
1435 | 66 | self.assertIn('UserNotValidated', self.ui._signals) | ||
1436 | 67 | self.assertTrue(callable(self.ui._signals['LoggedIn'])) | ||
1437 | 68 | self.assertTrue(callable(self.ui._signals['LoginError'])) | ||
1438 | 69 | self.assertTrue(callable(self.ui._signals['UserNotValidated'])) | ||
1439 | 70 | self.assertEqual(self.ui.backend, FakedBackend.sso_login) | ||
1440 | 71 | |||
1441 | 72 | # pylint: disable=E1101 | ||
1442 | 73 | def test_setup_page(self): | ||
1443 | 74 | """Test that the backend is received and the methods are called.""" | ||
1444 | 75 | exposed_methods = [ | ||
1445 | 76 | '_set_translated_strings', | ||
1446 | 77 | '_setup_signals', | ||
1447 | 78 | '_connect_ui'] | ||
1448 | 79 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
1449 | 80 | faked_object = FakedObject() | ||
1450 | 81 | self.patch(self.ui, "_set_translated_strings", | ||
1451 | 82 | faked_object._set_translated_strings) | ||
1452 | 83 | self.patch(self.ui, "_setup_signals", | ||
1453 | 84 | faked_object._setup_signals) | ||
1454 | 85 | self.patch(self.ui, "_connect_ui", | ||
1455 | 86 | faked_object._connect_ui) | ||
1456 | 87 | self.ui.setup_page() | ||
1457 | 88 | self.assertIn('_set_translated_strings', faked_object._called) | ||
1458 | 89 | self.assertIn('_setup_signals', faked_object._called) | ||
1459 | 90 | self.assertIn('_connect_ui', faked_object._called) | ||
1460 | 91 | # pylint: enable=E1101 | ||
1464 | 92 | 36 | ||
1465 | 93 | def test_on_user_not_validated(self): | 37 | def test_on_user_not_validated(self): |
1466 | 94 | """Test the navigation flow on user not validated.""" | 38 | """Test the navigation flow on user not validated.""" |
1467 | @@ -176,12 +120,6 @@ | |||
1468 | 176 | 120 | ||
1469 | 177 | def test_login_with_ping(self): | 121 | def test_login_with_ping(self): |
1470 | 178 | """Test the login method.""" | 122 | """Test the login method.""" |
1471 | 179 | ping = 'http://ping.me' | ||
1472 | 180 | self.ui.ping_url = ping | ||
1473 | 181 | exposed_methods = ['login', 'login_and_ping'] | ||
1474 | 182 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
1475 | 183 | faked_object = FakedObject() | ||
1476 | 184 | self.patch(self.ui, "backend", faked_object) | ||
1477 | 185 | email = 'valid@email' | 123 | email = 'valid@email' |
1478 | 186 | password = '123456' | 124 | password = '123456' |
1479 | 187 | self.ui.ui.email_edit.setText(email) | 125 | self.ui.ui.email_edit.setText(email) |
1480 | @@ -189,15 +127,11 @@ | |||
1481 | 189 | self.ui.login() | 127 | self.ui.login() |
1482 | 190 | self.assertEqual(self.ui.overlay.show_counter, 1) | 128 | self.assertEqual(self.ui.overlay.show_counter, 1) |
1483 | 191 | self.assert_backend_called('login_and_ping', | 129 | self.assert_backend_called('login_and_ping', |
1485 | 192 | self.app_name, email, password, ping) | 130 | self.app_name, email, password, self.ping_url) |
1486 | 193 | 131 | ||
1487 | 194 | def test_login_without_ping(self): | 132 | def test_login_without_ping(self): |
1488 | 195 | """Test the login method.""" | 133 | """Test the login method.""" |
1489 | 196 | self.ui.ping_url = '' | 134 | self.ui.ping_url = '' |
1490 | 197 | exposed_methods = ['login'] | ||
1491 | 198 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
1492 | 199 | faked_object = FakedObject() | ||
1493 | 200 | self.patch(self.ui, "backend", faked_object) | ||
1494 | 201 | email = 'valid@email' | 135 | email = 'valid@email' |
1495 | 202 | password = '123456' | 136 | password = '123456' |
1496 | 203 | self.ui.ui.email_edit.setText(email) | 137 | self.ui.ui.email_edit.setText(email) |
1497 | 204 | 138 | ||
1498 | === modified file 'ubuntu_sso/qt/tests/test_email_verification.py' | |||
1499 | --- ubuntu_sso/qt/tests/test_email_verification.py 2012-02-23 20:16:46 +0000 | |||
1500 | +++ ubuntu_sso/qt/tests/test_email_verification.py 2012-02-24 17:28:19 +0000 | |||
1501 | @@ -17,62 +17,23 @@ | |||
1502 | 17 | """Tests for the Setup Account page Qt UI.""" | 17 | """Tests for the Setup Account page Qt UI.""" |
1503 | 18 | 18 | ||
1504 | 19 | from PyQt4 import QtGui, QtCore | 19 | from PyQt4 import QtGui, QtCore |
1505 | 20 | from twisted.internet import defer | ||
1506 | 21 | 20 | ||
1507 | 22 | from ubuntu_sso.qt import gui | ||
1508 | 23 | from ubuntu_sso.qt import email_verification_page | 21 | from ubuntu_sso.qt import email_verification_page |
1509 | 24 | from ubuntu_sso.qt.tests import ( | 22 | from ubuntu_sso.qt.tests import ( |
1510 | 25 | BaseTestCase, | 23 | BaseTestCase, |
1511 | 26 | FakedBackend, | ||
1512 | 27 | FakedObject, | ||
1513 | 28 | FakePageUiStyle, | 24 | FakePageUiStyle, |
1514 | 29 | FakeSignal, | ||
1515 | 30 | FakeWizard, | ||
1516 | 31 | ) | 25 | ) |
1520 | 32 | from ubuntu_sso.qt.ui import email_verification_ui | 26 | |
1521 | 33 | 27 | # is ok to access private method/attrs in tests | |
1519 | 34 | |||
1522 | 35 | # pylint: disable=W0212 | 28 | # pylint: disable=W0212 |
1523 | 29 | |||
1524 | 30 | |||
1525 | 36 | class EmailVerificationTestCase(BaseTestCase): | 31 | class EmailVerificationTestCase(BaseTestCase): |
1526 | 37 | """Test the SetupAccountPage code.""" | 32 | """Test the SetupAccountPage code.""" |
1527 | 38 | 33 | ||
1565 | 39 | @defer.inlineCallbacks | 34 | ui_class = email_verification_page.EmailVerificationPage |
1566 | 40 | def setUp(self): | 35 | ui_signals = ('registrationSuccess',) |
1567 | 41 | yield super(EmailVerificationTestCase, self).setUp() | 36 | ui_backend_signals = ('EmailValidated', 'EmailValidationError') |
1531 | 42 | self.signals_results = [] | ||
1532 | 43 | self.patch(gui.main, "get_sso_client", FakedBackend) | ||
1533 | 44 | self.patch(email_verification_page.EmailVerificationPage, | ||
1534 | 45 | "registrationSuccess", FakeSignal()) | ||
1535 | 46 | self.ui = email_verification_page.EmailVerificationPage( | ||
1536 | 47 | email_verification_ui.Ui_EmailVerificationPage(), '', | ||
1537 | 48 | parent=None) | ||
1538 | 49 | self.wizard = FakeWizard() | ||
1539 | 50 | self.patch(self.ui, 'wizard', lambda: self.wizard) | ||
1540 | 51 | |||
1541 | 52 | def test_init(self): | ||
1542 | 53 | """Test the construction of the object.""" | ||
1543 | 54 | self.assertIn('EmailValidated', self.ui._signals) | ||
1544 | 55 | self.assertIn('EmailValidationError', self.ui._signals) | ||
1545 | 56 | self.assertTrue(callable(self.ui._signals['EmailValidated'])) | ||
1546 | 57 | self.assertTrue(callable(self.ui._signals['EmailValidationError'])) | ||
1547 | 58 | self.assertEqual(self.ui.backend, FakedBackend.sso_login) | ||
1548 | 59 | |||
1549 | 60 | # pylint: disable=E1101 | ||
1550 | 61 | def test_setup_page(self): | ||
1551 | 62 | """Test that the backend is received and the methods are called.""" | ||
1552 | 63 | exposed_methods = [ | ||
1553 | 64 | '_setup_signals', | ||
1554 | 65 | '_connect_ui_elements'] | ||
1555 | 66 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
1556 | 67 | faked_object = FakedObject() | ||
1557 | 68 | self.patch(self.ui, "_setup_signals", | ||
1558 | 69 | faked_object._setup_signals) | ||
1559 | 70 | self.patch(self.ui, "_connect_ui_elements", | ||
1560 | 71 | faked_object._connect_ui_elements) | ||
1561 | 72 | self.ui.setup_page() | ||
1562 | 73 | self.assertIn('_setup_signals', faked_object._called) | ||
1563 | 74 | self.assertIn('_connect_ui_elements', faked_object._called) | ||
1564 | 75 | # pylint: enable=E1101 | ||
1568 | 76 | 37 | ||
1569 | 77 | def test_verification_code(self): | 38 | def test_verification_code(self): |
1570 | 78 | """Test the verification value returned.""" | 39 | """Test the verification value returned.""" |
1571 | @@ -87,9 +48,9 @@ | |||
1572 | 87 | self.assertEqual(value, self.ui.ui.next_button) | 48 | self.assertEqual(value, self.ui.ui.next_button) |
1573 | 88 | self.assertTrue(isinstance(value, QtGui.QPushButton)) | 49 | self.assertTrue(isinstance(value, QtGui.QPushButton)) |
1574 | 89 | 50 | ||
1576 | 90 | def test_connect_ui_elements(self): | 51 | def test_connect_ui(self): |
1577 | 91 | """Test the connect ui method.""" | 52 | """Test the connect ui method.""" |
1579 | 92 | self.ui._connect_ui_elements() | 53 | self.ui._connect_ui() |
1580 | 93 | # We expect 2 values because _connect_ui is called in the init too. | 54 | # We expect 2 values because _connect_ui is called in the init too. |
1581 | 94 | self.assertEqual(self.ui.ui.verification_code_edit.receivers( | 55 | self.assertEqual(self.ui.ui.verification_code_edit.receivers( |
1582 | 95 | QtCore.SIGNAL("textChanged(const QString&)")), 2) | 56 | QtCore.SIGNAL("textChanged(const QString&)")), 2) |
1583 | @@ -170,40 +131,29 @@ | |||
1584 | 170 | 131 | ||
1585 | 171 | def test_validate_email_with_ping(self): | 132 | def test_validate_email_with_ping(self): |
1586 | 172 | """Test the login method.""" | 133 | """Test the login method.""" |
1587 | 173 | ping = 'http://ping.me' | ||
1588 | 174 | app_name = 'app_name' | ||
1589 | 175 | email = 'email@example.com' | 134 | email = 'email@example.com' |
1590 | 176 | password = 'password' | 135 | password = 'password' |
1591 | 177 | code = 'code' | 136 | code = 'code' |
1592 | 178 | self.ui.ping_url = ping | ||
1593 | 179 | self.ui.app_name = app_name | ||
1594 | 180 | self.ui.email = email | 137 | self.ui.email = email |
1595 | 181 | self.ui.password = password | 138 | self.ui.password = password |
1596 | 182 | self.ui.ui.verification_code_edit.setText(code) | 139 | self.ui.ui.verification_code_edit.setText(code) |
1601 | 183 | exposed_methods = ['validate_email', 'validate_email_and_ping'] | 140 | |
1598 | 184 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
1599 | 185 | faked_object = FakedObject() | ||
1600 | 186 | self.patch(self.ui, "backend", faked_object) | ||
1602 | 187 | self.ui.validate_email() | 141 | self.ui.validate_email() |
1603 | 142 | |||
1604 | 188 | self.assert_backend_called('validate_email_and_ping', | 143 | self.assert_backend_called('validate_email_and_ping', |
1606 | 189 | app_name, email, password, code, ping) | 144 | self.app_name, email, password, code, self.ping_url) |
1607 | 190 | 145 | ||
1608 | 191 | def test_validate_email_without_ping(self): | 146 | def test_validate_email_without_ping(self): |
1609 | 192 | """Test the login method.""" | 147 | """Test the login method.""" |
1612 | 193 | ping = '' | 148 | self.ui.ping_url = '' |
1611 | 194 | app_name = 'app_name' | ||
1613 | 195 | email = 'email@example.com' | 149 | email = 'email@example.com' |
1614 | 196 | password = 'password' | 150 | password = 'password' |
1615 | 197 | code = 'code' | 151 | code = 'code' |
1616 | 198 | self.ui.ping_url = ping | ||
1617 | 199 | self.ui.app_name = app_name | ||
1618 | 200 | self.ui.email = email | 152 | self.ui.email = email |
1619 | 201 | self.ui.password = password | 153 | self.ui.password = password |
1620 | 202 | self.ui.ui.verification_code_edit.setText(code) | 154 | self.ui.ui.verification_code_edit.setText(code) |
1625 | 203 | exposed_methods = ['validate_email', 'validate_email_and_ping'] | 155 | |
1622 | 204 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
1623 | 205 | faked_object = FakedObject() | ||
1624 | 206 | self.patch(self.ui, "backend", faked_object) | ||
1626 | 207 | self.ui.validate_email() | 156 | self.ui.validate_email() |
1627 | 157 | |||
1628 | 208 | self.assert_backend_called('validate_email', | 158 | self.assert_backend_called('validate_email', |
1630 | 209 | app_name, email, password, code) | 159 | self.app_name, email, password, code) |
1631 | 210 | 160 | ||
1632 | === modified file 'ubuntu_sso/qt/tests/test_enchanced_line_edit.py' | |||
1633 | --- ubuntu_sso/qt/tests/test_enchanced_line_edit.py 2012-01-26 15:34:16 +0000 | |||
1634 | +++ ubuntu_sso/qt/tests/test_enchanced_line_edit.py 2012-02-24 17:28:19 +0000 | |||
1635 | @@ -18,13 +18,10 @@ | |||
1636 | 18 | 18 | ||
1637 | 19 | import collections | 19 | import collections |
1638 | 20 | 20 | ||
1639 | 21 | from PyQt4 import QtGui, QtCore | ||
1640 | 21 | from twisted.trial.unittest import TestCase | 22 | from twisted.trial.unittest import TestCase |
1641 | 22 | 23 | ||
1647 | 23 | # pylint: disable=E1101 | 24 | from ubuntu_sso.qt.sso_wizard_page import EnhancedLineEdit |
1643 | 24 | |||
1644 | 25 | from PyQt4 import QtGui, QtCore | ||
1645 | 26 | |||
1646 | 27 | from ubuntu_sso.qt.gui import EnhancedLineEdit | ||
1648 | 28 | 25 | ||
1649 | 29 | 26 | ||
1650 | 30 | class EnhancedLineEditTestCase(TestCase): | 27 | class EnhancedLineEditTestCase(TestCase): |
1651 | 31 | 28 | ||
1652 | === added file 'ubuntu_sso/qt/tests/test_error_page.py' | |||
1653 | --- ubuntu_sso/qt/tests/test_error_page.py 1970-01-01 00:00:00 +0000 | |||
1654 | +++ ubuntu_sso/qt/tests/test_error_page.py 2012-02-24 17:28:19 +0000 | |||
1655 | @@ -0,0 +1,26 @@ | |||
1656 | 1 | # -*- coding: utf-8 -*- | ||
1657 | 2 | # | ||
1658 | 3 | # Copyright 2012 Canonical Ltd. | ||
1659 | 4 | # | ||
1660 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
1661 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
1662 | 7 | # by the Free Software Foundation. | ||
1663 | 8 | # | ||
1664 | 9 | # This program is distributed in the hope that it will be useful, but | ||
1665 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1666 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1667 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
1668 | 13 | # | ||
1669 | 14 | # You should have received a copy of the GNU General Public License along | ||
1670 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1671 | 16 | |||
1672 | 17 | """Test the error page.""" | ||
1673 | 18 | |||
1674 | 19 | from ubuntu_sso.qt.error_page import ErrorPage | ||
1675 | 20 | from ubuntu_sso.qt.tests import BaseTestCase | ||
1676 | 21 | |||
1677 | 22 | |||
1678 | 23 | class ErrorPageTestCase(BaseTestCase): | ||
1679 | 24 | """Test that the correct widgets are used.""" | ||
1680 | 25 | |||
1681 | 26 | ui_class = ErrorPage | ||
1682 | 0 | 27 | ||
1683 | === modified file 'ubuntu_sso/qt/tests/test_forgotten_password.py' | |||
1684 | --- ubuntu_sso/qt/tests/test_forgotten_password.py 2012-02-18 15:12:09 +0000 | |||
1685 | +++ ubuntu_sso/qt/tests/test_forgotten_password.py 2012-02-24 17:28:19 +0000 | |||
1686 | @@ -17,48 +17,23 @@ | |||
1687 | 17 | """Tests for the Setup Account page Qt UI.""" | 17 | """Tests for the Setup Account page Qt UI.""" |
1688 | 18 | 18 | ||
1689 | 19 | from PyQt4 import QtGui, QtCore | 19 | from PyQt4 import QtGui, QtCore |
1690 | 20 | from twisted.internet import defer | ||
1691 | 21 | 20 | ||
1692 | 22 | from ubuntu_sso.qt import gui | ||
1693 | 23 | from ubuntu_sso.qt import forgotten_password_page | 21 | from ubuntu_sso.qt import forgotten_password_page |
1694 | 24 | from ubuntu_sso.qt.tests import ( | 22 | from ubuntu_sso.qt.tests import ( |
1695 | 25 | BaseTestCase, | 23 | BaseTestCase, |
1696 | 26 | FakedBackend, | ||
1697 | 27 | FakedObject, | ||
1698 | 28 | FakeOverlay, | ||
1699 | 29 | FakePageUiStyle, | 24 | FakePageUiStyle, |
1700 | 30 | FakeSignal, | ||
1701 | 31 | FakeWizard, | ||
1702 | 32 | ) | 25 | ) |
1706 | 33 | from ubuntu_sso.qt.ui import forgotten_password_ui | 26 | |
1707 | 34 | 27 | # is ok to access private method/attrs in tests | |
1705 | 35 | |||
1708 | 36 | # pylint: disable=W0212, E1101 | 28 | # pylint: disable=W0212, E1101 |
1709 | 29 | |||
1710 | 30 | |||
1711 | 37 | class ForgottenPasswordTestCase(BaseTestCase): | 31 | class ForgottenPasswordTestCase(BaseTestCase): |
1712 | 38 | """Test the SetupAccountPage code.""" | 32 | """Test the SetupAccountPage code.""" |
1713 | 39 | 33 | ||
1736 | 40 | @defer.inlineCallbacks | 34 | ui_class = forgotten_password_page.ForgottenPasswordPage |
1737 | 41 | def setUp(self): | 35 | ui_siganls = ('passwordResetTokenSent',) |
1738 | 42 | yield super(ForgottenPasswordTestCase, self).setUp() | 36 | ui_backend_siganls = ('PasswordResetTokenSent', 'PasswordResetError') |
1717 | 43 | self.signals_results = [] | ||
1718 | 44 | self.patch(gui, "LoadingOverlay", FakeOverlay) | ||
1719 | 45 | self.patch(gui.main, "get_sso_client", FakedBackend) | ||
1720 | 46 | self.patch(forgotten_password_page.ForgottenPasswordPage, | ||
1721 | 47 | "passwordResetTokenSent", FakeSignal()) | ||
1722 | 48 | self.app_name = 'my_app' | ||
1723 | 49 | self.ui = forgotten_password_page.ForgottenPasswordPage( | ||
1724 | 50 | forgotten_password_ui.Ui_ForgottenPasswordPage(), | ||
1725 | 51 | app_name=self.app_name, parent=None) | ||
1726 | 52 | self.wizard = FakeWizard() | ||
1727 | 53 | self.patch(self.ui, 'wizard', lambda: self.wizard) | ||
1728 | 54 | |||
1729 | 55 | def test_init(self): | ||
1730 | 56 | """Test the construction of the object.""" | ||
1731 | 57 | self.assertIn('PasswordResetTokenSent', self.ui._signals) | ||
1732 | 58 | self.assertIn('PasswordResetError', self.ui._signals) | ||
1733 | 59 | self.assertTrue(callable(self.ui._signals['PasswordResetTokenSent'])) | ||
1734 | 60 | self.assertTrue(callable(self.ui._signals['PasswordResetError'])) | ||
1735 | 61 | self.assertEqual(self.ui.backend, FakedBackend.sso_login) | ||
1739 | 62 | 37 | ||
1740 | 63 | def test_request_new_password(self): | 38 | def test_request_new_password(self): |
1741 | 64 | """Test the request_new_password function.""" | 39 | """Test the request_new_password function.""" |
1742 | @@ -71,33 +46,6 @@ | |||
1743 | 71 | self.assert_backend_called('request_password_reset_token', | 46 | self.assert_backend_called('request_password_reset_token', |
1744 | 72 | app_name, email) | 47 | app_name, email) |
1745 | 73 | 48 | ||
1746 | 74 | def test_setup_page(self): | ||
1747 | 75 | """Test that the backend is received and the methods are called.""" | ||
1748 | 76 | exposed_methods = [ | ||
1749 | 77 | '_setup_signals', | ||
1750 | 78 | '_set_translated_strings', | ||
1751 | 79 | '_connect_ui', | ||
1752 | 80 | '_set_enhanced_line_edit', | ||
1753 | 81 | '_register_fields'] | ||
1754 | 82 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
1755 | 83 | faked_object = FakedObject() | ||
1756 | 84 | self.patch(self.ui, "_setup_signals", | ||
1757 | 85 | faked_object._setup_signals) | ||
1758 | 86 | self.patch(self.ui, "_set_translated_strings", | ||
1759 | 87 | faked_object._set_translated_strings) | ||
1760 | 88 | self.patch(self.ui, "_connect_ui", | ||
1761 | 89 | faked_object._connect_ui) | ||
1762 | 90 | self.patch(self.ui, "_set_enhanced_line_edit", | ||
1763 | 91 | faked_object._set_enhanced_line_edit) | ||
1764 | 92 | self.patch(self.ui, "_register_fields", | ||
1765 | 93 | faked_object._register_fields) | ||
1766 | 94 | self.ui.setup_page() | ||
1767 | 95 | self.assertIn('_setup_signals', faked_object._called) | ||
1768 | 96 | self.assertIn('_set_translated_strings', faked_object._called) | ||
1769 | 97 | self.assertIn('_connect_ui', faked_object._called) | ||
1770 | 98 | self.assertIn('_set_enhanced_line_edit', faked_object._called) | ||
1771 | 99 | self.assertIn('_register_fields', faked_object._called) | ||
1772 | 100 | |||
1773 | 101 | def test_email_widget(self): | 49 | def test_email_widget(self): |
1774 | 102 | """Test the email_widget property.""" | 50 | """Test the email_widget property.""" |
1775 | 103 | value = self.ui.email_widget | 51 | value = self.ui.email_widget |
1776 | 104 | 52 | ||
1777 | === modified file 'ubuntu_sso/qt/tests/test_loadingoverlay.py' | |||
1778 | --- ubuntu_sso/qt/tests/test_loadingoverlay.py 2012-02-03 14:51:41 +0000 | |||
1779 | +++ ubuntu_sso/qt/tests/test_loadingoverlay.py 2012-02-24 17:28:19 +0000 | |||
1780 | @@ -1,5 +1,5 @@ | |||
1781 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
1783 | 2 | 2 | # | |
1784 | 3 | # Copyright 2012 Canonical Ltd. | 3 | # Copyright 2012 Canonical Ltd. |
1785 | 4 | # | 4 | # |
1786 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
1787 | @@ -16,21 +16,21 @@ | |||
1788 | 16 | 16 | ||
1789 | 17 | """Tests for the Loading Overlay.""" | 17 | """Tests for the Loading Overlay.""" |
1790 | 18 | 18 | ||
1792 | 19 | from ubuntu_sso.qt import loadingoverlay as gui | 19 | from ubuntu_sso.qt.loadingoverlay import LoadingOverlay |
1793 | 20 | from ubuntu_sso.qt.tests import BaseTestCase | 20 | from ubuntu_sso.qt.tests import BaseTestCase |
1794 | 21 | 21 | ||
1795 | 22 | 22 | ||
1796 | 23 | class LoadingOverlayTestCase(BaseTestCase): | 23 | class LoadingOverlayTestCase(BaseTestCase): |
1797 | 24 | """Test the qt control panel.""" | 24 | """Test the qt control panel.""" |
1798 | 25 | 25 | ||
1802 | 26 | innerclass_ui = gui.loadingoverlay_ui | 26 | kwargs = {} |
1803 | 27 | innerclass_name = "Ui_Form" | 27 | ui_class = LoadingOverlay |
1804 | 28 | class_ui = gui.LoadingOverlay | 28 | ui_wizard_class = None |
1805 | 29 | 29 | ||
1808 | 30 | # pylint: disable=E1101 | 30 | def test_status_correct(self): |
1807 | 31 | def assert_status_correct(self): | ||
1809 | 32 | """Test if the necessary variables for the animation exists""" | 31 | """Test if the necessary variables for the animation exists""" |
1810 | 33 | self.ui.show() | 32 | self.ui.show() |
1811 | 33 | self.addCleanup(self.ui.hide) | ||
1812 | 34 | |||
1813 | 34 | self.assertTrue(self.ui.counter is not None) | 35 | self.assertTrue(self.ui.counter is not None) |
1814 | 35 | self.assertTrue(self.ui.orientation is not None) | 36 | self.assertTrue(self.ui.orientation is not None) |
1815 | 36 | # pylint: enable=E1101 | ||
1816 | 37 | 37 | ||
1817 | === modified file 'ubuntu_sso/qt/tests/test_network_detection.py' | |||
1818 | --- ubuntu_sso/qt/tests/test_network_detection.py 2012-02-22 16:58:08 +0000 | |||
1819 | +++ ubuntu_sso/qt/tests/test_network_detection.py 2012-02-24 17:28:19 +0000 | |||
1820 | @@ -16,39 +16,28 @@ | |||
1821 | 16 | 16 | ||
1822 | 17 | """The test suite for Network Detection UI.""" | 17 | """The test suite for Network Detection UI.""" |
1823 | 18 | 18 | ||
1824 | 19 | from twisted.internet import defer | ||
1825 | 20 | |||
1826 | 21 | from PyQt4 import QtGui | 19 | from PyQt4 import QtGui |
1827 | 22 | 20 | ||
1828 | 23 | from ubuntu_sso.tests import APP_NAME | ||
1829 | 24 | from ubuntu_sso.qt import network_detection_page | 21 | from ubuntu_sso.qt import network_detection_page |
1830 | 25 | from ubuntu_sso.qt.tests import ( | 22 | from ubuntu_sso.qt.tests import ( |
1831 | 26 | BaseTestCase, | 23 | BaseTestCase, |
1832 | 27 | FakeWizardButtonStyle, | 24 | FakeWizardButtonStyle, |
1833 | 28 | ) | 25 | ) |
1834 | 29 | 26 | ||
1835 | 27 | # is ok to access private method/attrs in tests | ||
1836 | 28 | # pylint: disable=W0212, E1101 | ||
1837 | 29 | |||
1838 | 30 | 30 | ||
1839 | 31 | class NetworkDetectionTestCase(BaseTestCase): | 31 | class NetworkDetectionTestCase(BaseTestCase): |
1840 | 32 | 32 | ||
1841 | 33 | """Test the CurrentUserController.""" | 33 | """Test the CurrentUserController.""" |
1842 | 34 | 34 | ||
1857 | 35 | @defer.inlineCallbacks | 35 | ui_class = network_detection_page.NetworkDetectionPage |
1858 | 36 | def setUp(self): | 36 | ui_wizard_class = FakeWizardButtonStyle |
1859 | 37 | """Initialize this test instance.""" | 37 | |
1846 | 38 | yield super(NetworkDetectionTestCase, self).setUp() | ||
1847 | 39 | self.wizard = FakeWizardButtonStyle() | ||
1848 | 40 | self.network_detection = network_detection_page.NetworkDetectionPage( | ||
1849 | 41 | app_name=APP_NAME) | ||
1850 | 42 | self.patch(self.network_detection, 'wizard', self._get_wizard) | ||
1851 | 43 | |||
1852 | 44 | def _get_wizard(self): | ||
1853 | 45 | """Fake wizard method for wizard page.""" | ||
1854 | 46 | return self.wizard | ||
1855 | 47 | |||
1856 | 48 | # pylint: disable=W0212 | ||
1860 | 49 | def test_initialize_page(self): | 38 | def test_initialize_page(self): |
1861 | 50 | """Check Network detection initialize page.""" | 39 | """Check Network detection initialize page.""" |
1863 | 51 | self.network_detection.initializePage() | 40 | self.ui.initializePage() |
1864 | 52 | self.assertEqual(self.wizard._next_id, None) | 41 | self.assertEqual(self.wizard._next_id, None) |
1865 | 53 | self.assertTrue(('setButtonLayout', ([ | 42 | self.assertTrue(('setButtonLayout', ([ |
1866 | 54 | QtGui.QWizard.Stretch, | 43 | QtGui.QWizard.Stretch, |
1867 | @@ -58,18 +47,16 @@ | |||
1868 | 58 | 47 | ||
1869 | 59 | def test_initialize_page_button_property(self): | 48 | def test_initialize_page_button_property(self): |
1870 | 60 | """Test the Try Again button properties.""" | 49 | """Test the Try Again button properties.""" |
1883 | 61 | self.patch(self.network_detection, | 50 | self.ui.initializePage() |
1884 | 62 | "wizard", FakeWizardButtonStyle) | 51 | self.assertTrue(self.ui.btn_try_again.isDefault()) |
1885 | 63 | self.network_detection.initializePage() | 52 | self.assertIn('polish', self.ui.btn_try_again.data) |
1886 | 64 | self.assertTrue(self.network_detection.btn_try_again.isDefault()) | 53 | self.assertIn('unpolish', self.ui.btn_try_again.data) |
1887 | 65 | self.assertIn('polish', self.network_detection.btn_try_again.data) | 54 | self.assertEqual( |
1888 | 66 | self.assertIn('unpolish', self.network_detection.btn_try_again.data) | 55 | self.ui.btn_try_again.data['polish'], |
1889 | 67 | self.assertEqual( | 56 | self.ui.btn_try_again) |
1890 | 68 | self.network_detection.btn_try_again.data['polish'], | 57 | self.assertEqual( |
1891 | 69 | self.network_detection.btn_try_again) | 58 | self.ui.btn_try_again.data['unpolish'], |
1892 | 70 | self.assertEqual( | 59 | self.ui.btn_try_again) |
1881 | 71 | self.network_detection.btn_try_again.data['unpolish'], | ||
1882 | 72 | self.network_detection.btn_try_again) | ||
1893 | 73 | 60 | ||
1894 | 74 | def test_try_again_with_connection(self): | 61 | def test_try_again_with_connection(self): |
1895 | 75 | """Check try again method with connection.""" | 62 | """Check try again method with connection.""" |
1896 | @@ -78,7 +65,7 @@ | |||
1897 | 78 | self.wizard._next_id = -1 | 65 | self.wizard._next_id = -1 |
1898 | 79 | if 'next' in self.wizard.data: | 66 | if 'next' in self.wizard.data: |
1899 | 80 | self.wizard.data.pop('next') | 67 | self.wizard.data.pop('next') |
1901 | 81 | self.network_detection.try_again() | 68 | self.ui.try_again() |
1902 | 82 | self.assertEqual(self.wizard._next_id, None) | 69 | self.assertEqual(self.wizard._next_id, None) |
1903 | 83 | self.assertTrue(self.wizard.data.get('next', False)) | 70 | self.assertTrue(self.wizard.data.get('next', False)) |
1904 | 84 | 71 | ||
1905 | @@ -89,7 +76,6 @@ | |||
1906 | 89 | self.wizard._next_id = -1 | 76 | self.wizard._next_id = -1 |
1907 | 90 | if 'next' in self.wizard.data: | 77 | if 'next' in self.wizard.data: |
1908 | 91 | self.wizard.data.pop('next') | 78 | self.wizard.data.pop('next') |
1910 | 92 | self.network_detection.try_again() | 79 | self.ui.try_again() |
1911 | 93 | self.assertEqual(self.wizard._next_id, -1) | 80 | self.assertEqual(self.wizard._next_id, -1) |
1912 | 94 | self.assertFalse(self.wizard.data.get('next', False)) | 81 | self.assertFalse(self.wizard.data.get('next', False)) |
1913 | 95 | # pylint: enable=W0212 | ||
1914 | 96 | 82 | ||
1915 | === modified file 'ubuntu_sso/qt/tests/test_reset_password.py' | |||
1916 | --- ubuntu_sso/qt/tests/test_reset_password.py 2012-02-15 17:33:40 +0000 | |||
1917 | +++ ubuntu_sso/qt/tests/test_reset_password.py 2012-02-24 17:28:19 +0000 | |||
1918 | @@ -18,40 +18,19 @@ | |||
1919 | 18 | # pylint: disable=F0401,E0611,E1101 | 18 | # pylint: disable=F0401,E0611,E1101 |
1920 | 19 | 19 | ||
1921 | 20 | from PyQt4 import QtGui, QtCore | 20 | from PyQt4 import QtGui, QtCore |
1922 | 21 | from twisted.internet import defer | ||
1923 | 22 | 21 | ||
1924 | 23 | from ubuntu_sso.utils.ui import ( | 22 | from ubuntu_sso.utils.ui import ( |
1925 | 24 | PASSWORD1_ENTRY, | 23 | PASSWORD1_ENTRY, |
1926 | 25 | PASSWORD2_ENTRY, | 24 | PASSWORD2_ENTRY, |
1929 | 26 | RESET_CODE_ENTRY) | 25 | RESET_CODE_ENTRY, |
1930 | 27 | from ubuntu_sso.qt import gui | 26 | ) |
1931 | 28 | from ubuntu_sso.qt import common | 27 | from ubuntu_sso.qt import common |
1932 | 29 | from ubuntu_sso.qt.reset_password_page import ( | 28 | from ubuntu_sso.qt.reset_password_page import ( |
1933 | 30 | ResetPasswordPage, | 29 | ResetPasswordPage, |
1934 | 31 | RESET_SUBTITLE, | 30 | RESET_SUBTITLE, |
1935 | 32 | RESET_TITLE, | 31 | RESET_TITLE, |
1936 | 33 | ) | 32 | ) |
1958 | 34 | from ubuntu_sso.qt.ui.reset_password_ui import Ui_ResetPasswordPage | 33 | from ubuntu_sso.qt.tests import BaseTestCase |
1938 | 35 | from ubuntu_sso.qt.tests import ( | ||
1939 | 36 | BaseTestCase, | ||
1940 | 37 | FakedBackend, | ||
1941 | 38 | FakedObject, | ||
1942 | 39 | FakeWizard, | ||
1943 | 40 | ) | ||
1944 | 41 | |||
1945 | 42 | |||
1946 | 43 | class FakePasswordAssistance(object): | ||
1947 | 44 | """Fake password_assistance_* calls.""" | ||
1948 | 45 | |||
1949 | 46 | _called = False | ||
1950 | 47 | |||
1951 | 48 | def call(self, *args, **kwargs): | ||
1952 | 49 | """Check if the method was called.""" | ||
1953 | 50 | FakePasswordAssistance._called = True | ||
1954 | 51 | |||
1955 | 52 | def clenaup(self): | ||
1956 | 53 | """Clean up the variable.""" | ||
1957 | 54 | FakePasswordAssistance._called = False | ||
1959 | 55 | 34 | ||
1960 | 56 | 35 | ||
1961 | 57 | # We need this Fake until a future refactor. | 36 | # We need this Fake until a future refactor. |
1962 | @@ -78,19 +57,11 @@ | |||
1963 | 78 | class ResetPasswordTestCase(BaseTestCase): | 57 | class ResetPasswordTestCase(BaseTestCase): |
1964 | 79 | """Test the ResetPasswordPage code.""" | 58 | """Test the ResetPasswordPage code.""" |
1965 | 80 | 59 | ||
1977 | 81 | @defer.inlineCallbacks | 60 | ui_class = ResetPasswordPage |
1978 | 82 | def setUp(self): | 61 | ui_signals = ('passwordChanged',) |
1979 | 83 | yield super(ResetPasswordTestCase, self).setUp() | 62 | ui_backend_siganls = ('PasswordChanged', 'PasswordChangeError') |
1969 | 84 | self.patch(gui.main, "get_sso_client", FakedBackend) | ||
1970 | 85 | self.app_name = 'my_app' | ||
1971 | 86 | self.ui = ResetPasswordPage(Ui_ResetPasswordPage(), | ||
1972 | 87 | app_name=self.app_name, | ||
1973 | 88 | parent=None) | ||
1974 | 89 | self.wizard = FakeWizard() | ||
1975 | 90 | self.patch(self.ui, 'wizard', lambda: self.wizard) | ||
1976 | 91 | self.fake = FakePasswordAssistance() | ||
1980 | 92 | 63 | ||
1982 | 93 | def test_init(self): | 64 | def test_password_line(self): |
1983 | 94 | """Check the initial state of ResetPassword.""" | 65 | """Check the initial state of ResetPassword.""" |
1984 | 95 | self.assertEqual(self.ui.ui.password_line_edit.receivers( | 66 | self.assertEqual(self.ui.ui.password_line_edit.receivers( |
1985 | 96 | QtCore.SIGNAL('textEdited(QString)')), 1) | 67 | QtCore.SIGNAL('textEdited(QString)')), 1) |
1986 | @@ -131,25 +102,27 @@ | |||
1987 | 131 | 102 | ||
1988 | 132 | def test_focus_changed_1(self): | 103 | def test_focus_changed_1(self): |
1989 | 133 | """Check functions execution when focus_changed() is executed.""" | 104 | """Check functions execution when focus_changed() is executed.""" |
1992 | 134 | self.patch(common, 'password_default_assistance', self.fake.call) | 105 | self.patch(common, 'password_default_assistance', self._set_called) |
1993 | 135 | self.addCleanup(self.fake.clenaup) | 106 | |
1994 | 136 | self.ui.show() | 107 | self.ui.show() |
1995 | 137 | self.addCleanup(self.ui.hide) | 108 | self.addCleanup(self.ui.hide) |
1997 | 138 | self.assertFalse(FakePasswordAssistance._called) | 109 | |
1998 | 110 | self.assertFalse(self._called) | ||
1999 | 139 | self.ui.focus_changed(None, self.ui.ui.password_line_edit) | 111 | self.ui.focus_changed(None, self.ui.ui.password_line_edit) |
2000 | 140 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) | 112 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
2002 | 141 | self.assertTrue(FakePasswordAssistance._called) | 113 | self.assertTrue(self._called) |
2003 | 142 | 114 | ||
2004 | 143 | def test_focus_changed_2(self): | 115 | def test_focus_changed_2(self): |
2005 | 144 | """Check functions execution when focus_changed() is executed.""" | 116 | """Check functions execution when focus_changed() is executed.""" |
2008 | 145 | self.patch(common, 'password_check_match', self.fake.call) | 117 | self.patch(common, 'password_check_match', self._set_called) |
2009 | 146 | self.addCleanup(self.fake.clenaup) | 118 | |
2010 | 147 | self.ui.show() | 119 | self.ui.show() |
2011 | 148 | self.addCleanup(self.ui.hide) | 120 | self.addCleanup(self.ui.hide) |
2013 | 149 | self.assertFalse(FakePasswordAssistance._called) | 121 | |
2014 | 122 | self.assertFalse(self._called) | ||
2015 | 150 | self.ui.focus_changed(None, self.ui.ui.confirm_password_line_edit) | 123 | self.ui.focus_changed(None, self.ui.ui.confirm_password_line_edit) |
2016 | 151 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) | 124 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
2018 | 152 | self.assertTrue(FakePasswordAssistance._called) | 125 | self.assertTrue(self._called) |
2019 | 153 | 126 | ||
2020 | 154 | # pylint: enable=W0212 | 127 | # pylint: enable=W0212 |
2021 | 155 | 128 | ||
2022 | @@ -161,12 +134,10 @@ | |||
2023 | 161 | forgotten = FakeForgottenPage() | 134 | forgotten = FakeForgottenPage() |
2024 | 162 | forgotten.setText(email) | 135 | forgotten.setText(email) |
2025 | 163 | self.patch(self.wizard, "forgotten", forgotten) | 136 | self.patch(self.wizard, "forgotten", forgotten) |
2026 | 164 | exposed_methods = ['set_new_password'] | ||
2027 | 165 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
2028 | 166 | faked_object = FakedObject() | ||
2029 | 167 | self.patch(self.ui, "backend", faked_object) | ||
2030 | 168 | self.ui.ui.reset_code_line_edit.setText(code) | 137 | self.ui.ui.reset_code_line_edit.setText(code) |
2031 | 169 | self.ui.ui.password_line_edit.setText(password) | 138 | self.ui.ui.password_line_edit.setText(password) |
2032 | 139 | |||
2033 | 170 | self.ui.set_new_password() | 140 | self.ui.set_new_password() |
2034 | 141 | |||
2035 | 171 | self.assert_backend_called('set_new_password', | 142 | self.assert_backend_called('set_new_password', |
2036 | 172 | self.app_name, email, code, password) | 143 | self.app_name, email, code, password) |
2037 | 173 | 144 | ||
2038 | === modified file 'ubuntu_sso/qt/tests/test_setup_account.py' | |||
2039 | --- ubuntu_sso/qt/tests/test_setup_account.py 2012-02-18 15:12:09 +0000 | |||
2040 | +++ ubuntu_sso/qt/tests/test_setup_account.py 2012-02-24 17:28:19 +0000 | |||
2041 | @@ -18,45 +18,22 @@ | |||
2042 | 18 | 18 | ||
2043 | 19 | from PyQt4 import QtGui, QtCore | 19 | from PyQt4 import QtGui, QtCore |
2044 | 20 | 20 | ||
2050 | 21 | from twisted.internet import defer | 21 | from ubuntu_sso.qt import common, setup_account_page |
2046 | 22 | |||
2047 | 23 | from ubuntu_sso.qt import gui | ||
2048 | 24 | from ubuntu_sso.qt import common | ||
2049 | 25 | from ubuntu_sso.qt import setup_account_page | ||
2051 | 26 | from ubuntu_sso.qt.tests import ( | 22 | from ubuntu_sso.qt.tests import ( |
2052 | 27 | BaseTestCase, | 23 | BaseTestCase, |
2058 | 28 | FakedBackend, | 24 | HELP_TEXT, |
2054 | 29 | FakedObject, | ||
2055 | 30 | FakeOverlay, | ||
2056 | 31 | FakeSignal, | ||
2057 | 32 | FakeWizard, | ||
2059 | 33 | ) | 25 | ) |
2060 | 34 | from ubuntu_sso.qt.ui import setup_account_ui | ||
2061 | 35 | 26 | ||
2062 | 36 | 27 | ||
2063 | 37 | class SetupAccountTestCase(BaseTestCase): | 28 | class SetupAccountTestCase(BaseTestCase): |
2064 | 38 | """Test the SetupAccountPage code.""" | 29 | """Test the SetupAccountPage code.""" |
2065 | 39 | 30 | ||
2084 | 40 | @defer.inlineCallbacks | 31 | ui_class = setup_account_page.SetupAccountPage |
2085 | 41 | def setUp(self): | 32 | ui_signals = ('userRegistered',) |
2086 | 42 | yield super(SetupAccountTestCase, self).setUp() | 33 | ui_backend_signals = ('CaptchaGenerated', 'CaptchaGenerationError', |
2087 | 43 | self.patch(gui.main, "get_sso_client", FakedBackend) | 34 | 'UserRegistered', 'UserRegistrationError') |
2070 | 44 | self.signals_results = [] | ||
2071 | 45 | self.patch(setup_account_page.SetupAccountPage, | ||
2072 | 46 | "userRegistered", FakeSignal()) | ||
2073 | 47 | self.app_name = 'my_app' | ||
2074 | 48 | self.ui = setup_account_page.SetupAccountPage( | ||
2075 | 49 | setup_account_ui.Ui_SetUpAccountPage(), | ||
2076 | 50 | 'subtitle', | ||
2077 | 51 | 'toc_link', | ||
2078 | 52 | 'policy_link', | ||
2079 | 53 | app_name=self.app_name, | ||
2080 | 54 | parent=None) | ||
2081 | 55 | self.wizard = FakeWizard() | ||
2082 | 56 | self.patch(self.ui, 'wizard', lambda: self.wizard) | ||
2083 | 57 | self.patch(self.ui, "set_up_button", QtGui.QPushButton()) | ||
2088 | 58 | 35 | ||
2090 | 59 | def test_init(self): | 36 | def test_password_receiver(self): |
2091 | 60 | """Check the initial state of SetupAccount.""" | 37 | """Check the initial state of SetupAccount.""" |
2092 | 61 | self.assertEqual(self.ui.ui.password_edit.receivers( | 38 | self.assertEqual(self.ui.ui.password_edit.receivers( |
2093 | 62 | QtCore.SIGNAL('textEdited(QString)')), 2) | 39 | QtCore.SIGNAL('textEdited(QString)')), 2) |
2094 | @@ -79,6 +56,8 @@ | |||
2095 | 79 | 56 | ||
2096 | 80 | def test_enable_setup_button_with_visible_check(self): | 57 | def test_enable_setup_button_with_visible_check(self): |
2097 | 81 | """Test _enable_setup_button method with terms check visible.""" | 58 | """Test _enable_setup_button method with terms check visible.""" |
2098 | 59 | self.patch(self.ui, "set_up_button", QtGui.QPushButton()) | ||
2099 | 60 | |||
2100 | 82 | self.ui.ui.name_edit.setText('name') | 61 | self.ui.ui.name_edit.setText('name') |
2101 | 83 | email = 'email@example.com' | 62 | email = 'email@example.com' |
2102 | 84 | self.ui.ui.email_edit.setText(email) | 63 | self.ui.ui.email_edit.setText(email) |
2103 | @@ -97,6 +76,8 @@ | |||
2104 | 97 | 76 | ||
2105 | 98 | def test_enable_setup_button_without_visible_check(self): | 77 | def test_enable_setup_button_without_visible_check(self): |
2106 | 99 | """Test _enable_setup_button method with terms check not visible.""" | 78 | """Test _enable_setup_button method with terms check not visible.""" |
2107 | 79 | self.patch(self.ui, "set_up_button", QtGui.QPushButton()) | ||
2108 | 80 | |||
2109 | 100 | self.ui.ui.name_edit.setText('name') | 81 | self.ui.ui.name_edit.setText('name') |
2110 | 101 | email = 'email@example.com' | 82 | email = 'email@example.com' |
2111 | 102 | self.ui.ui.email_edit.setText(email) | 83 | self.ui.ui.email_edit.setText(email) |
2112 | @@ -170,10 +151,6 @@ | |||
2113 | 170 | 151 | ||
2114 | 171 | def test_on_user_registered(self): | 152 | def test_on_user_registered(self): |
2115 | 172 | """Test on_user_registered method.""" | 153 | """Test on_user_registered method.""" |
2116 | 173 | exposed_methods = ['register_user'] | ||
2117 | 174 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
2118 | 175 | faked_object = FakedObject() | ||
2119 | 176 | self.patch(self.ui, "backend", faked_object) | ||
2120 | 177 | self.patch(self.ui, "validate_form", lambda: True) | 154 | self.patch(self.ui, "validate_form", lambda: True) |
2121 | 178 | 155 | ||
2122 | 179 | email = 'email@example' | 156 | email = 'email@example' |
2123 | @@ -190,8 +167,11 @@ | |||
2124 | 190 | def slot(email, password): | 167 | def slot(email, password): |
2125 | 191 | """Fake slot.""" | 168 | """Fake slot.""" |
2126 | 192 | self.signals_results.append((email, password)) | 169 | self.signals_results.append((email, password)) |
2127 | 170 | |||
2128 | 193 | self.ui.userRegistered.connect(slot) | 171 | self.ui.userRegistered.connect(slot) |
2129 | 172 | |||
2130 | 194 | self.ui.set_next_validation() | 173 | self.ui.set_next_validation() |
2131 | 174 | |||
2132 | 195 | self.assertIn((email, password), self.signals_results) | 175 | self.assertIn((email, password), self.signals_results) |
2133 | 196 | self.assert_backend_called('register_user', | 176 | self.assert_backend_called('register_user', |
2134 | 197 | self.app_name, email, password, name, captcha_id, | 177 | self.app_name, email, password, name, captcha_id, |
2135 | @@ -217,29 +197,6 @@ | |||
2136 | 217 | self.assert_backend_called('generate_captcha', | 197 | self.assert_backend_called('generate_captcha', |
2137 | 218 | self.app_name, self.ui.captcha_file) | 198 | self.app_name, self.ui.captcha_file) |
2138 | 219 | 199 | ||
2139 | 220 | |||
2140 | 221 | class SetupAccountFakeWizardTestCase(BaseTestCase): | ||
2141 | 222 | """Test the SetupAccountPage code.""" | ||
2142 | 223 | |||
2143 | 224 | @defer.inlineCallbacks | ||
2144 | 225 | def setUp(self): | ||
2145 | 226 | """Initialize this test instance.""" | ||
2146 | 227 | # Faking each SSO object instead of doing it lower | ||
2147 | 228 | # so we don't rely on any SSO behaviour | ||
2148 | 229 | yield super(SetupAccountFakeWizardTestCase, self).setUp() | ||
2149 | 230 | self.patch(gui, "LoadingOverlay", FakeOverlay) | ||
2150 | 231 | self.app_name = 'my_app' | ||
2151 | 232 | self._subtitle = 'subtitle' | ||
2152 | 233 | self.ui = setup_account_page.SetupAccountPage( | ||
2153 | 234 | setup_account_ui.Ui_SetUpAccountPage(), | ||
2154 | 235 | self._subtitle, | ||
2155 | 236 | 'toc_link', | ||
2156 | 237 | 'policy_link', | ||
2157 | 238 | app_name=self.app_name, | ||
2158 | 239 | parent=None) | ||
2159 | 240 | self.wizard = FakeWizard() | ||
2160 | 241 | self.patch(self.ui, 'wizard', lambda: self.wizard) | ||
2161 | 242 | |||
2162 | 243 | def test_initialize_page(self): | 200 | def test_initialize_page(self): |
2163 | 244 | """Widgets are properly initialized.""" | 201 | """Widgets are properly initialized.""" |
2164 | 245 | self.ui.initializePage() | 202 | self.ui.initializePage() |
2165 | @@ -251,7 +208,11 @@ | |||
2166 | 251 | title_expected = (setup_account_page.TITLE_STYLE % | 208 | title_expected = (setup_account_page.TITLE_STYLE % |
2167 | 252 | setup_account_page.TITLE.format(app_name=self.app_name)) | 209 | setup_account_page.TITLE.format(app_name=self.app_name)) |
2168 | 253 | self.assertEqual(title, title_expected) | 210 | self.assertEqual(title, title_expected) |
2170 | 254 | self.assertEqual(self.ui.header.subtitle_label.text(), self._subtitle) | 211 | |
2171 | 212 | elided_text = unicode(self.ui.header.subtitle_label.text()) | ||
2172 | 213 | elided_text = elided_text[:len(elided_text) - 1] | ||
2173 | 214 | self.assertTrue(HELP_TEXT.startswith(elided_text)) | ||
2174 | 215 | self.assertEqual(self.ui.header.subtitle_label.toolTip(), HELP_TEXT) | ||
2175 | 255 | 216 | ||
2176 | 256 | # set up account button | 217 | # set up account button |
2177 | 257 | expected = [QtGui.QWizard.BackButton, QtGui.QWizard.Stretch, | 218 | expected = [QtGui.QWizard.BackButton, QtGui.QWizard.Stretch, |
2178 | 258 | 219 | ||
2179 | === removed file 'ubuntu_sso/qt/tests/test_sign_in_page.py' | |||
2180 | --- ubuntu_sso/qt/tests/test_sign_in_page.py 2012-02-15 17:33:40 +0000 | |||
2181 | +++ ubuntu_sso/qt/tests/test_sign_in_page.py 1970-01-01 00:00:00 +0000 | |||
2182 | @@ -1,69 +0,0 @@ | |||
2183 | 1 | # -*- coding: utf-8 -*- | ||
2184 | 2 | # | ||
2185 | 3 | # Copyright 2012 Canonical Ltd. | ||
2186 | 4 | # | ||
2187 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
2188 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
2189 | 7 | # by the Free Software Foundation. | ||
2190 | 8 | # | ||
2191 | 9 | # This program is distributed in the hope that it will be useful, but | ||
2192 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2193 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2194 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
2195 | 13 | # | ||
2196 | 14 | # You should have received a copy of the GNU General Public License along | ||
2197 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2198 | 16 | |||
2199 | 17 | """The test suite for Sign In UI.""" | ||
2200 | 18 | |||
2201 | 19 | from PyQt4 import QtGui | ||
2202 | 20 | from twisted.internet import defer | ||
2203 | 21 | |||
2204 | 22 | from ubuntu_sso.qt import sign_in_page as gui | ||
2205 | 23 | from ubuntu_sso.qt.ui.choose_sign_in_ui import Ui_ChooseSignInPage | ||
2206 | 24 | from ubuntu_sso.qt.tests import BaseTestCase, FakeMainWindow, FakeSignal | ||
2207 | 25 | |||
2208 | 26 | |||
2209 | 27 | class SignInPageTestCase(BaseTestCase): | ||
2210 | 28 | """Test the SignInPage code.""" | ||
2211 | 29 | |||
2212 | 30 | @defer.inlineCallbacks | ||
2213 | 31 | def setUp(self): | ||
2214 | 32 | """Initialize this test instance.""" | ||
2215 | 33 | yield super(SignInPageTestCase, self).setUp() | ||
2216 | 34 | self.signals_results = [] | ||
2217 | 35 | self.patch(gui.SignInPage, "existingAccountSelected", FakeSignal()) | ||
2218 | 36 | self.patch(gui.SignInPage, "newAccountSelected", FakeSignal()) | ||
2219 | 37 | self.patch(gui.SignInPage, "singInCanceled", FakeSignal()) | ||
2220 | 38 | self.ui = gui.SignInPage(Ui_ChooseSignInPage(), QtGui.QPixmap()) | ||
2221 | 39 | |||
2222 | 40 | def test_show_event(self): | ||
2223 | 41 | """Check the page is initialized correctly.""" | ||
2224 | 42 | wizard = FakeMainWindow() | ||
2225 | 43 | self.patch(self.ui, 'wizard', lambda *args: wizard) | ||
2226 | 44 | self.ui.initializePage() | ||
2227 | 45 | self.ui.show() | ||
2228 | 46 | self.addCleanup(self.ui.hide) | ||
2229 | 47 | self.assertTrue(self.ui.ui.existing_account_button.isDefault()) | ||
2230 | 48 | |||
2231 | 49 | # pylint: disable=W0212 | ||
2232 | 50 | def test_set_next_existing(self): | ||
2233 | 51 | """Test _set_next_existing method.""" | ||
2234 | 52 | |||
2235 | 53 | def slot(): | ||
2236 | 54 | """Fake slot.""" | ||
2237 | 55 | self.signals_results.append(1) | ||
2238 | 56 | self.ui.existingAccountSelected.connect(slot) | ||
2239 | 57 | self.ui._set_next_existing() | ||
2240 | 58 | self.assertIn(1, self.signals_results) | ||
2241 | 59 | |||
2242 | 60 | def test_set_next_new(self): | ||
2243 | 61 | """Test _set_next_existing method.""" | ||
2244 | 62 | |||
2245 | 63 | def slot(): | ||
2246 | 64 | """Fake slot.""" | ||
2247 | 65 | self.signals_results.append(1) | ||
2248 | 66 | self.ui.newAccountSelected.connect(slot) | ||
2249 | 67 | self.ui._set_next_new() | ||
2250 | 68 | self.assertIn(1, self.signals_results) | ||
2251 | 69 | # pylint: enable=W0212 | ||
2252 | 70 | 0 | ||
2253 | === renamed file 'ubuntu_sso/qt/tests/test_qt_views.py' => 'ubuntu_sso/qt/tests/test_sso_wizard_page.py' | |||
2254 | --- ubuntu_sso/qt/tests/test_qt_views.py 2012-02-24 13:57:19 +0000 | |||
2255 | +++ ubuntu_sso/qt/tests/test_sso_wizard_page.py 2012-02-24 17:28:19 +0000 | |||
2256 | @@ -13,107 +13,23 @@ | |||
2257 | 13 | # | 13 | # |
2258 | 14 | # You should have received a copy of the GNU General Public License along | 14 | # You should have received a copy of the GNU General Public License along |
2259 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
2270 | 16 | """Test the interaction of the view with the auto generated code.""" | 16 | |
2271 | 17 | 17 | """Test the SSOWizardPage and related.""" | |
2272 | 18 | from unittest import TestCase | 18 | |
2273 | 19 | from mocker import MATCH, Mocker | 19 | from twisted.internet import defer |
2264 | 20 | |||
2265 | 21 | from PyQt4 import QtGui | ||
2266 | 22 | |||
2267 | 23 | from ubuntu_sso.qt.error_page import ErrorPage | ||
2268 | 24 | from ubuntu_sso.qt.sign_in_page import SignInPage | ||
2269 | 25 | from ubuntu_sso.qt.success_page import SuccessPage | ||
2274 | 26 | 20 | ||
2275 | 27 | from ubuntu_sso.qt import PREFERED_UI_SIZE | 21 | from ubuntu_sso.qt import PREFERED_UI_SIZE |
2360 | 28 | from ubuntu_sso.qt.gui import Header | 22 | from ubuntu_sso.qt.sso_wizard_page import Header |
2361 | 29 | from ubuntu_sso.qt.ui.choose_sign_in_ui import Ui_ChooseSignInPage | 23 | from ubuntu_sso.qt.tests import BaseTestCase |
2362 | 30 | from ubuntu_sso.qt.ui.error_message_ui import Ui_ErrorPage | 24 | |
2363 | 31 | from ubuntu_sso.qt.ui.success_message_ui import Ui_SuccessPage | 25 | |
2364 | 32 | 26 | class HeaderTest(BaseTestCase): | |
2365 | 33 | 27 | ||
2282 | 34 | class FakeController(object): | ||
2283 | 35 | """A fake controller for the tests.""" | ||
2284 | 36 | |||
2285 | 37 | # pylint: disable=C0103 | ||
2286 | 38 | def setupUi(self, view): | ||
2287 | 39 | """Fake the setup.""" | ||
2288 | 40 | # pylint: enable=C0103 | ||
2289 | 41 | |||
2290 | 42 | |||
2291 | 43 | class ChooseSignInPageTestCase(TestCase): | ||
2292 | 44 | """Test the ChooseSignInPage.""" | ||
2293 | 45 | |||
2294 | 46 | def setUp(self): | ||
2295 | 47 | """Set up the tests.""" | ||
2296 | 48 | super(ChooseSignInPageTestCase, self).setUp() | ||
2297 | 49 | self.ui = Ui_ChooseSignInPage() | ||
2298 | 50 | self.controller = FakeController() | ||
2299 | 51 | self.widget = SignInPage(self.ui, QtGui.QPixmap()) | ||
2300 | 52 | |||
2301 | 53 | def tearDown(self): | ||
2302 | 54 | self.widget.close() | ||
2303 | 55 | |||
2304 | 56 | def test_constructor(self): | ||
2305 | 57 | """Test the constructor of the class.""" | ||
2306 | 58 | # used a mocked ui for this | ||
2307 | 59 | mocker = Mocker() | ||
2308 | 60 | ui = mocker.mock() | ||
2309 | 61 | ui.setupUi(MATCH(lambda x: isinstance(x, SignInPage))) | ||
2310 | 62 | mocker.replay() | ||
2311 | 63 | self.widget = SignInPage(self.ui, QtGui.QPixmap()) | ||
2312 | 64 | |||
2313 | 65 | def test_next_id(self): | ||
2314 | 66 | """Test the nextId method.""" | ||
2315 | 67 | next_id = 1 | ||
2316 | 68 | self.widget.next = next_id | ||
2317 | 69 | self.assertEqual(next_id, self.widget.nextId()) | ||
2318 | 70 | |||
2319 | 71 | |||
2320 | 72 | class SuccessPageTestCase(TestCase): | ||
2321 | 73 | """Test that the correct widgets are used.""" | ||
2322 | 74 | |||
2323 | 75 | def setUp(self): | ||
2324 | 76 | """Setup tests.""" | ||
2325 | 77 | super(SuccessPageTestCase, self).setUp() | ||
2326 | 78 | self.ui = Ui_SuccessPage() | ||
2327 | 79 | self.widget = SuccessPage(self.ui, QtGui.QPixmap()) | ||
2328 | 80 | |||
2329 | 81 | def test_constructor(self): | ||
2330 | 82 | """Test that the constructor works as expected.""" | ||
2331 | 83 | mocker = Mocker() | ||
2332 | 84 | ui = mocker.mock() | ||
2333 | 85 | ui.setupUi(MATCH(lambda x: isinstance(x, SuccessPage))) | ||
2334 | 86 | mocker.replay() | ||
2335 | 87 | self.widget = SuccessPage(self.ui, QtGui.QPixmap()) | ||
2336 | 88 | |||
2337 | 89 | |||
2338 | 90 | class ErrorPageTestCase(TestCase): | ||
2339 | 91 | """Test that the correct widgets are used.""" | ||
2340 | 92 | |||
2341 | 93 | def setUp(self): | ||
2342 | 94 | """Setup tests.""" | ||
2343 | 95 | super(ErrorPageTestCase, self).setUp() | ||
2344 | 96 | self.ui = Ui_ErrorPage() | ||
2345 | 97 | self.controller = FakeController() | ||
2346 | 98 | self.widget = ErrorPage(self.ui, self.controller) | ||
2347 | 99 | |||
2348 | 100 | def test_constructor(self): | ||
2349 | 101 | """Test that the constructor works as expected.""" | ||
2350 | 102 | mocker = Mocker() | ||
2351 | 103 | ui = mocker.mock() | ||
2352 | 104 | controller = mocker.mock() | ||
2353 | 105 | ui.setupUi(MATCH(lambda x: isinstance(x, ErrorPage))) | ||
2354 | 106 | controller.setupUi(MATCH(lambda x: isinstance(x, ErrorPage))) | ||
2355 | 107 | mocker.replay() | ||
2356 | 108 | self.widget = ErrorPage(self.ui, self.controller) | ||
2357 | 109 | |||
2358 | 110 | |||
2359 | 111 | class HeaderTest(TestCase): | ||
2366 | 112 | """Tests for injected Header in each Wizard Page.""" | 28 | """Tests for injected Header in each Wizard Page.""" |
2367 | 113 | 29 | ||
2368 | 30 | @defer.inlineCallbacks | ||
2369 | 114 | def setUp(self): | 31 | def setUp(self): |
2372 | 115 | """Setup test.""" | 32 | yield super(HeaderTest, self).setUp() |
2371 | 116 | super(HeaderTest, self).setUp() | ||
2373 | 117 | self.header = Header() | 33 | self.header = Header() |
2374 | 118 | 34 | ||
2375 | 119 | def test_label_state(self): | 35 | def test_label_state(self): |
2376 | 120 | 36 | ||
2377 | === added file 'ubuntu_sso/qt/tests/test_success_page.py' | |||
2378 | --- ubuntu_sso/qt/tests/test_success_page.py 1970-01-01 00:00:00 +0000 | |||
2379 | +++ ubuntu_sso/qt/tests/test_success_page.py 2012-02-24 17:28:19 +0000 | |||
2380 | @@ -0,0 +1,26 @@ | |||
2381 | 1 | # -*- coding: utf-8 -*- | ||
2382 | 2 | # | ||
2383 | 3 | # Copyright 2012 Canonical Ltd. | ||
2384 | 4 | # | ||
2385 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
2386 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
2387 | 7 | # by the Free Software Foundation. | ||
2388 | 8 | # | ||
2389 | 9 | # This program is distributed in the hope that it will be useful, but | ||
2390 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2391 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2392 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
2393 | 13 | # | ||
2394 | 14 | # You should have received a copy of the GNU General Public License along | ||
2395 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2396 | 16 | |||
2397 | 17 | """Test the success page.""" | ||
2398 | 18 | |||
2399 | 19 | from ubuntu_sso.qt.success_page import SuccessPage | ||
2400 | 20 | from ubuntu_sso.qt.tests import BaseTestCase | ||
2401 | 21 | |||
2402 | 22 | |||
2403 | 23 | class SuccessPageTestCase(BaseTestCase): | ||
2404 | 24 | """Test that the correct widgets are used.""" | ||
2405 | 25 | |||
2406 | 26 | ui_class = SuccessPage | ||
2407 | 0 | 27 | ||
2408 | === modified file 'ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py' | |||
2409 | --- ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-02-24 14:58:30 +0000 | |||
2410 | +++ ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-02-24 17:28:19 +0000 | |||
2411 | @@ -20,21 +20,24 @@ | |||
2412 | 20 | from twisted.internet import defer | 20 | from twisted.internet import defer |
2413 | 21 | 21 | ||
2414 | 22 | from ubuntu_sso.qt import PREFERED_UI_SIZE, ubuntu_sso_wizard | 22 | from ubuntu_sso.qt import PREFERED_UI_SIZE, ubuntu_sso_wizard |
2423 | 23 | from ubuntu_sso.qt.tests import ( | 23 | from ubuntu_sso.qt.tests import BaseTestCase |
2424 | 24 | BaseTestCase, | 24 | |
2425 | 25 | FakedObject, | 25 | |
2426 | 26 | ) | 26 | # is ok to access private method/attrs in tests |
2427 | 27 | 27 | # pylint: disable=W0212 | |
2428 | 28 | 28 | ||
2429 | 29 | class ReturnCodeTestCase(BaseTestCase): | 29 | |
2430 | 30 | """Test the return codes.""" | 30 | class UbuntuSSOClientGUITestCase(BaseTestCase): |
2431 | 31 | |||
2432 | 32 | """Test the UbuntuSSOClientGUI class.""" | ||
2433 | 33 | |||
2434 | 34 | ui_class = ubuntu_sso_wizard.UbuntuSSOClientGUI | ||
2435 | 35 | ui_wizard_class = None | ||
2436 | 31 | 36 | ||
2437 | 32 | @defer.inlineCallbacks | 37 | @defer.inlineCallbacks |
2438 | 33 | def setUp(self): | 38 | def setUp(self): |
2440 | 34 | yield super(ReturnCodeTestCase, self).setUp() | 39 | yield super(UbuntuSSOClientGUITestCase, self).setUp() |
2441 | 35 | self.patch(ubuntu_sso_wizard.sys, 'exit', self._set_called) | 40 | self.patch(ubuntu_sso_wizard.sys, 'exit', self._set_called) |
2442 | 36 | self.app_name = 'app_name' | ||
2443 | 37 | self.ui = ubuntu_sso_wizard.UbuntuSSOClientGUI(self.app_name) | ||
2444 | 38 | 41 | ||
2445 | 39 | def test_closing_main_window(self): | 42 | def test_closing_main_window(self): |
2446 | 40 | """When closing the main window, USER_CANCELLATION is returned.""" | 43 | """When closing the main window, USER_CANCELLATION is returned.""" |
2447 | @@ -42,44 +45,36 @@ | |||
2448 | 42 | self.assertEqual(self._called, | 45 | self.assertEqual(self._called, |
2449 | 43 | ((ubuntu_sso_wizard.USER_CANCELLATION,), {})) | 46 | ((ubuntu_sso_wizard.USER_CANCELLATION,), {})) |
2450 | 44 | 47 | ||
2451 | 45 | # pylint: disable=W0212 | ||
2452 | 46 | def test_close_main_window_reaching_success_page(self): | 48 | def test_close_main_window_reaching_success_page(self): |
2453 | 47 | """Closing the window in success page, USER_SUCCESS is returned.""" | 49 | """Closing the window in success page, USER_SUCCESS is returned.""" |
2456 | 48 | email = 'email@example.com' | 50 | self.ui.wizard._move_to_success_page() |
2455 | 49 | self.ui.wizard._move_to_success_page(self.app_name, email) | ||
2457 | 50 | self.ui.close() | 51 | self.ui.close() |
2458 | 51 | self.assertEqual(self._called, | 52 | self.assertEqual(self._called, |
2459 | 52 | ((ubuntu_sso_wizard.USER_SUCCESS,), {})) | 53 | ((ubuntu_sso_wizard.USER_SUCCESS,), {})) |
2460 | 53 | # pylint: enable=W0212 | ||
2461 | 54 | 54 | ||
2463 | 55 | def test_closing_wizard(self): | 55 | def test_closing_wizard_no_parent(self): |
2464 | 56 | """When closing the wizard, USER_CANCELLATION is returned.""" | 56 | """When closing the wizard, USER_CANCELLATION is returned.""" |
2465 | 57 | self.ui.wizard.setParent(None) | 57 | self.ui.wizard.setParent(None) |
2466 | 58 | self.ui.wizard.close() | 58 | self.ui.wizard.close() |
2467 | 59 | self.assertEqual(self._called, | 59 | self.assertEqual(self._called, |
2468 | 60 | ((ubuntu_sso_wizard.USER_CANCELLATION,), {})) | 60 | ((ubuntu_sso_wizard.USER_CANCELLATION,), {})) |
2469 | 61 | 61 | ||
2472 | 62 | # pylint: disable=W0212 | 62 | def test_close_wizard_no_parent_reaching_success_page(self): |
2471 | 63 | def test_close_wizard_reaching_success_page(self): | ||
2473 | 64 | """Closing the wizard in success page, USER_SUCCESS is returned.""" | 63 | """Closing the wizard in success page, USER_SUCCESS is returned.""" |
2474 | 65 | self.ui.wizard.setParent(None) | 64 | self.ui.wizard.setParent(None) |
2477 | 66 | email = 'email@example.com' | 65 | self.ui.wizard._move_to_success_page() |
2476 | 67 | self.ui.wizard._move_to_success_page(self.app_name, email) | ||
2478 | 68 | self.ui.wizard.close() | 66 | self.ui.wizard.close() |
2479 | 69 | self.assertEqual(self._called, | 67 | self.assertEqual(self._called, |
2480 | 70 | ((ubuntu_sso_wizard.USER_SUCCESS,), {})) | 68 | ((ubuntu_sso_wizard.USER_SUCCESS,), {})) |
2481 | 71 | # pylint: enable=W0212 | ||
2482 | 72 | 69 | ||
2483 | 73 | 70 | ||
2484 | 74 | class UbuntuSSOWizardTestCase(BaseTestCase): | 71 | class UbuntuSSOWizardTestCase(BaseTestCase): |
2485 | 75 | 72 | ||
2487 | 76 | """Test Case for UbuntuSSOWizard""" | 73 | """Test case for UbuntuSSOWizard class.""" |
2488 | 77 | 74 | ||
2494 | 78 | @defer.inlineCallbacks | 75 | ui_class = ubuntu_sso_wizard.UbuntuSSOWizard |
2495 | 79 | def setUp(self): | 76 | ui_signals = ('recoverableError', 'loginSuccess', 'registrationSuccess') |
2496 | 80 | yield super(UbuntuSSOWizardTestCase, self).setUp() | 77 | ui_wizard_class = None |
2492 | 81 | self.app_name = 'app_name' | ||
2493 | 82 | self.ui = ubuntu_sso_wizard.UbuntuSSOWizard(self.app_name) | ||
2497 | 83 | 78 | ||
2498 | 84 | def test_window_size(self): | 79 | def test_window_size(self): |
2499 | 85 | """check the window size.""" | 80 | """check the window size.""" |
2500 | @@ -89,32 +84,13 @@ | |||
2501 | 89 | self.assertEqual(size.height(), PREFERED_UI_SIZE['height']) | 84 | self.assertEqual(size.height(), PREFERED_UI_SIZE['height']) |
2502 | 90 | self.assertEqual(size.width(), PREFERED_UI_SIZE['width']) | 85 | self.assertEqual(size.width(), PREFERED_UI_SIZE['width']) |
2503 | 91 | 86 | ||
2504 | 92 | # pylint: disable=W0212 | ||
2505 | 93 | def test_move_to_success_page_state(self): | 87 | def test_move_to_success_page_state(self): |
2506 | 94 | """Test _move_to_success_page method.""" | 88 | """Test _move_to_success_page method.""" |
2507 | 95 | self.patch(self.ui, 'setButtonLayout', self._set_called) | 89 | self.patch(self.ui, 'setButtonLayout', self._set_called) |
2509 | 96 | self.ui._move_to_success_page(self.app_name) | 90 | self.ui._move_to_success_page() |
2510 | 97 | self.assertEqual(self.ui._next_id, -1) | 91 | self.assertEqual(self.ui._next_id, -1) |
2511 | 98 | self.assertEqual(self.ui._next_id, -1) | 92 | self.assertEqual(self.ui._next_id, -1) |
2512 | 99 | self.assertEqual(self._called, | 93 | self.assertEqual(self._called, |
2513 | 100 | (([QtGui.QWizard.Stretch, QtGui.QWizard.FinishButton],), {})) | 94 | (([QtGui.QWizard.Stretch, QtGui.QWizard.FinishButton],), {})) |
2514 | 101 | self.assertTrue(self.ui.button(QtGui.QWizard.FinishButton).isEnabled()) | 95 | self.assertTrue(self.ui.button(QtGui.QWizard.FinishButton).isEnabled()) |
2534 | 102 | self.assertEqual(self.ui._done, ubuntu_sso_wizard.USER_SUCCESS) | 96 | self.assertEqual(self.ui.exit_code, ubuntu_sso_wizard.USER_SUCCESS) |
2516 | 103 | # pylint: enable=W0212 | ||
2517 | 104 | |||
2518 | 105 | # pylint: disable=W0212, E1101 | ||
2519 | 106 | def test_sing_in_canceled_connection(self): | ||
2520 | 107 | """Test if sign in canceled signal calls close and not reject.""" | ||
2521 | 108 | exposed_methods = [ | ||
2522 | 109 | 'close', | ||
2523 | 110 | 'reject'] | ||
2524 | 111 | self.patch(FakedObject, "exposed_methods", exposed_methods) | ||
2525 | 112 | faked_object = FakedObject() | ||
2526 | 113 | self.patch(self.ui, "closeEvent", faked_object.close) | ||
2527 | 114 | self.patch(self.ui, "reject", faked_object.reject) | ||
2528 | 115 | self.ui.show() | ||
2529 | 116 | self.addCleanup(self.ui.hide) | ||
2530 | 117 | self.ui.sign_in_page.ui.cancel_button.clicked.emit(True) | ||
2531 | 118 | self.assertIn('close', faked_object._called) | ||
2532 | 119 | self.assertNotIn('reject', faked_object._called) | ||
2533 | 120 | # pylint: enable=W0212, E1101 | ||
2535 | 121 | 97 | ||
2536 | === modified file 'ubuntu_sso/qt/ubuntu_sso_wizard.py' | |||
2537 | --- ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-02-24 14:58:30 +0000 | |||
2538 | +++ ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-02-24 17:28:19 +0000 | |||
2539 | @@ -1,5 +1,5 @@ | |||
2540 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
2542 | 2 | 2 | # | |
2543 | 3 | # Copyright 2012 Canonical Ltd. | 3 | # Copyright 2012 Canonical Ltd. |
2544 | 4 | # | 4 | # |
2545 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
2546 | @@ -21,14 +21,11 @@ | |||
2547 | 21 | from PyQt4.QtCore import pyqtSignal | 21 | from PyQt4.QtCore import pyqtSignal |
2548 | 22 | from PyQt4.QtGui import ( | 22 | from PyQt4.QtGui import ( |
2549 | 23 | QFrame, | 23 | QFrame, |
2550 | 24 | QPixmap, | ||
2551 | 25 | QVBoxLayout, | 24 | QVBoxLayout, |
2552 | 26 | QWizard, | 25 | QWizard, |
2553 | 27 | ) | 26 | ) |
2554 | 28 | from twisted.internet import defer | ||
2555 | 29 | 27 | ||
2556 | 30 | from ubuntu_sso import ( | 28 | from ubuntu_sso import ( |
2557 | 31 | NO_OP, | ||
2558 | 32 | USER_CANCELLATION, | 29 | USER_CANCELLATION, |
2559 | 33 | USER_SUCCESS, | 30 | USER_SUCCESS, |
2560 | 34 | ) | 31 | ) |
2561 | @@ -40,17 +37,7 @@ | |||
2562 | 40 | from ubuntu_sso.qt.forgotten_password_page import ForgottenPasswordPage | 37 | from ubuntu_sso.qt.forgotten_password_page import ForgottenPasswordPage |
2563 | 41 | from ubuntu_sso.qt.reset_password_page import ResetPasswordPage | 38 | from ubuntu_sso.qt.reset_password_page import ResetPasswordPage |
2564 | 42 | from ubuntu_sso.qt.setup_account_page import SetupAccountPage | 39 | from ubuntu_sso.qt.setup_account_page import SetupAccountPage |
2565 | 43 | from ubuntu_sso.qt.sign_in_page import SignInPage | ||
2566 | 44 | from ubuntu_sso.qt.success_page import SuccessPage | 40 | from ubuntu_sso.qt.success_page import SuccessPage |
2567 | 45 | from ubuntu_sso.qt.ui.choose_sign_in_ui import Ui_ChooseSignInPage | ||
2568 | 46 | from ubuntu_sso.qt.ui.current_user_sign_in_ui import Ui_CurrentUserSignInPage | ||
2569 | 47 | from ubuntu_sso.qt.ui.email_verification_ui import Ui_EmailVerificationPage | ||
2570 | 48 | from ubuntu_sso.qt.ui.error_message_ui import Ui_ErrorPage | ||
2571 | 49 | from ubuntu_sso.qt.ui.setup_account_ui import Ui_SetUpAccountPage | ||
2572 | 50 | from ubuntu_sso.qt.ui.success_message_ui import Ui_SuccessPage | ||
2573 | 51 | from ubuntu_sso.qt.ui.forgotten_password_ui import Ui_ForgottenPasswordPage | ||
2574 | 52 | from ubuntu_sso.qt.ui.reset_password_ui import Ui_ResetPasswordPage | ||
2575 | 53 | |||
2576 | 54 | 41 | ||
2577 | 55 | logger = setup_logging('ubuntu_sso.gui') | 42 | logger = setup_logging('ubuntu_sso.gui') |
2578 | 56 | 43 | ||
2579 | @@ -65,83 +52,61 @@ | |||
2580 | 65 | 52 | ||
2581 | 66 | def __init__(self, app_name, **kwargs): | 53 | def __init__(self, app_name, **kwargs): |
2582 | 67 | """Create a new wizard.""" | 54 | """Create a new wizard.""" |
2585 | 68 | parent = kwargs.get('parent') | 55 | logger.debug('UbuntuSSOWizard: app_name %r, kwargs %r.', |
2586 | 69 | super(UbuntuSSOWizard, self).__init__(parent) | 56 | app_name, kwargs) |
2587 | 57 | parent = kwargs.pop('parent', None) | ||
2588 | 58 | super(UbuntuSSOWizard, self).__init__(parent=parent) | ||
2589 | 70 | self._next_id = -1 | 59 | self._next_id = -1 |
2590 | 71 | self.setOption(QWizard.HaveFinishButtonOnEarlyPages, True) | 60 | self.setOption(QWizard.HaveFinishButtonOnEarlyPages, True) |
2592 | 72 | self._done = USER_CANCELLATION | 61 | self.setOption(QWizard.NoBackButtonOnStartPage, True) |
2593 | 62 | self.exit_code = USER_CANCELLATION | ||
2594 | 73 | 63 | ||
2595 | 74 | # store common useful data provided by the app | ||
2596 | 75 | self.app_name = app_name | 64 | self.app_name = app_name |
2606 | 76 | self.ping_url = kwargs.get('ping_url', '') | 65 | self.login_only = kwargs.pop('login_only', False) |
2607 | 77 | self.tc_url = kwargs.get('tc_url', '') | 66 | self.close_callback = kwargs.pop('close_callback', lambda: None) |
2608 | 78 | self.policy_url = kwargs.get('policy_url', '') | 67 | |
2609 | 79 | self.help_text = kwargs.get('help_text', '') | 68 | # store the ids of the pages so that it is easier to access them later |
2610 | 80 | self.login_only = kwargs.get('login_only', False) | 69 | self._pages = {} |
2611 | 81 | self.close_callback = kwargs.get('close_callback', lambda: None) | 70 | |
2612 | 82 | self.login_success_callback = NO_OP | 71 | # prepare kwargs to be suitable for the pages |
2613 | 83 | self.registration_success_callback = NO_OP | 72 | kwargs['app_name'] = self.app_name |
2614 | 84 | self.user_cancellation_callback = NO_OP | 73 | kwargs['parent'] = self |
2615 | 85 | 74 | ||
2616 | 86 | # set the diff pages of the QWizard | 75 | # set the diff pages of the QWizard |
2640 | 87 | self.sign_in_page = SignInPage(Ui_ChooseSignInPage(), | 76 | if not self.login_only: |
2641 | 88 | QPixmap(), | 77 | self.setup_account = SetupAccountPage(**kwargs) |
2642 | 89 | app_name=self.app_name, | 78 | self.setup_account.userRegistered.connect( |
2643 | 90 | parent=self) | 79 | self._move_to_email_verification_page) |
2644 | 91 | self.sign_in_page.singInCanceled.connect(self.close) | 80 | self.addPage(self.setup_account) |
2645 | 92 | self.sign_in_page.existingAccountSelected.connect( | 81 | |
2646 | 93 | self._move_to_login_page) | 82 | self.current_user = CurrentUserSignInPage(**kwargs) |
2624 | 94 | self.sign_in_page.newAccountSelected.connect( | ||
2625 | 95 | self._move_to_setup_account_page) | ||
2626 | 96 | |||
2627 | 97 | self.setup_account = SetupAccountPage(Ui_SetUpAccountPage(), | ||
2628 | 98 | self.help_text, | ||
2629 | 99 | self.tc_url, | ||
2630 | 100 | self.policy_url, | ||
2631 | 101 | app_name=self.app_name, | ||
2632 | 102 | parent=self) | ||
2633 | 103 | self.setup_account.userRegistered.connect( | ||
2634 | 104 | self._move_to_email_verification_page) | ||
2635 | 105 | |||
2636 | 106 | self.current_user = CurrentUserSignInPage(Ui_CurrentUserSignInPage(), | ||
2637 | 107 | self.ping_url, | ||
2638 | 108 | app_name=self.app_name, | ||
2639 | 109 | parent=self) | ||
2647 | 110 | self.current_user.userNotValidated.connect( | 83 | self.current_user.userNotValidated.connect( |
2648 | 111 | self._move_to_email_verification_page) | 84 | self._move_to_email_verification_page) |
2649 | 112 | self.current_user.userLoggedIn.connect(self._move_to_success_page) | 85 | self.current_user.userLoggedIn.connect(self._move_to_success_page) |
2650 | 113 | self.current_user.passwordForgotten.connect( | 86 | self.current_user.passwordForgotten.connect( |
2651 | 114 | self._move_to_forgotten_page) | 87 | self._move_to_forgotten_page) |
2652 | 88 | self.addPage(self.current_user) | ||
2653 | 115 | 89 | ||
2658 | 116 | self.email_verification = EmailVerificationPage( | 90 | self.email_verification = EmailVerificationPage(**kwargs) |
2655 | 117 | Ui_EmailVerificationPage(), | ||
2656 | 118 | self.ping_url, | ||
2657 | 119 | app_name=self.app_name) | ||
2659 | 120 | self.email_verification.registrationSuccess.connect( | 91 | self.email_verification.registrationSuccess.connect( |
2660 | 121 | self._move_to_success_page) | 92 | self._move_to_success_page) |
2669 | 122 | 93 | self.addPage(self.email_verification) | |
2670 | 123 | self.success = SuccessPage(Ui_SuccessPage(), QPixmap(), | 94 | |
2671 | 124 | app_name=self.app_name, parent=self) | 95 | self.success = SuccessPage(**kwargs) |
2672 | 125 | self.error = ErrorPage(Ui_ErrorPage(), | 96 | self.addPage(self.success) |
2673 | 126 | app_name=self.app_name) | 97 | |
2674 | 127 | self.forgotten = ForgottenPasswordPage(Ui_ForgottenPasswordPage(), | 98 | self.error = ErrorPage(**kwargs) |
2675 | 128 | app_name=self.app_name, | 99 | self.addPage(self.error) |
2676 | 129 | parent=self) | 100 | |
2677 | 101 | self.forgotten = ForgottenPasswordPage(**kwargs) | ||
2678 | 130 | self.forgotten.passwordResetTokenSent.connect( | 102 | self.forgotten.passwordResetTokenSent.connect( |
2679 | 131 | self._move_to_reset_password_page) | 103 | self._move_to_reset_password_page) |
2680 | 104 | self.addPage(self.forgotten) | ||
2681 | 132 | 105 | ||
2694 | 133 | self.reset_password = ResetPasswordPage(Ui_ResetPasswordPage(), | 106 | self.reset_password = ResetPasswordPage(**kwargs) |
2695 | 134 | app_name=self.app_name, | 107 | back = lambda *a: self._go_back_to_current_page(self.current_user) |
2696 | 135 | parent=self) | 108 | self.reset_password.passwordChanged.connect(back) |
2697 | 136 | self.reset_password.passwordChanged.connect( | 109 | self.addPage(self.reset_password) |
2686 | 137 | self._go_back_to_current_page) | ||
2687 | 138 | # store the ids of the pages so that it is easier to access them later | ||
2688 | 139 | pages = [self.sign_in_page, self.setup_account, | ||
2689 | 140 | self.email_verification, self.current_user, self.success, | ||
2690 | 141 | self.error, self.forgotten, self.reset_password] | ||
2691 | 142 | self._pages = {} | ||
2692 | 143 | for page in pages: | ||
2693 | 144 | self._pages[page] = self.addPage(page) | ||
2698 | 145 | 110 | ||
2699 | 146 | # set the buttons layout to only have cancel and back since the next | 111 | # set the buttons layout to only have cancel and back since the next |
2700 | 147 | # buttons are the ones used in the diff pages. | 112 | # buttons are the ones used in the diff pages. |
2701 | @@ -152,24 +117,29 @@ | |||
2702 | 152 | self.setButtonLayout(buttons_layout) | 117 | self.setButtonLayout(buttons_layout) |
2703 | 153 | self.setWindowTitle(self.app_name) | 118 | self.setWindowTitle(self.app_name) |
2704 | 154 | self.setWizardStyle(QWizard.ModernStyle) | 119 | self.setWizardStyle(QWizard.ModernStyle) |
2707 | 155 | self.button(QWizard.CancelButton).clicked.connect( | 120 | self.button(QWizard.CancelButton).clicked.connect(self.close) |
2706 | 156 | self.on_user_cancelation) | ||
2708 | 157 | self.setMinimumSize(PREFERED_UI_SIZE['width'], | 121 | self.setMinimumSize(PREFERED_UI_SIZE['width'], |
2709 | 158 | PREFERED_UI_SIZE['height']) | 122 | PREFERED_UI_SIZE['height']) |
2710 | 159 | 123 | ||
2711 | 160 | # pylint: disable=C0103 | 124 | # pylint: disable=C0103 |
2712 | 125 | |||
2713 | 161 | def nextId(self): | 126 | def nextId(self): |
2714 | 162 | """Return the id of the next page.""" | 127 | """Return the id of the next page.""" |
2715 | 163 | return self._next_id | 128 | return self._next_id |
2716 | 129 | |||
2717 | 130 | def addPage(self, page): | ||
2718 | 131 | """Add 'page' to this wizard.""" | ||
2719 | 132 | page_id = super(UbuntuSSOWizard, self).addPage(page) | ||
2720 | 133 | self._pages[page] = page_id | ||
2721 | 134 | |||
2722 | 164 | # pylint: enable=C0103 | 135 | # pylint: enable=C0103 |
2723 | 165 | 136 | ||
2728 | 166 | def _go_back_to_current_page(self, email): | 137 | def _go_back_to_page(self, page): |
2729 | 167 | """Move back until it reaches the current user sign in page. """ | 138 | """Move back until it reaches the 'page'.""" |
2730 | 168 | self.current_user.ui.email_edit.setText(email) | 139 | page_id = self._pages[page] |
2727 | 169 | current_user_id = self.current_user_page_id | ||
2731 | 170 | visited_pages = self.visitedPages() | 140 | visited_pages = self.visitedPages() |
2732 | 171 | for index in reversed(visited_pages): | 141 | for index in reversed(visited_pages): |
2734 | 172 | if index == current_user_id: | 142 | if index == page_id: |
2735 | 173 | break | 143 | break |
2736 | 174 | self.back() | 144 | self.back() |
2737 | 175 | 145 | ||
2738 | @@ -179,12 +149,9 @@ | |||
2739 | 179 | self.next() | 149 | self.next() |
2740 | 180 | self._next_id = -1 | 150 | self._next_id = -1 |
2741 | 181 | 151 | ||
2743 | 182 | def _move_to_email_verification_page(self, email, password): | 152 | def _move_to_email_verification_page(self): |
2744 | 183 | """Move to the email verification page wizard.""" | 153 | """Move to the email verification page wizard.""" |
2745 | 184 | self._next_id = self.email_verification_page_id | 154 | self._next_id = self.email_verification_page_id |
2746 | 185 | self.email_verification.email = unicode(email) | ||
2747 | 186 | self.email_verification.password = unicode(password) | ||
2748 | 187 | self.email_verification.set_titles(email) | ||
2749 | 188 | self.next() | 155 | self.next() |
2750 | 189 | self._next_id = -1 | 156 | self._next_id = -1 |
2751 | 190 | 157 | ||
2752 | @@ -200,7 +167,7 @@ | |||
2753 | 200 | self.next() | 167 | self.next() |
2754 | 201 | self._next_id = -1 | 168 | self._next_id = -1 |
2755 | 202 | 169 | ||
2757 | 203 | def _move_to_success_page(self, app_name='', email=''): | 170 | def _move_to_success_page(self): |
2758 | 204 | """Move to the success page wizard.""" | 171 | """Move to the success page wizard.""" |
2759 | 205 | self._next_id = self.success_page_id | 172 | self._next_id = self.success_page_id |
2760 | 206 | self.next() | 173 | self.next() |
2761 | @@ -209,7 +176,7 @@ | |||
2762 | 209 | QWizard.FinishButton]) | 176 | QWizard.FinishButton]) |
2763 | 210 | self.button(QWizard.FinishButton).setEnabled(True) | 177 | self.button(QWizard.FinishButton).setEnabled(True) |
2764 | 211 | self.button(QWizard.FinishButton).setFocus() | 178 | self.button(QWizard.FinishButton).setFocus() |
2766 | 212 | self._done = USER_SUCCESS | 179 | self.exit_code = USER_SUCCESS |
2767 | 213 | self._next_id = -1 | 180 | self._next_id = -1 |
2768 | 214 | 181 | ||
2769 | 215 | def _move_to_forgotten_page(self): | 182 | def _move_to_forgotten_page(self): |
2770 | @@ -219,11 +186,6 @@ | |||
2771 | 219 | self._next_id = -1 | 186 | self._next_id = -1 |
2772 | 220 | 187 | ||
2773 | 221 | @property | 188 | @property |
2774 | 222 | def sign_in_page_id(self): | ||
2775 | 223 | """Return the id of the page used for choosing sign in type.""" | ||
2776 | 224 | return self._pages[self.sign_in_page] | ||
2777 | 225 | |||
2778 | 226 | @property | ||
2779 | 227 | def setup_account_page_id(self): | 189 | def setup_account_page_id(self): |
2780 | 228 | """Return the id of the page used for sign in.""" | 190 | """Return the id of the page used for sign in.""" |
2781 | 229 | return self._pages[self.setup_account] | 191 | return self._pages[self.setup_account] |
2782 | @@ -258,76 +220,18 @@ | |||
2783 | 258 | """Return the id of the error page.""" | 220 | """Return the id of the error page.""" |
2784 | 259 | return self._pages[self.error] | 221 | return self._pages[self.error] |
2785 | 260 | 222 | ||
2846 | 261 | def on_user_cancelation(self): | 223 | # pylint: disable=C0103 |
2847 | 262 | """Process the cancel action.""" | 224 | |
2788 | 263 | logger.debug('UbuntuSSOWizard.on_user_cancelation') | ||
2789 | 264 | self.user_cancellation_callback(self.app_name) | ||
2790 | 265 | self.close() | ||
2791 | 266 | |||
2792 | 267 | @defer.inlineCallbacks | ||
2793 | 268 | def on_login_success(self, app_name, email): | ||
2794 | 269 | """Process the success of a login.""" | ||
2795 | 270 | logger.debug('UbuntuSSOWizard.on_login_success') | ||
2796 | 271 | result = yield self.login_success_callback( | ||
2797 | 272 | unicode(app_name), unicode(email)) | ||
2798 | 273 | logger.debug('Result from callback is %s', result) | ||
2799 | 274 | if result == 0: | ||
2800 | 275 | logger.info('Success in calling the given success_callback') | ||
2801 | 276 | self.show_success_message() | ||
2802 | 277 | else: | ||
2803 | 278 | logger.info('Error in calling the given success_callback') | ||
2804 | 279 | self.show_error_message() | ||
2805 | 280 | |||
2806 | 281 | @defer.inlineCallbacks | ||
2807 | 282 | def on_registration_success(self, app_name, email): | ||
2808 | 283 | """Process the success of a registration.""" | ||
2809 | 284 | logger.debug('UbuntuSSOWizard.on_registration_success') | ||
2810 | 285 | result = yield self.registration_success_callback(unicode(app_name), | ||
2811 | 286 | unicode(email)) | ||
2812 | 287 | logger.debug('Result from callback is %s', result) | ||
2813 | 288 | if result == 0: | ||
2814 | 289 | logger.info('Success in calling the given registration_callback') | ||
2815 | 290 | self.show_success_message() | ||
2816 | 291 | else: | ||
2817 | 292 | logger.info('Success in calling the given registration_callback') | ||
2818 | 293 | self.show_error_message() | ||
2819 | 294 | |||
2820 | 295 | def show_success_message(self): | ||
2821 | 296 | """Show the success message in the view.""" | ||
2822 | 297 | logger.info('Showing success message.') | ||
2823 | 298 | # get the id of the success page, set it as the next id of the | ||
2824 | 299 | # current page and let the wizard move to the next step | ||
2825 | 300 | self.currentPage().next = self.success_page_id | ||
2826 | 301 | self.next() | ||
2827 | 302 | # show the finish button but with a close message | ||
2828 | 303 | buttons_layout = [] | ||
2829 | 304 | buttons_layout.append(QWizard.Stretch) | ||
2830 | 305 | buttons_layout.append(QWizard.FinishButton) | ||
2831 | 306 | self.setButtonLayout(buttons_layout) | ||
2832 | 307 | |||
2833 | 308 | def show_error_message(self): | ||
2834 | 309 | """Show the error page in the view.""" | ||
2835 | 310 | logger.info('Showing error message.') | ||
2836 | 311 | # similar to the success page but using the error id | ||
2837 | 312 | self.currentPage().next = self.error_page_id | ||
2838 | 313 | self.next() | ||
2839 | 314 | # show the finish button but with a close message | ||
2840 | 315 | buttons_layout = [] | ||
2841 | 316 | buttons_layout.append(QWizard.Stretch) | ||
2842 | 317 | buttons_layout.append(QWizard.FinishButton) | ||
2843 | 318 | self.setButtonLayout(buttons_layout) | ||
2844 | 319 | |||
2845 | 320 | # pylint: disable=C0103, W0212 | ||
2848 | 321 | def closeEvent(self, event): | 225 | def closeEvent(self, event): |
2849 | 322 | """Catch close event and send the proper return code.""" | 226 | """Catch close event and send the proper return code.""" |
2850 | 323 | if self.parent() is not None: | 227 | if self.parent() is not None: |
2851 | 324 | self.parent().close() | 228 | self.parent().close() |
2852 | 325 | else: | 229 | else: |
2858 | 326 | sys.exit(self._done) | 230 | sys.exit(self.exit_code) |
2859 | 327 | # pylint: enable=C0103, W0212 | 231 | |
2860 | 328 | 232 | # pylint: enable=C0103 | |
2861 | 329 | 233 | ||
2862 | 330 | # pylint: disable=W0201 | 234 | |
2863 | 331 | class UbuntuSSOClientGUI(QFrame): | 235 | class UbuntuSSOClientGUI(QFrame): |
2864 | 332 | """Ubuntu single sign-on GUI.""" | 236 | """Ubuntu single sign-on GUI.""" |
2865 | 333 | 237 | ||
2866 | @@ -345,41 +249,10 @@ | |||
2867 | 345 | self.wizard = UbuntuSSOWizard(app_name=app_name, **kwargs) | 249 | self.wizard = UbuntuSSOWizard(app_name=app_name, **kwargs) |
2868 | 346 | vbox.addWidget(self.wizard) | 250 | vbox.addWidget(self.wizard) |
2869 | 347 | 251 | ||
2904 | 348 | def get_login_success_callback(self): | 252 | # pylint: disable=C0103 |
2905 | 349 | """Return the log in success cb.""" | 253 | |
2872 | 350 | return self.view.login_success_callback | ||
2873 | 351 | |||
2874 | 352 | def set_login_success_callback(self, cb): | ||
2875 | 353 | """Set log in success cb.""" | ||
2876 | 354 | self.view.login_success_callback = cb | ||
2877 | 355 | |||
2878 | 356 | login_success_callback = property(get_login_success_callback, | ||
2879 | 357 | set_login_success_callback) | ||
2880 | 358 | |||
2881 | 359 | def get_registration_success_callback(self): | ||
2882 | 360 | """Return the registration success cb.""" | ||
2883 | 361 | return self.view.registration_success_callback | ||
2884 | 362 | |||
2885 | 363 | def set_registration_success_callback(self, cb): | ||
2886 | 364 | """Set registration success cb.""" | ||
2887 | 365 | self.view.registration_success_callback = cb | ||
2888 | 366 | |||
2889 | 367 | registration_success_callback = property(get_registration_success_callback, | ||
2890 | 368 | set_registration_success_callback) | ||
2891 | 369 | |||
2892 | 370 | def get_user_cancellation_callback(self): | ||
2893 | 371 | """Return the user cancellation callback.""" | ||
2894 | 372 | return self.view.user_cancellation_callback | ||
2895 | 373 | |||
2896 | 374 | def set_user_cancellation_callback(self, cb): | ||
2897 | 375 | """Set the user cancellation callback.""" | ||
2898 | 376 | self.view.user_cancellation_callback = cb | ||
2899 | 377 | |||
2900 | 378 | user_cancellation_callback = property(get_user_cancellation_callback, | ||
2901 | 379 | set_user_cancellation_callback) | ||
2902 | 380 | |||
2903 | 381 | # pylint: disable=C0103, W0212 | ||
2906 | 382 | def closeEvent(self, event): | 254 | def closeEvent(self, event): |
2907 | 383 | """Catch close event and send the proper return code.""" | 255 | """Catch close event and send the proper return code.""" |
2910 | 384 | sys.exit(self.wizard._done) | 256 | sys.exit(self.wizard.exit_code) |
2911 | 385 | # pylint: enable=C0103, W0212 | 257 | |
2912 | 258 | # pylint: enable=C0103 |
+1