Merge lp:~nataliabidart/ubuntu-sso-client/reusable-headers into lp:ubuntu-sso-client
- reusable-headers
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Natalia Bidart | ||||
Approved revision: | 921 | ||||
Merged at revision: | 910 | ||||
Proposed branch: | lp:~nataliabidart/ubuntu-sso-client/reusable-headers | ||||
Merge into: | lp:ubuntu-sso-client | ||||
Diff against target: |
1257 lines (+391/-267) 19 files modified
data/qt/stylesheet.qss (+1/-7) run-tests (+1/-1) ubuntu_sso/qt/__init__.py (+26/-2) ubuntu_sso/qt/current_user_sign_in_page.py (+4/-6) ubuntu_sso/qt/email_verification_page.py (+1/-1) ubuntu_sso/qt/forgotten_password_page.py (+1/-1) ubuntu_sso/qt/reset_password_page.py (+1/-1) ubuntu_sso/qt/setup_account_page.py (+5/-5) ubuntu_sso/qt/sso_wizard_page.py (+101/-75) ubuntu_sso/qt/tests/__init__.py (+54/-6) ubuntu_sso/qt/tests/test_common.py (+49/-2) ubuntu_sso/qt/tests/test_current_user_sign_in_page.py (+4/-4) ubuntu_sso/qt/tests/test_email_verification.py (+6/-7) ubuntu_sso/qt/tests/test_forgotten_password.py (+3/-2) ubuntu_sso/qt/tests/test_loadingoverlay.py (+0/-3) ubuntu_sso/qt/tests/test_reset_password.py (+4/-14) ubuntu_sso/qt/tests/test_setup_account.py (+36/-65) ubuntu_sso/qt/tests/test_sso_wizard_page.py (+88/-59) ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py (+6/-6) |
||||
To merge this branch: | bzr merge lp:~nataliabidart/ubuntu-sso-client/reusable-headers | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Diego Sarmentero (community) | Approve | ||
Roberto Alsina (community) | Approve | ||
Review via email: mp+97129@code.launchpad.net |
Commit message
- The tooltip should not be shown for titles and subtitles when no cut off was
needed (LP: #949741).
- Making the WizardHeader a reusable class.
- Added some minor logging to build_general_
- Improved code for the 'sign in' button validation.
Description of the change
To post a comment you must log in.
- 914. By Natalia Bidart
-
Fixed tests.
- 915. By Natalia Bidart
-
Fixed lint issues.
- 916. By Natalia Bidart
-
Pep8 fixes.
- 917. By Natalia Bidart
-
Merged trunk in.
- 918. By Natalia Bidart
-
- Added some minor logging to build_general_
error_msg. - 919. By Natalia Bidart
-
- Do not hide the error when a new captcha is requested, since that will
immediatly hide a potential error shown from a just-failed registration
attempt. - 920. By Natalia Bidart
-
Revert error hiding and fiule bug for it.
- 921. By Natalia Bidart
-
- Improved code for 'sign in' button validation.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'data/qt/stylesheet.qss' | |||
2 | --- data/qt/stylesheet.qss 2012-03-05 20:30:57 +0000 | |||
3 | +++ data/qt/stylesheet.qss 2012-03-14 13:30:25 +0000 | |||
4 | @@ -95,17 +95,11 @@ | |||
5 | 95 | font-size: 20px; | 95 | font-size: 20px; |
6 | 96 | } | 96 | } |
7 | 97 | 97 | ||
13 | 98 | QLabel#title_label { | 98 | WizardHeader { |
9 | 99 | font-size: 20px; | ||
10 | 100 | } | ||
11 | 101 | |||
12 | 102 | QFrame#header { | ||
14 | 103 | padding-top: 1px; | 99 | padding-top: 1px; |
15 | 104 | padding-bottom: 1px; | 100 | padding-bottom: 1px; |
16 | 105 | } | 101 | } |
17 | 106 | 102 | ||
18 | 107 | QLabel#form_errors { | 103 | QLabel#form_errors { |
19 | 108 | font: bold 14px; | ||
20 | 109 | color: #df2d1f; | ||
21 | 110 | padding-bottom: 1px; | 104 | padding-bottom: 1px; |
22 | 111 | } | 105 | } |
23 | 112 | 106 | ||
24 | === modified file 'run-tests' | |||
25 | --- run-tests 2012-02-17 16:57:34 +0000 | |||
26 | +++ run-tests 2012-03-14 13:30:25 +0000 | |||
27 | @@ -57,7 +57,7 @@ | |||
28 | 57 | 57 | ||
29 | 58 | echo "*** Running QT test suite for ""$MODULE"" ***" | 58 | echo "*** Running QT test suite for ""$MODULE"" ***" |
30 | 59 | ./setup.py build | 59 | ./setup.py build |
32 | 60 | USE_QT_MAINLOOP=True $XVFB_CMDLINE u1trial --reactor=qt4 --gui -p "$GTK_TESTS_PATH" -i "test_windows.py" "$MODULE" | 60 | $XVFB_CMDLINE u1trial --reactor=qt4 --gui -p "$GTK_TESTS_PATH" -i "test_windows.py" "$MODULE" |
33 | 61 | rm -rf _trial_temp | 61 | rm -rf _trial_temp |
34 | 62 | rm -rf build | 62 | rm -rf build |
35 | 63 | 63 | ||
36 | 64 | 64 | ||
37 | === modified file 'ubuntu_sso/qt/__init__.py' | |||
38 | --- ubuntu_sso/qt/__init__.py 2012-03-12 14:03:08 +0000 | |||
39 | +++ ubuntu_sso/qt/__init__.py 2012-03-14 13:30:25 +0000 | |||
40 | @@ -18,20 +18,26 @@ | |||
41 | 18 | 18 | ||
42 | 19 | import collections | 19 | import collections |
43 | 20 | 20 | ||
44 | 21 | from PyQt4 import QtGui, QtCore | ||
45 | 22 | |||
46 | 23 | from ubuntu_sso.logger import setup_gui_logging | ||
47 | 24 | |||
48 | 25 | logger = setup_gui_logging('ubuntu_sso.qt') | ||
49 | 21 | 26 | ||
50 | 22 | LINK_STYLE = (u'<a href="{link_url}">' | 27 | LINK_STYLE = (u'<a href="{link_url}">' |
51 | 23 | '<span style="color:#df2d1f;">{link_text}</span></a>') | 28 | '<span style="color:#df2d1f;">{link_text}</span></a>') |
52 | 24 | ERROR_ALL = '__all__' | 29 | ERROR_ALL = '__all__' |
54 | 25 | ERROR_STYLE = u'<font color="#df2d1f"><b>%s</b></font>' | 30 | ERROR_STYLE = u'<font color="#df2d1f" style="font-size:small"><b>%s</b></font>' |
55 | 26 | ERROR_MESSAGE = 'message' | 31 | ERROR_MESSAGE = 'message' |
56 | 27 | PREFERED_UI_SIZE = {'width': 550, 'height': 525} | 32 | PREFERED_UI_SIZE = {'width': 550, 'height': 525} |
58 | 28 | TITLE_STYLE = u'<span style="font-size:24px">%s</span>' | 33 | TITLE_STYLE = u'<span style="font-size:xx-large">%s</span>' |
59 | 29 | WINDOW_TITLE = 'Ubuntu Single Sign On' | 34 | WINDOW_TITLE = 'Ubuntu Single Sign On' |
60 | 30 | 35 | ||
61 | 31 | 36 | ||
62 | 32 | # Based on the gtk implementation | 37 | # Based on the gtk implementation |
63 | 33 | def build_general_error_message(errordict): | 38 | def build_general_error_message(errordict): |
64 | 34 | """Build a user-friendly error message from the errordict.""" | 39 | """Build a user-friendly error message from the errordict.""" |
65 | 40 | logger.debug('build_general_error_message: errordict is: %r.', errordict) | ||
66 | 35 | result = '' | 41 | result = '' |
67 | 36 | if isinstance(errordict, collections.Mapping): | 42 | if isinstance(errordict, collections.Mapping): |
68 | 37 | msg1 = errordict.get(ERROR_ALL) | 43 | msg1 = errordict.get(ERROR_ALL) |
69 | @@ -52,4 +58,22 @@ | |||
70 | 52 | [('%s: %s' % (k, v)) for k, v in errordict.iteritems()]) | 58 | [('%s: %s' % (k, v)) for k, v in errordict.iteritems()]) |
71 | 53 | else: | 59 | else: |
72 | 54 | result = repr(errordict) | 60 | result = repr(errordict) |
73 | 61 | |||
74 | 62 | logger.info('build_general_error_message: returning %r.', result) | ||
75 | 55 | return result | 63 | return result |
76 | 64 | |||
77 | 65 | |||
78 | 66 | def maybe_elide_text(label, text, width, markup=None): | ||
79 | 67 | """Set 'text' to be the 'label's text. | ||
80 | 68 | |||
81 | 69 | If 'text' is longer than 'width', set the label's tooltip to be the full | ||
82 | 70 | text, and the text itself to be the elided version of 'text'. | ||
83 | 71 | |||
84 | 72 | """ | ||
85 | 73 | fm = QtGui.QFontMetrics(label.font()) | ||
86 | 74 | elided_text = fm.elidedText(text, QtCore.Qt.ElideRight, width) | ||
87 | 75 | if elided_text != text: | ||
88 | 76 | label.setToolTip(text) | ||
89 | 77 | if markup is not None: | ||
90 | 78 | elided_text = markup % elided_text | ||
91 | 79 | label.setText(elided_text) | ||
92 | 56 | 80 | ||
93 | === modified file 'ubuntu_sso/qt/current_user_sign_in_page.py' | |||
94 | --- ubuntu_sso/qt/current_user_sign_in_page.py 2012-03-12 14:53:00 +0000 | |||
95 | +++ ubuntu_sso/qt/current_user_sign_in_page.py 2012-03-14 13:30:25 +0000 | |||
96 | @@ -119,12 +119,10 @@ | |||
97 | 119 | 119 | ||
98 | 120 | def _validate(self): | 120 | def _validate(self): |
99 | 121 | """Perform input validation.""" | 121 | """Perform input validation.""" |
100 | 122 | valid = True | ||
101 | 123 | correct_mail = is_correct_email(unicode(self.ui.email_edit.text())) | 122 | correct_mail = is_correct_email(unicode(self.ui.email_edit.text())) |
106 | 124 | password = unicode(self.ui.password_edit.text()) | 123 | correct_password = len(unicode(self.ui.password_edit.text())) > 0 |
107 | 125 | if not correct_mail or not password: | 124 | enabled = correct_mail and correct_password |
108 | 126 | valid = False | 125 | self.ui.sign_in_button.setEnabled(enabled) |
105 | 127 | self.ui.sign_in_button.setEnabled(valid) | ||
109 | 128 | 126 | ||
110 | 129 | def login(self): | 127 | def login(self): |
111 | 130 | """Perform the login using the self.backend.""" | 128 | """Perform the login using the self.backend.""" |
112 | @@ -149,7 +147,7 @@ | |||
113 | 149 | # let the user know | 147 | # let the user know |
114 | 150 | logger.error('Got error when login %s, error: %s', | 148 | logger.error('Got error when login %s, error: %s', |
115 | 151 | self.app_name, error) | 149 | self.app_name, error) |
117 | 152 | self.show_error(self.app_name, build_general_error_message(error)) | 150 | self.show_error(build_general_error_message(error)) |
118 | 153 | 151 | ||
119 | 154 | def on_logged_in(self, app_name, result): | 152 | def on_logged_in(self, app_name, result): |
120 | 155 | """We managed to log in.""" | 153 | """We managed to log in.""" |
121 | 156 | 154 | ||
122 | === modified file 'ubuntu_sso/qt/email_verification_page.py' | |||
123 | --- ubuntu_sso/qt/email_verification_page.py 2012-03-09 17:27:30 +0000 | |||
124 | +++ ubuntu_sso/qt/email_verification_page.py 2012-03-14 13:30:25 +0000 | |||
125 | @@ -134,7 +134,7 @@ | |||
126 | 134 | self.hide_overlay() | 134 | self.hide_overlay() |
127 | 135 | msg = error.pop(ERROR_EMAIL_TOKEN, '') | 135 | msg = error.pop(ERROR_EMAIL_TOKEN, '') |
128 | 136 | msg += build_general_error_message(error) | 136 | msg += build_general_error_message(error) |
130 | 137 | self.show_error(self.app_name, msg) | 137 | self.show_error(msg) |
131 | 138 | 138 | ||
132 | 139 | # pylint: disable=C0103 | 139 | # pylint: disable=C0103 |
133 | 140 | 140 | ||
134 | 141 | 141 | ||
135 | === modified file 'ubuntu_sso/qt/forgotten_password_page.py' | |||
136 | --- ubuntu_sso/qt/forgotten_password_page.py 2012-03-09 17:27:30 +0000 | |||
137 | +++ ubuntu_sso/qt/forgotten_password_page.py 2012-03-14 13:30:25 +0000 | |||
138 | @@ -127,4 +127,4 @@ | |||
139 | 127 | # set the error message | 127 | # set the error message |
140 | 128 | self.hide_overlay() | 128 | self.hide_overlay() |
141 | 129 | msg = REQUEST_PASSWORD_TOKEN_WRONG_EMAIL | 129 | msg = REQUEST_PASSWORD_TOKEN_WRONG_EMAIL |
143 | 130 | self.show_error(self.app_name, msg) | 130 | self.show_error(msg) |
144 | 131 | 131 | ||
145 | === modified file 'ubuntu_sso/qt/reset_password_page.py' | |||
146 | --- ubuntu_sso/qt/reset_password_page.py 2012-03-09 17:27:30 +0000 | |||
147 | +++ ubuntu_sso/qt/reset_password_page.py 2012-03-14 13:30:25 +0000 | |||
148 | @@ -169,7 +169,7 @@ | |||
149 | 169 | """Let the user know that there was an error.""" | 169 | """Let the user know that there was an error.""" |
150 | 170 | logger.error('Got error changing password for %s, error: %s', | 170 | logger.error('Got error changing password for %s, error: %s', |
151 | 171 | self.app_name, error) | 171 | self.app_name, error) |
153 | 172 | self.show_error(self.app_name, build_general_error_message(error)) | 172 | self.show_error(build_general_error_message(error)) |
154 | 173 | 173 | ||
155 | 174 | def set_new_password(self): | 174 | def set_new_password(self): |
156 | 175 | """Request a new password to be set.""" | 175 | """Request a new password to be set.""" |
157 | 176 | 176 | ||
158 | === modified file 'ubuntu_sso/qt/setup_account_page.py' | |||
159 | --- ubuntu_sso/qt/setup_account_page.py 2012-03-13 20:33:06 +0000 | |||
160 | +++ ubuntu_sso/qt/setup_account_page.py 2012-03-14 13:30:25 +0000 | |||
161 | @@ -322,10 +322,10 @@ | |||
162 | 322 | self.captcha_image = pixmap_image | 322 | self.captcha_image = pixmap_image |
163 | 323 | self.on_captcha_refresh_complete() | 323 | self.on_captcha_refresh_complete() |
164 | 324 | 324 | ||
166 | 325 | def on_captcha_generation_error(self, error, *args, **kwargs): | 325 | @log_call(logger.error) |
167 | 326 | def on_captcha_generation_error(self, app_name, error): | ||
168 | 326 | """An error ocurred.""" | 327 | """An error ocurred.""" |
171 | 327 | logger.error('Got error on captcha generation: %s', error) | 328 | self.show_error(CAPTCHA_LOAD_ERROR) |
170 | 328 | self.show_error(self.app_name, CAPTCHA_LOAD_ERROR) | ||
172 | 329 | self.on_captcha_refresh_complete() | 329 | self.on_captcha_refresh_complete() |
173 | 330 | 330 | ||
174 | 331 | @log_call(logger.error) | 331 | @log_call(logger.error) |
175 | @@ -337,7 +337,7 @@ | |||
176 | 337 | self.set_error_message(self.ui.email_assistance, msg) | 337 | self.set_error_message(self.ui.email_assistance, msg) |
177 | 338 | error_msg = build_general_error_message(error) | 338 | error_msg = build_general_error_message(error) |
178 | 339 | if error_msg: | 339 | if error_msg: |
180 | 340 | self.show_error(self.app_name, error_msg) | 340 | self.show_error(error_msg) |
181 | 341 | self._refresh_captcha() | 341 | self._refresh_captcha() |
182 | 342 | 342 | ||
183 | 343 | @log_call(logger.info) | 343 | @log_call(logger.info) |
184 | @@ -378,7 +378,7 @@ | |||
185 | 378 | messages.append(CAPTCHA_REQUIRED_ERROR) | 378 | messages.append(CAPTCHA_REQUIRED_ERROR) |
186 | 379 | if len(messages) > 0: | 379 | if len(messages) > 0: |
187 | 380 | condition = False | 380 | condition = False |
189 | 381 | self.show_error(self.app_name, '\n'.join(messages)) | 381 | self.show_error('\n'.join(messages)) |
190 | 382 | return condition | 382 | return condition |
191 | 383 | 383 | ||
192 | 384 | def set_next_validation(self): | 384 | def set_next_validation(self): |
193 | 385 | 385 | ||
194 | === modified file 'ubuntu_sso/qt/sso_wizard_page.py' | |||
195 | --- ubuntu_sso/qt/sso_wizard_page.py 2012-03-12 14:53:00 +0000 | |||
196 | +++ ubuntu_sso/qt/sso_wizard_page.py 2012-03-14 13:30:25 +0000 | |||
197 | @@ -23,31 +23,38 @@ | |||
198 | 23 | QApplication, | 23 | QApplication, |
199 | 24 | QCursor, | 24 | QCursor, |
200 | 25 | QFrame, | 25 | QFrame, |
201 | 26 | QFontMetrics, | ||
202 | 27 | QHBoxLayout, | 26 | QHBoxLayout, |
203 | 27 | QLabel, | ||
204 | 28 | QStyle, | ||
205 | 28 | QVBoxLayout, | 29 | QVBoxLayout, |
206 | 29 | QStyle, | ||
207 | 30 | QWizardPage, | 30 | QWizardPage, |
208 | 31 | QLabel, | ||
209 | 32 | ) | 31 | ) |
210 | 33 | from twisted.internet import defer | 32 | from twisted.internet import defer |
211 | 34 | 33 | ||
212 | 35 | from ubuntu_sso import main | 34 | from ubuntu_sso import main |
213 | 36 | from ubuntu_sso.logger import setup_gui_logging, log_call | 35 | from ubuntu_sso.logger import setup_gui_logging, log_call |
215 | 37 | from ubuntu_sso.qt import PREFERED_UI_SIZE, TITLE_STYLE | 36 | from ubuntu_sso.qt import ( |
216 | 37 | ERROR_STYLE, | ||
217 | 38 | maybe_elide_text, | ||
218 | 39 | PREFERED_UI_SIZE, | ||
219 | 40 | TITLE_STYLE, | ||
220 | 41 | ) | ||
221 | 38 | from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR | 42 | from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR |
222 | 39 | 43 | ||
223 | 40 | 44 | ||
224 | 41 | logger = setup_gui_logging('ubuntu_sso.sso_wizard_page') | 45 | logger = setup_gui_logging('ubuntu_sso.sso_wizard_page') |
225 | 42 | 46 | ||
226 | 43 | 47 | ||
229 | 44 | class Header(QFrame): | 48 | class WizardHeader(QFrame): |
230 | 45 | """Header Class for Title and Subtitle in all wizard pages.""" | 49 | """WizardHeader Class for Title and Subtitle in all wizard pages.""" |
231 | 46 | 50 | ||
233 | 47 | def __init__(self): | 51 | def __init__(self, max_width, parent=None): |
234 | 48 | """Create a new instance.""" | 52 | """Create a new instance.""" |
237 | 49 | super(Header, self).__init__() | 53 | super(WizardHeader, self).__init__(parent=parent) |
238 | 50 | self.setObjectName('header') | 54 | self.max_width = max_width |
239 | 55 | self.max_title_width = self.max_width * 0.95 | ||
240 | 56 | self.max_subtitle_width = self.max_width * 1.8 | ||
241 | 57 | |||
242 | 51 | vbox = QVBoxLayout(self) | 58 | vbox = QVBoxLayout(self) |
243 | 52 | vbox.setContentsMargins(0, 0, 0, 0) | 59 | vbox.setContentsMargins(0, 0, 0, 0) |
244 | 53 | self.title_label = QLabel() | 60 | self.title_label = QLabel() |
245 | @@ -64,11 +71,8 @@ | |||
246 | 64 | def set_title(self, title): | 71 | def set_title(self, title): |
247 | 65 | """Set the Title of the page or hide it otherwise""" | 72 | """Set the Title of the page or hide it otherwise""" |
248 | 66 | if title: | 73 | if title: |
254 | 67 | fm = QFontMetrics(self.subtitle_label.font()) | 74 | maybe_elide_text(self.title_label, title, self.max_title_width, |
255 | 68 | width = PREFERED_UI_SIZE['width'] * 0.95 | 75 | markup=TITLE_STYLE) |
251 | 69 | elided_text = fm.elidedText(title, Qt.ElideRight, width) | ||
252 | 70 | self.title_label.setToolTip(title) | ||
253 | 71 | self.title_label.setText(elided_text) | ||
256 | 72 | self.title_label.setVisible(True) | 76 | self.title_label.setVisible(True) |
257 | 73 | else: | 77 | else: |
258 | 74 | self.title_label.setVisible(False) | 78 | self.title_label.setVisible(False) |
259 | @@ -76,28 +80,23 @@ | |||
260 | 76 | def set_subtitle(self, subtitle): | 80 | def set_subtitle(self, subtitle): |
261 | 77 | """Set the Subtitle of the page or hide it otherwise""" | 81 | """Set the Subtitle of the page or hide it otherwise""" |
262 | 78 | if subtitle: | 82 | if subtitle: |
268 | 79 | fm = QFontMetrics(self.subtitle_label.font()) | 83 | maybe_elide_text(self.subtitle_label, subtitle, |
269 | 80 | width = PREFERED_UI_SIZE['width'] * 1.8 | 84 | self.max_subtitle_width) |
265 | 81 | elided_text = fm.elidedText(subtitle, Qt.ElideRight, width) | ||
266 | 82 | self.subtitle_label.setText(elided_text) | ||
267 | 83 | self.subtitle_label.setToolTip(subtitle) | ||
270 | 84 | self.subtitle_label.setVisible(True) | 85 | self.subtitle_label.setVisible(True) |
271 | 85 | else: | 86 | else: |
272 | 86 | self.subtitle_label.setVisible(False) | 87 | self.subtitle_label.setVisible(False) |
273 | 87 | 88 | ||
274 | 88 | 89 | ||
277 | 89 | class SSOWizardPage(QWizardPage): | 90 | class BaseWizardPage(QWizardPage): |
278 | 90 | """Root class for all wizard pages.""" | 91 | """Base class for all wizard pages.""" |
279 | 91 | 92 | ||
280 | 92 | ui_class = None | 93 | ui_class = None |
282 | 93 | _signals = {} # override in children | 94 | max_width = 0 |
283 | 94 | processingStarted = pyqtSignal() | 95 | processingStarted = pyqtSignal() |
284 | 95 | processingFinished = pyqtSignal() | 96 | processingFinished = pyqtSignal() |
285 | 96 | 97 | ||
290 | 97 | def __init__(self, app_name, **kwargs): | 98 | def __init__(self, parent=None): |
291 | 98 | """Create a new instance.""" | 99 | super(BaseWizardPage, self).__init__(parent=parent) |
288 | 99 | parent = kwargs.pop('parent', None) | ||
289 | 100 | super(SSOWizardPage, self).__init__(parent=parent) | ||
292 | 101 | 100 | ||
293 | 102 | self.ui = None | 101 | self.ui = None |
294 | 103 | if self.ui_class is not None: | 102 | if self.ui_class is not None: |
295 | @@ -105,55 +104,108 @@ | |||
296 | 105 | self.ui = self.ui_class() | 104 | self.ui = self.ui_class() |
297 | 106 | self.ui.setupUi(self) | 105 | self.ui.setupUi(self) |
298 | 107 | 106 | ||
305 | 108 | # store common useful data provided by the app | 107 | if self.layout() is None: |
306 | 109 | self.app_name = app_name | 108 | self.setLayout(QVBoxLayout(self)) |
301 | 110 | self.ping_url = kwargs.get('ping_url', '') | ||
302 | 111 | self.tc_url = kwargs.get('tc_url', '') | ||
303 | 112 | self.policy_url = kwargs.get('policy_url', '') | ||
304 | 113 | self.help_text = kwargs.get('help_text', '') | ||
307 | 114 | 109 | ||
308 | 115 | # Set the error area | 110 | # Set the error area |
310 | 116 | self.form_errors_label = QLabel(' ') | 111 | self.form_errors_label = QLabel() |
311 | 117 | self.form_errors_label.setObjectName('form_errors') | 112 | self.form_errors_label.setObjectName('form_errors') |
312 | 118 | self.form_errors_label.setAlignment(Qt.AlignBottom) | 113 | self.form_errors_label.setAlignment(Qt.AlignBottom) |
313 | 119 | self.layout().insertWidget(0, self.form_errors_label) | 114 | self.layout().insertWidget(0, self.form_errors_label) |
314 | 115 | |||
315 | 120 | # Set the header | 116 | # Set the header |
317 | 121 | self.header = Header() | 117 | self.header = WizardHeader(max_width=self.max_width) |
318 | 122 | self.header.set_title(title='') | 118 | self.header.set_title(title='') |
319 | 123 | self.header.set_subtitle(subtitle='') | 119 | self.header.set_subtitle(subtitle='') |
320 | 124 | self.layout().insertWidget(0, self.header) | 120 | self.layout().insertWidget(0, self.header) |
321 | 125 | self._signals_receivers = {} | ||
322 | 126 | self.backend = None | ||
323 | 127 | 121 | ||
324 | 128 | self.layout().setAlignment(Qt.AlignLeft) | 122 | self.layout().setAlignment(Qt.AlignLeft) |
325 | 129 | 123 | ||
327 | 130 | self.setup_page() | 124 | self._is_processing = False |
328 | 125 | |||
329 | 126 | def _get_is_processing(self): | ||
330 | 127 | """Is this widget processing any request?""" | ||
331 | 128 | return self._is_processing | ||
332 | 129 | |||
333 | 130 | def _set_is_processing(self, new_value): | ||
334 | 131 | """Set this widget to be processing a request.""" | ||
335 | 132 | self._is_processing = new_value | ||
336 | 133 | self.setEnabled(not new_value) | ||
337 | 134 | if not self._is_processing: | ||
338 | 135 | self.processingFinished.emit() | ||
339 | 136 | else: | ||
340 | 137 | self.processingStarted.emit() | ||
341 | 138 | |||
342 | 139 | is_processing = property(fget=_get_is_processing, fset=_set_is_processing) | ||
343 | 140 | |||
344 | 141 | # pylint: disable=C0103 | ||
345 | 142 | |||
346 | 143 | def cleanupPage(self): | ||
347 | 144 | """Hide the errors.""" | ||
348 | 145 | self.hide_error() | ||
349 | 146 | |||
350 | 147 | def setTitle(self, title=''): | ||
351 | 148 | """Set the Wizard Page Title.""" | ||
352 | 149 | self.header.set_title(title) | ||
353 | 150 | |||
354 | 151 | def setSubTitle(self, subtitle=''): | ||
355 | 152 | """Set the Wizard Page Subtitle.""" | ||
356 | 153 | self.header.set_subtitle(subtitle) | ||
357 | 154 | |||
358 | 155 | def title(self): | ||
359 | 156 | """Return the header's title.""" | ||
360 | 157 | return self.header.title_label.text() | ||
361 | 158 | |||
362 | 159 | def subTitle(self): | ||
363 | 160 | """Return the header's subtitle.""" | ||
364 | 161 | return self.header.subtitle_label.text() | ||
365 | 162 | |||
366 | 163 | # pylint: enable=C0103 | ||
367 | 131 | 164 | ||
368 | 132 | @log_call(logger.error) | 165 | @log_call(logger.error) |
370 | 133 | def show_error(self, app_name, message): | 166 | def show_error(self, message): |
371 | 134 | """Show an error message inside the page.""" | 167 | """Show an error message inside the page.""" |
378 | 135 | self.hide_overlay() | 168 | self.is_processing = False |
379 | 136 | fm = QFontMetrics(self.form_errors_label.font()) | 169 | maybe_elide_text(self.form_errors_label, message, |
380 | 137 | width = PREFERED_UI_SIZE['width'] * 0.95 | 170 | self.max_width * 0.95, markup=ERROR_STYLE) |
375 | 138 | elided_text = fm.elidedText(message, Qt.ElideRight, width) | ||
376 | 139 | self.form_errors_label.setText(elided_text) | ||
377 | 140 | self.form_errors_label.setToolTip(message) | ||
381 | 141 | 171 | ||
382 | 142 | def hide_error(self): | 172 | def hide_error(self): |
383 | 143 | """Hide the label errors in the current page.""" | 173 | """Hide the label errors in the current page.""" |
385 | 144 | # We actually want the label with one chat, because if it is an | 174 | # We actually want the label with one empty char, because if it is an |
386 | 145 | # empty string, the height of the label is 0 | 175 | # empty string, the height of the label is 0 |
387 | 146 | self.form_errors_label.setText(' ') | 176 | self.form_errors_label.setText(' ') |
388 | 147 | 177 | ||
389 | 178 | |||
390 | 179 | class SSOWizardPage(BaseWizardPage): | ||
391 | 180 | """Root class for all SSO specific wizard pages.""" | ||
392 | 181 | |||
393 | 182 | _signals = {} # override in children | ||
394 | 183 | max_width = PREFERED_UI_SIZE['width'] | ||
395 | 184 | |||
396 | 185 | def __init__(self, app_name, **kwargs): | ||
397 | 186 | """Create a new instance.""" | ||
398 | 187 | parent = kwargs.pop('parent', None) | ||
399 | 188 | super(SSOWizardPage, self).__init__(parent=parent) | ||
400 | 189 | |||
401 | 190 | # store common useful data provided by the app | ||
402 | 191 | self.app_name = app_name | ||
403 | 192 | self.ping_url = kwargs.get('ping_url', '') | ||
404 | 193 | self.tc_url = kwargs.get('tc_url', '') | ||
405 | 194 | self.policy_url = kwargs.get('policy_url', '') | ||
406 | 195 | self.help_text = kwargs.get('help_text', '') | ||
407 | 196 | |||
408 | 197 | self._signals_receivers = {} | ||
409 | 198 | self.backend = None | ||
410 | 199 | |||
411 | 200 | self.setup_page() | ||
412 | 201 | |||
413 | 148 | def hide_overlay(self): | 202 | def hide_overlay(self): |
414 | 149 | """Emit the signal to notify the upper container that ends loading.""" | 203 | """Emit the signal to notify the upper container that ends loading.""" |
417 | 150 | self.setEnabled(True) | 204 | self.is_processing = False |
416 | 151 | self.processingFinished.emit() | ||
418 | 152 | 205 | ||
419 | 153 | def show_overlay(self): | 206 | def show_overlay(self): |
420 | 154 | """Emit the signal to notify the upper container that is loading.""" | 207 | """Emit the signal to notify the upper container that is loading.""" |
423 | 155 | self.setEnabled(False) | 208 | self.is_processing = True |
422 | 156 | self.processingStarted.emit() | ||
424 | 157 | 209 | ||
425 | 158 | @defer.inlineCallbacks | 210 | @defer.inlineCallbacks |
426 | 159 | def setup_page(self): | 211 | def setup_page(self): |
427 | @@ -165,30 +217,6 @@ | |||
428 | 165 | self._set_translated_strings() | 217 | self._set_translated_strings() |
429 | 166 | self._connect_ui() | 218 | self._connect_ui() |
430 | 167 | 219 | ||
431 | 168 | # pylint: disable=C0103 | ||
432 | 169 | |||
433 | 170 | def cleanupPage(self): | ||
434 | 171 | """Hide the errors.""" | ||
435 | 172 | self.hide_error() | ||
436 | 173 | |||
437 | 174 | def setTitle(self, title=''): | ||
438 | 175 | """Set the Wizard Page Title.""" | ||
439 | 176 | self.header.set_title(TITLE_STYLE % title) | ||
440 | 177 | |||
441 | 178 | def setSubTitle(self, subtitle=''): | ||
442 | 179 | """Set the Wizard Page Subtitle.""" | ||
443 | 180 | self.header.set_subtitle(subtitle) | ||
444 | 181 | |||
445 | 182 | def title(self): | ||
446 | 183 | """Return the header's title.""" | ||
447 | 184 | return self.header.title_label.text() | ||
448 | 185 | |||
449 | 186 | def subTitle(self): | ||
450 | 187 | """Return the header's subtitle.""" | ||
451 | 188 | return self.header.subtitle_label.text() | ||
452 | 189 | |||
453 | 190 | # pylint: enable=C0103 | ||
454 | 191 | |||
455 | 192 | def _filter_by_app_name(self, f): | 220 | def _filter_by_app_name(self, f): |
456 | 193 | """Excecute the decorated function only for 'self.app_name'.""" | 221 | """Excecute the decorated function only for 'self.app_name'.""" |
457 | 194 | 222 | ||
458 | @@ -219,11 +247,9 @@ | |||
459 | 219 | 247 | ||
460 | 220 | def _set_translated_strings(self): | 248 | def _set_translated_strings(self): |
461 | 221 | """Implement in each child.""" | 249 | """Implement in each child.""" |
462 | 222 | raise NotImplementedError() | ||
463 | 223 | 250 | ||
464 | 224 | def _connect_ui(self): | 251 | def _connect_ui(self): |
465 | 225 | """Implement in each child.""" | 252 | """Implement in each child.""" |
466 | 226 | raise NotImplementedError() | ||
467 | 227 | 253 | ||
468 | 228 | def _handle_error(self, remote_call, handler, error): | 254 | def _handle_error(self, remote_call, handler, error): |
469 | 229 | """Handle any error when calling the remote backend.""" | 255 | """Handle any error when calling the remote backend.""" |
470 | 230 | 256 | ||
471 | === modified file 'ubuntu_sso/qt/tests/__init__.py' | |||
472 | --- ubuntu_sso/qt/tests/__init__.py 2012-03-05 21:18:15 +0000 | |||
473 | +++ ubuntu_sso/qt/tests/__init__.py 2012-03-14 13:30:25 +0000 | |||
474 | @@ -21,7 +21,7 @@ | |||
475 | 21 | from twisted.trial.unittest import TestCase | 21 | from twisted.trial.unittest import TestCase |
476 | 22 | 22 | ||
477 | 23 | from ubuntu_sso import main, NO_OP | 23 | from ubuntu_sso import main, NO_OP |
479 | 24 | from ubuntu_sso.qt import TITLE_STYLE | 24 | from ubuntu_sso.qt import ERROR_STYLE, maybe_elide_text, TITLE_STYLE |
480 | 25 | from ubuntu_sso.tests import ( | 25 | from ubuntu_sso.tests import ( |
481 | 26 | APP_NAME, | 26 | APP_NAME, |
482 | 27 | HELP_TEXT, | 27 | HELP_TEXT, |
483 | @@ -38,6 +38,15 @@ | |||
484 | 38 | # pylint: disable=W0212 | 38 | # pylint: disable=W0212 |
485 | 39 | 39 | ||
486 | 40 | 40 | ||
487 | 41 | def build_string_for_pixels(label, width): | ||
488 | 42 | """Return a random string that will be as big as with in pixels.""" | ||
489 | 43 | char = 'a' | ||
490 | 44 | fm = QtGui.QFontMetrics(label.font()) | ||
491 | 45 | pixel_width = fm.width(char) | ||
492 | 46 | chars = int(width / pixel_width) | ||
493 | 47 | return char * chars | ||
494 | 48 | |||
495 | 49 | |||
496 | 41 | class FakedObject(object): | 50 | class FakedObject(object): |
497 | 42 | """Fake an object, record every call.""" | 51 | """Fake an object, record every call.""" |
498 | 43 | 52 | ||
499 | @@ -439,6 +448,9 @@ | |||
500 | 439 | self.wizard = self.ui_wizard_class() | 448 | self.wizard = self.ui_wizard_class() |
501 | 440 | self.patch(self.ui, 'wizard', lambda: self.wizard) | 449 | self.patch(self.ui, 'wizard', lambda: self.wizard) |
502 | 441 | 450 | ||
503 | 451 | self.ui.show() | ||
504 | 452 | self.addCleanup(self.ui.hide) | ||
505 | 453 | |||
506 | 442 | def _set_called(self, *args, **kwargs): | 454 | def _set_called(self, *args, **kwargs): |
507 | 443 | """Store 'args' and 'kwargs' for test assertions.""" | 455 | """Store 'args' and 'kwargs' for test assertions.""" |
508 | 444 | self._called = (args, kwargs) | 456 | self._called = (args, kwargs) |
509 | @@ -467,6 +479,38 @@ | |||
510 | 467 | 479 | ||
511 | 468 | self.assertEqual(self.signal_results, [signal_args]) | 480 | self.assertEqual(self.signal_results, [signal_args]) |
512 | 469 | 481 | ||
513 | 482 | def assert_title_correct(self, title_label, expected, max_width): | ||
514 | 483 | """Check that the label's text is equal to 'expected'.""" | ||
515 | 484 | label = QtGui.QLabel() | ||
516 | 485 | maybe_elide_text(label, expected, max_width) | ||
517 | 486 | |||
518 | 487 | self.assertEqual(TITLE_STYLE % unicode(label.text()), | ||
519 | 488 | unicode(title_label.text())) | ||
520 | 489 | self.assertEqual(unicode(label.toolTip()), | ||
521 | 490 | unicode(title_label.toolTip())) | ||
522 | 491 | self.assertTrue(title_label.isVisible()) | ||
523 | 492 | |||
524 | 493 | def assert_subtitle_correct(self, subtitle_label, expected, max_width): | ||
525 | 494 | """Check that the subtitle is equal to 'expected'.""" | ||
526 | 495 | label = QtGui.QLabel() | ||
527 | 496 | maybe_elide_text(label, expected, max_width) | ||
528 | 497 | |||
529 | 498 | self.assertEqual(unicode(label.text()), unicode(subtitle_label.text())) | ||
530 | 499 | self.assertEqual(unicode(label.toolTip()), | ||
531 | 500 | unicode(subtitle_label.toolTip())) | ||
532 | 501 | self.assertTrue(subtitle_label.isVisible()) | ||
533 | 502 | |||
534 | 503 | def assert_error_correct(self, error_label, expected, max_width): | ||
535 | 504 | """Check that the error 'error_label' displays 'expected' as text.""" | ||
536 | 505 | label = QtGui.QLabel() | ||
537 | 506 | maybe_elide_text(label, expected, max_width) | ||
538 | 507 | |||
539 | 508 | self.assertEqual(ERROR_STYLE % unicode(label.text()), | ||
540 | 509 | unicode(error_label.text())) | ||
541 | 510 | self.assertEqual(unicode(label.toolTip()), | ||
542 | 511 | unicode(error_label.toolTip())) | ||
543 | 512 | self.assertTrue(error_label.isVisible()) | ||
544 | 513 | |||
545 | 470 | def get_pixmap_data(self, pixmap): | 514 | def get_pixmap_data(self, pixmap): |
546 | 471 | """Get the raw data of a QPixmap.""" | 515 | """Get the raw data of a QPixmap.""" |
547 | 472 | byte_array = QtCore.QByteArray() | 516 | byte_array = QtCore.QByteArray() |
548 | @@ -550,14 +594,18 @@ | |||
549 | 550 | self.assertEqual(self._overlay_hide_counter, 1) | 594 | self.assertEqual(self._overlay_hide_counter, 1) |
550 | 551 | self.assertTrue(self.ui.isEnabled()) | 595 | self.assertTrue(self.ui.isEnabled()) |
551 | 552 | 596 | ||
552 | 597 | # pylint: disable=W0221 | ||
553 | 598 | |||
554 | 553 | def assert_title_correct(self, expected): | 599 | def assert_title_correct(self, expected): |
555 | 554 | """Check that the title is equal to 'expected'.""" | 600 | """Check that the title is equal to 'expected'.""" |
557 | 555 | self.assertEqual(TITLE_STYLE % expected, unicode(self.ui.title())) | 601 | check = super(PageBaseTestCase, self).assert_title_correct |
558 | 602 | check(self.ui.header.title_label, expected, | ||
559 | 603 | self.ui.header.max_title_width) | ||
560 | 556 | 604 | ||
561 | 557 | def assert_subtitle_correct(self, expected): | 605 | def assert_subtitle_correct(self, expected): |
562 | 558 | """Check that the subtitle is equal to 'expected'.""" | 606 | """Check that the subtitle is equal to 'expected'.""" |
565 | 559 | elided_text = unicode(self.ui.subTitle()) | 607 | check = super(PageBaseTestCase, self).assert_subtitle_correct |
566 | 560 | elided_text = elided_text[:len(elided_text) - 1] | 608 | check(self.ui.header.subtitle_label, expected, |
567 | 609 | self.ui.header.max_subtitle_width) | ||
568 | 561 | 610 | ||
571 | 562 | self.assertTrue(expected.startswith(elided_text)) | 611 | # pylint: enable=W0221 |
570 | 563 | self.assertEqual(self.ui.header.subtitle_label.toolTip(), expected) | ||
572 | 564 | 612 | ||
573 | === modified file 'ubuntu_sso/qt/tests/test_common.py' | |||
574 | --- ubuntu_sso/qt/tests/test_common.py 2011-10-28 10:41:18 +0000 | |||
575 | +++ ubuntu_sso/qt/tests/test_common.py 2012-03-14 13:30:25 +0000 | |||
576 | @@ -20,7 +20,9 @@ | |||
577 | 20 | from twisted.internet import defer | 20 | from twisted.internet import defer |
578 | 21 | from twisted.trial.unittest import TestCase | 21 | from twisted.trial.unittest import TestCase |
579 | 22 | 22 | ||
581 | 23 | from ubuntu_sso.qt.common import (check_as_invalid, | 23 | from ubuntu_sso.qt import maybe_elide_text |
582 | 24 | from ubuntu_sso.qt.common import ( | ||
583 | 25 | check_as_invalid, | ||
584 | 24 | check_as_valid, | 26 | check_as_valid, |
585 | 25 | password_assistance, | 27 | password_assistance, |
586 | 26 | password_check_match, | 28 | password_check_match, |
587 | @@ -30,7 +32,9 @@ | |||
588 | 30 | PASSWORD_DIGIT, | 32 | PASSWORD_DIGIT, |
589 | 31 | PASSWORD_LENGTH, | 33 | PASSWORD_LENGTH, |
590 | 32 | PASSWORD_MATCH, | 34 | PASSWORD_MATCH, |
592 | 33 | PASSWORD_UPPER) | 35 | PASSWORD_UPPER, |
593 | 36 | ) | ||
594 | 37 | from ubuntu_sso.qt.tests import build_string_for_pixels | ||
595 | 34 | 38 | ||
596 | 35 | 39 | ||
597 | 36 | class PasswordTestCase(TestCase): | 40 | class PasswordTestCase(TestCase): |
598 | @@ -234,3 +238,46 @@ | |||
599 | 234 | line_edit = QtGui.QLineEdit() | 238 | line_edit = QtGui.QLineEdit() |
600 | 235 | check_as_invalid(line_edit) | 239 | check_as_invalid(line_edit) |
601 | 236 | self.assertTrue(line_edit.property("formError").toBool()) | 240 | self.assertTrue(line_edit.property("formError").toBool()) |
602 | 241 | |||
603 | 242 | |||
604 | 243 | class ElidedTextTestCase(TestCase): | ||
605 | 244 | """The test case for the maybe_elide_text function.""" | ||
606 | 245 | |||
607 | 246 | max_width = 100 | ||
608 | 247 | |||
609 | 248 | @defer.inlineCallbacks | ||
610 | 249 | def setUp(self): | ||
611 | 250 | """Setup tests.""" | ||
612 | 251 | yield super(ElidedTextTestCase, self).setUp() | ||
613 | 252 | self.ui = QtGui.QLabel() | ||
614 | 253 | |||
615 | 254 | def test_text_not_elided_if_too_short(self): | ||
616 | 255 | """If text is shorter than max_width, do not elide.""" | ||
617 | 256 | text = build_string_for_pixels(self.ui, self.max_width - 1) | ||
618 | 257 | |||
619 | 258 | maybe_elide_text(self.ui, text, self.max_width) | ||
620 | 259 | |||
621 | 260 | self.assertEqual(self.ui.toolTip(), '') | ||
622 | 261 | self.assertEqual(self.ui.text(), text) | ||
623 | 262 | self.assertNotIn(u'\u2026', self.ui.text()) | ||
624 | 263 | |||
625 | 264 | def test_text_not_elided_if_equals_max_width(self): | ||
626 | 265 | """If text is equal than max_width, do not elide.""" | ||
627 | 266 | text = build_string_for_pixels(self.ui, self.max_width) | ||
628 | 267 | |||
629 | 268 | maybe_elide_text(self.ui, text, self.max_width) | ||
630 | 269 | |||
631 | 270 | self.assertEqual(self.ui.toolTip(), '') | ||
632 | 271 | self.assertEqual(self.ui.text(), text) | ||
633 | 272 | self.assertNotIn(u'\u2026', self.ui.text()) | ||
634 | 273 | |||
635 | 274 | def test_text_elided_if_bigger_than_max_width(self): | ||
636 | 275 | """If text is equal than max_width, do not elide.""" | ||
637 | 276 | text = build_string_for_pixels(self.ui, self.max_width + 10) | ||
638 | 277 | |||
639 | 278 | maybe_elide_text(self.ui, text, self.max_width) | ||
640 | 279 | |||
641 | 280 | self.assertEqual(self.ui.toolTip(), text) | ||
642 | 281 | expected = unicode(self.ui.text()) | ||
643 | 282 | self.assertTrue(expected.endswith(u'\u2026')) | ||
644 | 283 | self.assertTrue(text.startswith(expected[:-1])) | ||
645 | 237 | 284 | ||
646 | === modified file 'ubuntu_sso/qt/tests/test_current_user_sign_in_page.py' | |||
647 | --- ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-03-12 19:47:07 +0000 | |||
648 | +++ ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-03-14 13:30:25 +0000 | |||
649 | @@ -142,13 +142,13 @@ | |||
650 | 142 | def test_on_login_error(self): | 142 | def test_on_login_error(self): |
651 | 143 | """Test the on_login_error method.""" | 143 | """Test the on_login_error method.""" |
652 | 144 | self.patch(self.ui, "show_error", self._set_called) | 144 | self.patch(self.ui, "show_error", self._set_called) |
653 | 145 | app_name = 'my_app' | ||
654 | 146 | self.ui.app_name = app_name | ||
655 | 147 | error = {'errtype': 'UserNotValidated'} | 145 | error = {'errtype': 'UserNotValidated'} |
657 | 148 | self.ui.on_login_error(app_name, error) | 146 | |
658 | 147 | self.ui.on_login_error(self.app_name, error) | ||
659 | 148 | |||
660 | 149 | self.assertEqual(self._overlay_hide_counter, 0) | 149 | self.assertEqual(self._overlay_hide_counter, 0) |
661 | 150 | self.assertTrue(self.ui.isEnabled()) | 150 | self.assertTrue(self.ui.isEnabled()) |
663 | 151 | expected = ((self.ui, 'my_app', ''), {}) | 151 | expected = ((self.ui, self.app_name, ''), {}) |
664 | 152 | self.assertTrue(expected, self._called) | 152 | self.assertTrue(expected, self._called) |
665 | 153 | 153 | ||
666 | 154 | def test_on_logged_in(self): | 154 | def test_on_logged_in(self): |
667 | 155 | 155 | ||
668 | === modified file 'ubuntu_sso/qt/tests/test_email_verification.py' | |||
669 | --- ubuntu_sso/qt/tests/test_email_verification.py 2012-03-12 19:47:07 +0000 | |||
670 | +++ ubuntu_sso/qt/tests/test_email_verification.py 2012-03-14 13:30:25 +0000 | |||
671 | @@ -78,14 +78,12 @@ | |||
672 | 78 | email = 'mail@example' | 78 | email = 'mail@example' |
673 | 79 | self.ui.email = email | 79 | self.ui.email = email |
674 | 80 | self.ui.set_titles(email) | 80 | self.ui.set_titles(email) |
677 | 81 | self.assertEqual(unicode(self.ui.header.title_label.text()), | 81 | self.assert_title_correct(email_verification_page.VERIFY_EMAIL_TITLE) |
676 | 82 | email_verification_page.VERIFY_EMAIL_TITLE) | ||
678 | 83 | expected = email_verification_page.VERIFY_EMAIL_CONTENT % { | 82 | expected = email_verification_page.VERIFY_EMAIL_CONTENT % { |
679 | 84 | "app_name": self.app_name, | 83 | "app_name": self.app_name, |
680 | 85 | "email": email, | 84 | "email": email, |
681 | 86 | } | 85 | } |
684 | 87 | self.assertEqual(unicode(self.ui.header.subtitle_label.toolTip()), | 86 | self.assert_subtitle_correct(expected) |
683 | 88 | expected) | ||
685 | 89 | 87 | ||
686 | 90 | def test_initialize_page(self): | 88 | def test_initialize_page(self): |
687 | 91 | """Test the initialization method.""" | 89 | """Test the initialization method.""" |
688 | @@ -100,10 +98,11 @@ | |||
689 | 100 | def test_on_email_validation_error(self): | 98 | def test_on_email_validation_error(self): |
690 | 101 | """Test the validate_email method.""" | 99 | """Test the validate_email method.""" |
691 | 102 | self.patch(self.ui, "show_error", self._set_called) | 100 | self.patch(self.ui, "show_error", self._set_called) |
692 | 103 | app_name = 'my_app' | ||
693 | 104 | error = {email_verification_page: 'error in email_verification_page'} | 101 | error = {email_verification_page: 'error in email_verification_page'} |
696 | 105 | self.ui.on_email_validation_error(app_name, error) | 102 | |
697 | 106 | expected = ((self.ui, app_name, ''), {}) | 103 | self.ui.on_email_validation_error(self.app_name, error) |
698 | 104 | |||
699 | 105 | expected = ((self.ui, ''), {}) | ||
700 | 107 | self.assertTrue(expected, self._called) | 106 | self.assertTrue(expected, self._called) |
701 | 108 | self.assertEqual(self._overlay_hide_counter, 1) | 107 | self.assertEqual(self._overlay_hide_counter, 1) |
702 | 109 | 108 | ||
703 | 110 | 109 | ||
704 | === modified file 'ubuntu_sso/qt/tests/test_forgotten_password.py' | |||
705 | --- ubuntu_sso/qt/tests/test_forgotten_password.py 2012-03-12 19:47:07 +0000 | |||
706 | +++ ubuntu_sso/qt/tests/test_forgotten_password.py 2012-03-14 13:30:25 +0000 | |||
707 | @@ -113,7 +113,8 @@ | |||
708 | 113 | """Test on_password_reset_error method.""" | 113 | """Test on_password_reset_error method.""" |
709 | 114 | self.patch(self.ui, "show_error", self._set_called) | 114 | self.patch(self.ui, "show_error", self._set_called) |
710 | 115 | error = {'errtype': 'FooBarBaz'} | 115 | error = {'errtype': 'FooBarBaz'} |
711 | 116 | |||
712 | 116 | self.ui.on_password_reset_error(self.app_name, error) | 117 | self.ui.on_password_reset_error(self.app_name, error) |
715 | 117 | expected = ((self.ui, self.app_name, | 118 | |
716 | 118 | gui.REQUEST_PASSWORD_TOKEN_WRONG_EMAIL), {}) | 119 | expected = ((self.ui, gui.REQUEST_PASSWORD_TOKEN_WRONG_EMAIL), {}) |
717 | 119 | self.assertTrue(expected, self._called) | 120 | self.assertTrue(expected, self._called) |
718 | 120 | 121 | ||
719 | === modified file 'ubuntu_sso/qt/tests/test_loadingoverlay.py' | |||
720 | --- ubuntu_sso/qt/tests/test_loadingoverlay.py 2012-02-23 19:49:02 +0000 | |||
721 | +++ ubuntu_sso/qt/tests/test_loadingoverlay.py 2012-03-14 13:30:25 +0000 | |||
722 | @@ -29,8 +29,5 @@ | |||
723 | 29 | 29 | ||
724 | 30 | def test_status_correct(self): | 30 | def test_status_correct(self): |
725 | 31 | """Test if the necessary variables for the animation exists""" | 31 | """Test if the necessary variables for the animation exists""" |
726 | 32 | self.ui.show() | ||
727 | 33 | self.addCleanup(self.ui.hide) | ||
728 | 34 | |||
729 | 35 | self.assertTrue(self.ui.counter is not None) | 32 | self.assertTrue(self.ui.counter is not None) |
730 | 36 | self.assertTrue(self.ui.orientation is not None) | 33 | self.assertTrue(self.ui.orientation is not None) |
731 | 37 | 34 | ||
732 | === modified file 'ubuntu_sso/qt/tests/test_reset_password.py' | |||
733 | --- ubuntu_sso/qt/tests/test_reset_password.py 2012-03-12 19:47:07 +0000 | |||
734 | +++ ubuntu_sso/qt/tests/test_reset_password.py 2012-03-14 13:30:25 +0000 | |||
735 | @@ -70,9 +70,7 @@ | |||
736 | 70 | 70 | ||
737 | 71 | def test_initialize(self): | 71 | def test_initialize(self): |
738 | 72 | """Check the Title and Subtitle.""" | 72 | """Check the Title and Subtitle.""" |
739 | 73 | self.ui.show() | ||
740 | 74 | self.ui.initializePage() | 73 | self.ui.initializePage() |
741 | 75 | self.addCleanup(self.ui.hide) | ||
742 | 76 | self.assert_title_correct(RESET_TITLE) | 74 | self.assert_title_correct(RESET_TITLE) |
743 | 77 | self.assert_subtitle_correct(RESET_SUBTITLE) | 75 | self.assert_subtitle_correct(RESET_SUBTITLE) |
744 | 78 | self.assertEqual(unicode(self.ui.ui.password_label.text()), | 76 | self.assertEqual(unicode(self.ui.ui.password_label.text()), |
745 | @@ -84,15 +82,11 @@ | |||
746 | 84 | 82 | ||
747 | 85 | def test_focus_changed_password_visibility(self): | 83 | def test_focus_changed_password_visibility(self): |
748 | 86 | """Check visibility changes when focus_changed() is executed.""" | 84 | """Check visibility changes when focus_changed() is executed.""" |
749 | 87 | self.ui.show() | ||
750 | 88 | self.addCleanup(self.ui.hide) | ||
751 | 89 | self.ui.focus_changed(None, self.ui.ui.password_line_edit) | 85 | self.ui.focus_changed(None, self.ui.ui.password_line_edit) |
752 | 90 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) | 86 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
753 | 91 | 87 | ||
754 | 92 | def test_show_hide_event(self): | 88 | def test_show_hide_event(self): |
755 | 93 | """Check connections to focusChanged on show and hide event.""" | 89 | """Check connections to focusChanged on show and hide event.""" |
756 | 94 | self.ui.show() | ||
757 | 95 | self.addCleanup(self.ui.hide) | ||
758 | 96 | self.assertEqual(QtGui.QApplication.instance().receivers( | 90 | self.assertEqual(QtGui.QApplication.instance().receivers( |
759 | 97 | QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 1) | 91 | QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 1) |
760 | 98 | self.ui.hide() | 92 | self.ui.hide() |
761 | @@ -104,24 +98,20 @@ | |||
762 | 104 | def test_focus_changed_1(self): | 98 | def test_focus_changed_1(self): |
763 | 105 | """Check functions execution when focus_changed() is executed.""" | 99 | """Check functions execution when focus_changed() is executed.""" |
764 | 106 | self.patch(common, 'password_default_assistance', self._set_called) | 100 | self.patch(common, 'password_default_assistance', self._set_called) |
765 | 107 | |||
766 | 108 | self.ui.show() | ||
767 | 109 | self.addCleanup(self.ui.hide) | ||
768 | 110 | |||
769 | 111 | self.assertFalse(self._called) | 101 | self.assertFalse(self._called) |
770 | 102 | |||
771 | 112 | self.ui.focus_changed(None, self.ui.ui.password_line_edit) | 103 | self.ui.focus_changed(None, self.ui.ui.password_line_edit) |
772 | 104 | |||
773 | 113 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) | 105 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
774 | 114 | self.assertTrue(self._called) | 106 | self.assertTrue(self._called) |
775 | 115 | 107 | ||
776 | 116 | def test_focus_changed_2(self): | 108 | def test_focus_changed_2(self): |
777 | 117 | """Check functions execution when focus_changed() is executed.""" | 109 | """Check functions execution when focus_changed() is executed.""" |
778 | 118 | self.patch(common, 'password_check_match', self._set_called) | 110 | self.patch(common, 'password_check_match', self._set_called) |
779 | 119 | |||
780 | 120 | self.ui.show() | ||
781 | 121 | self.addCleanup(self.ui.hide) | ||
782 | 122 | |||
783 | 123 | self.assertFalse(self._called) | 111 | self.assertFalse(self._called) |
784 | 112 | |||
785 | 124 | self.ui.focus_changed(None, self.ui.ui.confirm_password_line_edit) | 113 | self.ui.focus_changed(None, self.ui.ui.confirm_password_line_edit) |
786 | 114 | |||
787 | 125 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) | 115 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
788 | 126 | self.assertTrue(self._called) | 116 | self.assertTrue(self._called) |
789 | 127 | 117 | ||
790 | 128 | 118 | ||
791 | === modified file 'ubuntu_sso/qt/tests/test_setup_account.py' | |||
792 | --- ubuntu_sso/qt/tests/test_setup_account.py 2012-03-12 19:47:07 +0000 | |||
793 | +++ ubuntu_sso/qt/tests/test_setup_account.py 2012-03-14 13:30:25 +0000 | |||
794 | @@ -43,13 +43,9 @@ | |||
795 | 43 | """ | 43 | """ |
796 | 44 | self.ui.ui.name_edit.setText("") | 44 | self.ui.ui.name_edit.setText("") |
797 | 45 | self.ui.name_assistance() | 45 | self.ui.name_assistance() |
798 | 46 | self.ui.show() | ||
799 | 47 | self.addCleanup(self.ui.hide) | ||
800 | 48 | self.assertTrue(self.ui.ui.name_assistance.isVisible()) | 46 | self.assertTrue(self.ui.ui.name_assistance.isVisible()) |
805 | 49 | self.assertEqual( | 47 | self.assert_error_correct(self.ui.ui.name_assistance, gui.EMPTY_NAME, |
806 | 50 | unicode(self.ui.ui.name_assistance.text()), | 48 | max_width=self.ui.header.max_title_width) |
803 | 51 | gui.ERROR_STYLE % gui.EMPTY_NAME) | ||
804 | 52 | self.ui.hide() | ||
807 | 53 | 49 | ||
808 | 54 | def test_enable_setup_button_with_visible_check(self): | 50 | def test_enable_setup_button_with_visible_check(self): |
809 | 55 | """Test _enable_setup_button method with terms check visible.""" | 51 | """Test _enable_setup_button method with terms check visible.""" |
810 | @@ -65,8 +61,6 @@ | |||
811 | 65 | self.ui.ui.captcha_solution_edit.setText('captcha solution') | 61 | self.ui.ui.captcha_solution_edit.setText('captcha solution') |
812 | 66 | self.ui.terms_checkbox.setChecked(True) | 62 | self.ui.terms_checkbox.setChecked(True) |
813 | 67 | 63 | ||
814 | 68 | self.ui.show() | ||
815 | 69 | self.addCleanup(self.ui.hide) | ||
816 | 70 | self.ui.terms_checkbox.setVisible(True) | 64 | self.ui.terms_checkbox.setVisible(True) |
817 | 71 | self.ui.ui.captcha_solution_edit.textEdited.emit('') | 65 | self.ui.ui.captcha_solution_edit.textEdited.emit('') |
818 | 72 | self.assertTrue(self.ui.set_up_button.isEnabled()) | 66 | self.assertTrue(self.ui.set_up_button.isEnabled()) |
819 | @@ -84,8 +78,6 @@ | |||
820 | 84 | self.ui.ui.confirm_password_edit.setText(password) | 78 | self.ui.ui.confirm_password_edit.setText(password) |
821 | 85 | self.ui.ui.captcha_solution_edit.setText('captcha solution') | 79 | self.ui.ui.captcha_solution_edit.setText('captcha solution') |
822 | 86 | 80 | ||
823 | 87 | self.ui.show() | ||
824 | 88 | self.addCleanup(self.ui.hide) | ||
825 | 89 | self.ui.terms_checkbox.setVisible(False) | 81 | self.ui.terms_checkbox.setVisible(False) |
826 | 90 | self.ui.ui.captcha_solution_edit.textEdited.emit('') | 82 | self.ui.ui.captcha_solution_edit.textEdited.emit('') |
827 | 91 | self.assertTrue(self.ui.set_up_button.isEnabled()) | 83 | self.assertTrue(self.ui.set_up_button.isEnabled()) |
828 | @@ -114,8 +106,6 @@ | |||
829 | 114 | 106 | ||
830 | 115 | def test_password_focus_gain(self): | 107 | def test_password_focus_gain(self): |
831 | 116 | """Check functions execution when focus_changed() is executed.""" | 108 | """Check functions execution when focus_changed() is executed.""" |
832 | 117 | self.ui.show() | ||
833 | 118 | self.addCleanup(self.ui.hide) | ||
834 | 119 | self.ui.ui.password_assistance.setVisible(False) | 109 | self.ui.ui.password_assistance.setVisible(False) |
835 | 120 | self.assertFalse(self.ui.ui.password_assistance.isVisible()) | 110 | self.assertFalse(self.ui.ui.password_assistance.isVisible()) |
836 | 121 | self.patch(self.ui, 'name_assistance', self._set_called) | 111 | self.patch(self.ui, 'name_assistance', self._set_called) |
837 | @@ -192,8 +182,6 @@ | |||
838 | 192 | def test_initialize_page(self): | 182 | def test_initialize_page(self): |
839 | 193 | """Widgets are properly initialized.""" | 183 | """Widgets are properly initialized.""" |
840 | 194 | self.ui.initializePage() | 184 | self.ui.initializePage() |
841 | 195 | self.ui.show() | ||
842 | 196 | self.addCleanup(self.ui.hide) | ||
843 | 197 | 185 | ||
844 | 198 | # set up account button | 186 | # set up account button |
845 | 199 | expected = [QtGui.QWizard.BackButton, QtGui.QWizard.Stretch, | 187 | expected = [QtGui.QWizard.BackButton, QtGui.QWizard.Stretch, |
846 | @@ -232,8 +220,6 @@ | |||
847 | 232 | self.patch(self.ui, 'set_next_validation', self._set_called) | 220 | self.patch(self.ui, 'set_next_validation', self._set_called) |
848 | 233 | self.ui.initializePage() | 221 | self.ui.initializePage() |
849 | 234 | self.ui.captcha_received = True | 222 | self.ui.captcha_received = True |
850 | 235 | self.ui.show() | ||
851 | 236 | self.addCleanup(self.ui.hide) | ||
852 | 237 | 223 | ||
853 | 238 | self.ui.set_up_button.clicked.emit(False) | 224 | self.ui.set_up_button.clicked.emit(False) |
854 | 239 | self.assertEqual(self._called, ((False,), {})) | 225 | self.assertEqual(self._called, ((False,), {})) |
855 | @@ -241,13 +227,10 @@ | |||
856 | 241 | def test_set_error_message(self): | 227 | def test_set_error_message(self): |
857 | 242 | """Check the state of the label after calling: set_error_message.""" | 228 | """Check the state of the label after calling: set_error_message.""" |
858 | 243 | self.ui.email_assistance() | 229 | self.ui.email_assistance() |
859 | 244 | self.ui.show() | ||
860 | 245 | self.addCleanup(self.ui.hide) | ||
861 | 246 | self.ui.set_error_message(self.ui.ui.email_assistance, "message") | 230 | self.ui.set_error_message(self.ui.ui.email_assistance, "message") |
862 | 247 | self.assertTrue(self.ui.ui.email_assistance.isVisible()) | 231 | self.assertTrue(self.ui.ui.email_assistance.isVisible()) |
866 | 248 | self.assertEqual( | 232 | self.assert_error_correct(self.ui.ui.email_assistance, "message", |
867 | 249 | unicode(self.ui.ui.email_assistance.text()), | 233 | max_width=self.ui.header.max_title_width) |
865 | 250 | gui.ERROR_STYLE % "message") | ||
868 | 251 | 234 | ||
869 | 252 | def test_blank_name(self): | 235 | def test_blank_name(self): |
870 | 253 | """Status when the name field is blank (spaces). | 236 | """Status when the name field is blank (spaces). |
871 | @@ -257,13 +240,9 @@ | |||
872 | 257 | """ | 240 | """ |
873 | 258 | self.ui.ui.name_edit.setText(" ") | 241 | self.ui.ui.name_edit.setText(" ") |
874 | 259 | self.ui.name_assistance() | 242 | self.ui.name_assistance() |
875 | 260 | self.ui.show() | ||
876 | 261 | self.addCleanup(self.ui.hide) | ||
877 | 262 | self.assertTrue(self.ui.ui.name_assistance.isVisible()) | 243 | self.assertTrue(self.ui.ui.name_assistance.isVisible()) |
882 | 263 | self.assertEqual( | 244 | self.assert_error_correct(self.ui.ui.name_assistance, gui.EMPTY_NAME, |
883 | 264 | unicode(self.ui.ui.name_assistance.text()), | 245 | max_width=self.ui.header.max_title_width) |
880 | 265 | gui.ERROR_STYLE % gui.EMPTY_NAME) | ||
881 | 266 | self.ui.hide() | ||
884 | 267 | 246 | ||
885 | 268 | def test_valid_name(self): | 247 | def test_valid_name(self): |
886 | 269 | """Status when the name field is valid. | 248 | """Status when the name field is valid. |
887 | @@ -272,10 +251,7 @@ | |||
888 | 272 | """ | 251 | """ |
889 | 273 | self.ui.ui.name_edit.setText("John Doe") | 252 | self.ui.ui.name_edit.setText("John Doe") |
890 | 274 | self.ui.name_assistance() | 253 | self.ui.name_assistance() |
891 | 275 | self.ui.show() | ||
892 | 276 | self.addCleanup(self.ui.hide) | ||
893 | 277 | self.assertFalse(self.ui.ui.name_assistance.isVisible()) | 254 | self.assertFalse(self.ui.ui.name_assistance.isVisible()) |
894 | 278 | self.ui.hide() | ||
895 | 279 | 255 | ||
896 | 280 | def test_invalid_email(self): | 256 | def test_invalid_email(self): |
897 | 281 | """Status when the email field has no @. | 257 | """Status when the email field has no @. |
898 | @@ -285,12 +261,10 @@ | |||
899 | 285 | """ | 261 | """ |
900 | 286 | self.ui.ui.email_edit.setText("foobar") | 262 | self.ui.ui.email_edit.setText("foobar") |
901 | 287 | self.ui.email_assistance() | 263 | self.ui.email_assistance() |
902 | 288 | self.ui.show() | ||
903 | 289 | self.addCleanup(self.ui.hide) | ||
904 | 290 | self.assertTrue(self.ui.ui.email_assistance.isVisible()) | 264 | self.assertTrue(self.ui.ui.email_assistance.isVisible()) |
908 | 291 | self.assertEqual( | 265 | self.assert_error_correct(self.ui.ui.email_assistance, |
909 | 292 | unicode(self.ui.ui.email_assistance.text()), | 266 | gui.INVALID_EMAIL, |
910 | 293 | gui.ERROR_STYLE % gui.INVALID_EMAIL) | 267 | max_width=self.ui.header.max_title_width) |
911 | 294 | 268 | ||
912 | 295 | def test_valid_email(self): | 269 | def test_valid_email(self): |
913 | 296 | """Status when the email field has a @. | 270 | """Status when the email field has a @. |
914 | @@ -299,10 +273,7 @@ | |||
915 | 299 | """ | 273 | """ |
916 | 300 | self.ui.ui.email_edit.setText("foo@bar") | 274 | self.ui.ui.email_edit.setText("foo@bar") |
917 | 301 | self.ui.email_assistance() | 275 | self.ui.email_assistance() |
918 | 302 | self.ui.show() | ||
919 | 303 | self.addCleanup(self.ui.hide) | ||
920 | 304 | self.assertFalse(self.ui.ui.email_assistance.isVisible()) | 276 | self.assertFalse(self.ui.ui.email_assistance.isVisible()) |
921 | 305 | self.ui.hide() | ||
922 | 306 | 277 | ||
923 | 307 | def test_matching_emails(self): | 278 | def test_matching_emails(self): |
924 | 308 | """Status when the email fields match. | 279 | """Status when the email fields match. |
925 | @@ -312,10 +283,7 @@ | |||
926 | 312 | self.ui.ui.email_edit.setText("foo@bar") | 283 | self.ui.ui.email_edit.setText("foo@bar") |
927 | 313 | self.ui.ui.confirm_email_edit.setText("foo@bar") | 284 | self.ui.ui.confirm_email_edit.setText("foo@bar") |
928 | 314 | self.ui.confirm_email_assistance() | 285 | self.ui.confirm_email_assistance() |
929 | 315 | self.ui.show() | ||
930 | 316 | self.addCleanup(self.ui.hide) | ||
931 | 317 | self.assertFalse(self.ui.ui.confirm_email_assistance.isVisible()) | 286 | self.assertFalse(self.ui.ui.confirm_email_assistance.isVisible()) |
932 | 318 | self.ui.hide() | ||
933 | 319 | 287 | ||
934 | 320 | def test_not_matching_emails(self): | 288 | def test_not_matching_emails(self): |
935 | 321 | """Status when the email fields don't match. | 289 | """Status when the email fields don't match. |
936 | @@ -326,18 +294,13 @@ | |||
937 | 326 | self.ui.ui.email_edit.setText("foo@bar") | 294 | self.ui.ui.email_edit.setText("foo@bar") |
938 | 327 | self.ui.ui.confirm_email_edit.setText("foo@baz") | 295 | self.ui.ui.confirm_email_edit.setText("foo@baz") |
939 | 328 | self.ui.confirm_email_assistance() | 296 | self.ui.confirm_email_assistance() |
940 | 329 | self.ui.show() | ||
941 | 330 | self.addCleanup(self.ui.hide) | ||
942 | 331 | self.assertTrue(self.ui.ui.confirm_email_assistance.isVisible()) | 297 | self.assertTrue(self.ui.ui.confirm_email_assistance.isVisible()) |
947 | 332 | self.assertEqual( | 298 | self.assert_error_correct(self.ui.ui.confirm_email_assistance, |
948 | 333 | unicode(self.ui.ui.confirm_email_assistance.text()), | 299 | gui.EMAIL_MATCH, |
949 | 334 | gui.ERROR_STYLE % gui.EMAIL_MATCH) | 300 | max_width=self.ui.header.max_title_width) |
946 | 335 | self.ui.hide() | ||
950 | 336 | 301 | ||
951 | 337 | def test_focus_changed_password_visibility(self): | 302 | def test_focus_changed_password_visibility(self): |
952 | 338 | """Check visibility changes when focus_changed() is executed.""" | 303 | """Check visibility changes when focus_changed() is executed.""" |
953 | 339 | self.ui.show() | ||
954 | 340 | self.addCleanup(self.ui.hide) | ||
955 | 341 | self.ui.focus_changed(None, self.ui.ui.password_edit) | 304 | self.ui.focus_changed(None, self.ui.ui.password_edit) |
956 | 342 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) | 305 | self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
957 | 343 | 306 | ||
958 | @@ -352,33 +315,41 @@ | |||
959 | 352 | self.ui.showEvent(QtGui.QShowEvent()) | 315 | self.ui.showEvent(QtGui.QShowEvent()) |
960 | 353 | self.ui.hideEvent(QtGui.QHideEvent()) | 316 | self.ui.hideEvent(QtGui.QHideEvent()) |
961 | 354 | 317 | ||
963 | 355 | def test_on_captcha_refreshing(self): | 318 | def test_on_captcha_refreshing_visible(self): |
964 | 356 | """Check the state of the overlay on captcha refreshing.""" | 319 | """Check the state of the overlay on captcha refreshing.""" |
975 | 357 | self.assertEqual(self._overlay_show_counter, 0) | 320 | self.ui.hide_overlay() |
976 | 358 | self.ui.on_captcha_refreshing() | 321 | |
977 | 359 | self.assertEqual(self._overlay_show_counter, 0) | 322 | self.assertEqual(self._overlay_show_counter, 0) |
978 | 360 | self.assertTrue(self.ui.isEnabled()) | 323 | self.assertTrue(self.ui.isEnabled()) |
979 | 361 | self.ui.captcha_received = True | 324 | |
980 | 362 | self.ui.show() | 325 | self.ui.on_captcha_refreshing() |
981 | 363 | self.addCleanup(self.ui.hide) | 326 | |
972 | 364 | self.assertEqual(self._overlay_show_counter, 0) | ||
973 | 365 | self.assertTrue(self.ui.isEnabled()) | ||
974 | 366 | self.ui.on_captcha_refreshing() | ||
982 | 367 | self.assertFalse(self.ui.isEnabled()) | 327 | self.assertFalse(self.ui.isEnabled()) |
983 | 368 | self.assertEqual(self._overlay_show_counter, 1) | 328 | self.assertEqual(self._overlay_show_counter, 1) |
984 | 369 | 329 | ||
985 | 330 | def test_on_captcha_refreshing_not_visible(self): | ||
986 | 331 | """Check the state of the overlay on captcha refreshing.""" | ||
987 | 332 | self.ui.hide_overlay() | ||
988 | 333 | |||
989 | 334 | self.assertEqual(self._overlay_show_counter, 0) | ||
990 | 335 | self.assertTrue(self.ui.isEnabled()) | ||
991 | 336 | |||
992 | 337 | self.ui.hide() | ||
993 | 338 | self.ui.on_captcha_refreshing() | ||
994 | 339 | |||
995 | 340 | self.assertEqual(self._overlay_show_counter, 0) | ||
996 | 341 | self.assertTrue(self.ui.isEnabled()) | ||
997 | 342 | |||
998 | 370 | def test_on_captcha_refresh_complete(self): | 343 | def test_on_captcha_refresh_complete(self): |
999 | 371 | """Check the state of the overlay on captcha refreshing complete.""" | 344 | """Check the state of the overlay on captcha refreshing complete.""" |
1000 | 372 | self.assertEqual(self._overlay_hide_counter, 0) | 345 | self.assertEqual(self._overlay_hide_counter, 0) |
1002 | 373 | self.assertTrue(self.ui.isEnabled()) | 346 | |
1003 | 374 | self.ui.on_captcha_refresh_complete() | 347 | self.ui.on_captcha_refresh_complete() |
1004 | 348 | |||
1005 | 375 | self.assertEqual(self._overlay_hide_counter, 1) | 349 | self.assertEqual(self._overlay_hide_counter, 1) |
1006 | 376 | self.assertTrue(self.ui.isEnabled()) | ||
1007 | 377 | 350 | ||
1008 | 378 | def test_hide_error_on_refresh_captcha(self): | 351 | def test_hide_error_on_refresh_captcha(self): |
1009 | 379 | """Test that the errors are hidden on refresh captcha.""" | 352 | """Test that the errors are hidden on refresh captcha.""" |
1013 | 380 | self.ui.show() | 353 | self.ui.show_error('error-message') |
1011 | 381 | self.addCleanup(self.ui.hide) | ||
1012 | 382 | self.ui.show_error(self.app_name, 'error-message') | ||
1014 | 383 | self.ui.ui.refresh_label.linkActivated.emit('link') | 354 | self.ui.ui.refresh_label.linkActivated.emit('link') |
1015 | 384 | self.assertEqual(self.ui.form_errors_label.text(), ' ') | 355 | self.assertEqual(self.ui.form_errors_label.text(), ' ') |
1016 | 385 | 356 | ||
1017 | === modified file 'ubuntu_sso/qt/tests/test_sso_wizard_page.py' | |||
1018 | --- ubuntu_sso/qt/tests/test_sso_wizard_page.py 2012-03-05 18:56:50 +0000 | |||
1019 | +++ ubuntu_sso/qt/tests/test_sso_wizard_page.py 2012-03-14 13:30:25 +0000 | |||
1020 | @@ -16,98 +16,127 @@ | |||
1021 | 16 | 16 | ||
1022 | 17 | """Test the SSOWizardPage and related.""" | 17 | """Test the SSOWizardPage and related.""" |
1023 | 18 | 18 | ||
1033 | 19 | from twisted.internet import defer | 19 | from ubuntu_sso.qt import PREFERED_UI_SIZE, sso_wizard_page as gui |
1034 | 20 | 20 | from ubuntu_sso.qt.tests import ( | |
1035 | 21 | from ubuntu_sso.qt import PREFERED_UI_SIZE | 21 | APP_NAME, |
1036 | 22 | from ubuntu_sso.qt.setup_account_page import SetupAccountPage | 22 | BaseTestCase, |
1037 | 23 | from ubuntu_sso.qt.sso_wizard_page import Header | 23 | build_string_for_pixels, |
1038 | 24 | from ubuntu_sso.qt.tests import BaseTestCase, PageBaseTestCase | 24 | PageBaseTestCase, |
1039 | 25 | 25 | ) | |
1040 | 26 | 26 | ||
1041 | 27 | class HeaderTest(BaseTestCase): | 27 | |
1042 | 28 | MAX_WIDTH = 100 | ||
1043 | 29 | |||
1044 | 30 | |||
1045 | 31 | class WizardHeaderTestCase(BaseTestCase): | ||
1046 | 28 | 32 | ||
1047 | 29 | """Tests for injected Header in each Wizard Page.""" | 33 | """Tests for injected Header in each Wizard Page.""" |
1048 | 30 | 34 | ||
1053 | 31 | @defer.inlineCallbacks | 35 | kwargs = dict(max_width=MAX_WIDTH) |
1054 | 32 | def setUp(self): | 36 | ui_class = gui.WizardHeader |
1055 | 33 | yield super(HeaderTest, self).setUp() | 37 | ui_wizard_class = None |
1052 | 34 | self.header = Header() | ||
1056 | 35 | 38 | ||
1057 | 36 | def test_label_state(self): | 39 | def test_label_state(self): |
1058 | 37 | """Check the title and subtitle properties.""" | 40 | """Check the title and subtitle properties.""" |
1063 | 38 | self.assertTrue(self.header.title_label.wordWrap()) | 41 | self.assertTrue(self.ui.title_label.wordWrap()) |
1064 | 39 | self.assertTrue(self.header.subtitle_label.wordWrap()) | 42 | self.assertTrue(self.ui.subtitle_label.wordWrap()) |
1065 | 40 | self.assertFalse(self.header.title_label.isVisible()) | 43 | self.assertFalse(self.ui.title_label.isVisible()) |
1066 | 41 | self.assertFalse(self.header.subtitle_label.isVisible()) | 44 | self.assertFalse(self.ui.subtitle_label.isVisible()) |
1067 | 42 | 45 | ||
1068 | 43 | def test_set_title(self): | 46 | def test_set_title(self): |
1069 | 44 | """Check if set_title works ok, showing the widget if necessary.""" | 47 | """Check if set_title works ok, showing the widget if necessary.""" |
1075 | 45 | self.header.set_title('title') | 48 | max_width = self.ui.max_title_width |
1076 | 46 | self.assertEqual(self.header.title_label.text(), 'title') | 49 | text = build_string_for_pixels(self.ui.title_label, max_width) |
1077 | 47 | self.header.show() | 50 | |
1078 | 48 | self.assertTrue(self.header.title_label.isVisible()) | 51 | self.ui.set_title(text) |
1079 | 49 | self.header.hide() | 52 | |
1080 | 53 | self.assert_title_correct(self.ui.title_label, text, max_width) | ||
1081 | 50 | 54 | ||
1082 | 51 | def test_set_elided_title(self): | 55 | def test_set_elided_title(self): |
1083 | 52 | """Check if set_title adds the ellipsis when necessary.""" | 56 | """Check if set_title adds the ellipsis when necessary.""" |
1084 | 53 | # add an extra letter so we ensure this needs to be trimmed | 57 | # add an extra letter so we ensure this needs to be trimmed |
1090 | 54 | title = 'a' * int(PREFERED_UI_SIZE['width'] * 0.95) + 'a' | 58 | max_width = self.ui.max_title_width |
1091 | 55 | self.header.set_title(title) | 59 | text = build_string_for_pixels(self.ui.title_label, max_width + 10) |
1092 | 56 | self.assertEqual(self.header.title_label.toolTip(), title) | 60 | |
1093 | 57 | expected = unicode(self.header.title_label.text()) | 61 | self.ui.set_title(text) |
1094 | 58 | self.assertTrue(expected.endswith(u'\u2026')) | 62 | |
1095 | 63 | self.assert_title_correct(self.ui.title_label, text, max_width) | ||
1096 | 59 | 64 | ||
1097 | 60 | def test_set_empty_title(self): | 65 | def test_set_empty_title(self): |
1098 | 61 | """Check if the widget is hidden for empty title.""" | 66 | """Check if the widget is hidden for empty title.""" |
1101 | 62 | self.header.set_title('') | 67 | self.ui.set_title('') |
1102 | 63 | self.assertFalse(self.header.title_label.isVisible()) | 68 | |
1103 | 69 | self.assertEqual(self.ui.title_label.toolTip(), '') | ||
1104 | 70 | self.assertFalse(self.ui.title_label.isVisible()) | ||
1105 | 64 | 71 | ||
1106 | 65 | def test_set_subtitle(self): | 72 | def test_set_subtitle(self): |
1107 | 66 | """Check if set_subtitle works ok, showing the widget if necessary.""" | 73 | """Check if set_subtitle works ok, showing the widget if necessary.""" |
1113 | 67 | self.header.set_subtitle('subtitle') | 74 | max_width = self.ui.max_subtitle_width |
1114 | 68 | self.assertEqual(self.header.subtitle_label.text(), 'subtitle') | 75 | text = build_string_for_pixels(self.ui.subtitle_label, max_width) |
1115 | 69 | self.header.show() | 76 | |
1116 | 70 | self.assertTrue(self.header.subtitle_label.isVisible()) | 77 | self.ui.set_subtitle(text) |
1117 | 71 | self.header.hide() | 78 | |
1118 | 79 | self.assert_subtitle_correct(self.ui.subtitle_label, text, max_width) | ||
1119 | 72 | 80 | ||
1120 | 73 | def test_set_elided_subtitle(self): | 81 | def test_set_elided_subtitle(self): |
1121 | 74 | """Check if set_subtitle adds the ellipsis when necessary.""" | 82 | """Check if set_subtitle adds the ellipsis when necessary.""" |
1127 | 75 | subtitle = 'a' * int(PREFERED_UI_SIZE['width'] * 0.95) + 'a' | 83 | max_width = self.ui.max_subtitle_width |
1128 | 76 | self.header.set_subtitle(subtitle) | 84 | text = build_string_for_pixels(self.ui.subtitle_label, max_width + 10) |
1129 | 77 | self.assertEqual(self.header.subtitle_label.toolTip(), subtitle) | 85 | |
1130 | 78 | expected = unicode(self.header.subtitle_label.text()) | 86 | self.ui.set_subtitle(text) |
1131 | 79 | self.assertTrue(expected.endswith(u'\u2026')) | 87 | |
1132 | 88 | self.assert_subtitle_correct(self.ui.subtitle_label, text, max_width) | ||
1133 | 80 | 89 | ||
1134 | 81 | def test_set_empty_subtitle(self): | 90 | def test_set_empty_subtitle(self): |
1135 | 82 | """Check if the widget is hidden for empty subtitle.""" | 91 | """Check if the widget is hidden for empty subtitle.""" |
1145 | 83 | self.header.set_title('') | 92 | self.ui.set_subtitle('') |
1146 | 84 | self.assertFalse(self.header.title_label.isVisible()) | 93 | |
1147 | 85 | 94 | self.assertEqual(self.ui.subtitle_label.toolTip(), '') | |
1148 | 86 | 95 | self.assertFalse(self.ui.subtitle_label.isVisible()) | |
1149 | 87 | class SSOWizardPageTest(PageBaseTestCase): | 96 | |
1150 | 88 | 97 | ||
1151 | 89 | """Tests for SSOWizardPage.""" | 98 | class BaseWizardPageTestCase(PageBaseTestCase): |
1152 | 90 | 99 | ||
1153 | 91 | ui_class = SetupAccountPage | 100 | """Tests for SSOWizardPage.""" |
1154 | 101 | |||
1155 | 102 | kwargs = {} | ||
1156 | 103 | ui_class = gui.BaseWizardPage | ||
1157 | 104 | |||
1158 | 105 | def test_max_width(self): | ||
1159 | 106 | """The max_width is correct.""" | ||
1160 | 107 | self.assertEqual(self.ui.max_width, 0) | ||
1161 | 108 | |||
1162 | 109 | |||
1163 | 110 | class SSOWizardPageTestCase(BaseWizardPageTestCase): | ||
1164 | 111 | |||
1165 | 112 | """Tests for SSOWizardPage.""" | ||
1166 | 113 | |||
1167 | 114 | kwargs = dict(app_name=APP_NAME) | ||
1168 | 115 | ui_class = gui.SSOWizardPage | ||
1169 | 116 | |||
1170 | 117 | def test_max_width(self): | ||
1171 | 118 | """The max_width is correct.""" | ||
1172 | 119 | self.assertEqual(self.ui.max_width, PREFERED_UI_SIZE['width']) | ||
1173 | 92 | 120 | ||
1174 | 93 | def test_show_error(self): | 121 | def test_show_error(self): |
1175 | 94 | """Test show_error with a normal length string.""" | 122 | """Test show_error with a normal length string.""" |
1176 | 95 | message = 'error-message' | 123 | message = 'error-message' |
1181 | 96 | self.ui.show_error(self.app_name, message) | 124 | self.ui.show_error(message) |
1182 | 97 | self.assertEqual(self.ui.form_errors_label.toolTip(), message) | 125 | |
1183 | 98 | expected = unicode(self.ui.form_errors_label.text()) | 126 | self.assert_error_correct(self.ui.form_errors_label, message, |
1184 | 99 | self.assertEqual(expected, message) | 127 | self.ui.header.max_title_width) |
1185 | 100 | 128 | ||
1186 | 101 | def test_show_error_long_text(self): | 129 | def test_show_error_long_text(self): |
1187 | 102 | """Test show_error with a long length string.""" | 130 | """Test show_error with a long length string.""" |
1193 | 103 | message = 'a' * int(PREFERED_UI_SIZE['width'] * 0.95) + 'a' | 131 | message = build_string_for_pixels(self.ui.form_errors_label, |
1194 | 104 | self.ui.show_error(self.app_name, message) | 132 | self.ui.header.max_title_width + 10) |
1195 | 105 | self.assertEqual(self.ui.form_errors_label.toolTip(), message) | 133 | self.ui.show_error(message) |
1196 | 106 | expected = unicode(self.ui.form_errors_label.text()) | 134 | |
1197 | 107 | self.assertTrue(expected.endswith(u'\u2026')) | 135 | self.assert_error_correct(self.ui.form_errors_label, message, |
1198 | 136 | self.ui.header.max_title_width) | ||
1199 | 108 | 137 | ||
1200 | 109 | def test_hide_error(self): | 138 | def test_hide_error(self): |
1201 | 110 | """Test show_error with a long length string.""" | 139 | """Test show_error with a long length string.""" |
1202 | 111 | message = ' ' | ||
1203 | 112 | self.ui.hide_error() | 140 | self.ui.hide_error() |
1205 | 113 | self.assertEqual(self.ui.form_errors_label.text(), message) | 141 | |
1206 | 142 | self.assertEqual(self.ui.form_errors_label.text(), ' ') | ||
1207 | 114 | 143 | ||
1208 | === modified file 'ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py' | |||
1209 | --- ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-03-13 20:33:06 +0000 | |||
1210 | +++ ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-03-14 13:30:25 +0000 | |||
1211 | @@ -112,8 +112,6 @@ | |||
1212 | 112 | 112 | ||
1213 | 113 | def test_window_size(self): | 113 | def test_window_size(self): |
1214 | 114 | """check the window size.""" | 114 | """check the window size.""" |
1215 | 115 | self.ui.show() | ||
1216 | 116 | self.addCleanup(self.ui.hide) | ||
1217 | 117 | size = self.ui.size() | 115 | size = self.ui.size() |
1218 | 118 | self.assertTrue(size.height() >= PREFERED_UI_SIZE['height']) | 116 | self.assertTrue(size.height() >= PREFERED_UI_SIZE['height']) |
1219 | 119 | self.assertTrue(size.width() >= PREFERED_UI_SIZE['width']) | 117 | self.assertTrue(size.width() >= PREFERED_UI_SIZE['width']) |
1220 | @@ -131,6 +129,9 @@ | |||
1221 | 131 | 129 | ||
1222 | 132 | def test_overlay_shows(self): | 130 | def test_overlay_shows(self): |
1223 | 133 | """Test if the signals call the overlay.show properly.""" | 131 | """Test if the signals call the overlay.show properly.""" |
1224 | 132 | # reset the counter | ||
1225 | 133 | self.ui.overlay.show_counter = 0 | ||
1226 | 134 | |||
1227 | 134 | for page in self.ui._pages: | 135 | for page in self.ui._pages: |
1228 | 135 | page.show_overlay() | 136 | page.show_overlay() |
1229 | 136 | 137 | ||
1230 | @@ -138,6 +139,9 @@ | |||
1231 | 138 | 139 | ||
1232 | 139 | def test_overlay_hides(self): | 140 | def test_overlay_hides(self): |
1233 | 140 | """Test if the signals call the overlay.show properly.""" | 141 | """Test if the signals call the overlay.show properly.""" |
1234 | 142 | # reset the counter | ||
1235 | 143 | self.ui.overlay.show_counter = 0 | ||
1236 | 144 | |||
1237 | 141 | for page in self.ui._pages: | 145 | for page in self.ui._pages: |
1238 | 142 | page.hide_overlay() | 146 | page.hide_overlay() |
1239 | 143 | 147 | ||
1240 | @@ -157,8 +161,6 @@ | |||
1241 | 157 | 161 | ||
1242 | 158 | def test_email_verification_page_params_from_current_user(self): | 162 | def test_email_verification_page_params_from_current_user(self): |
1243 | 159 | """Tests that email_verification_page receives the proper params.""" | 163 | """Tests that email_verification_page receives the proper params.""" |
1244 | 160 | self.ui.show() | ||
1245 | 161 | self.addCleanup(self.ui.hide) | ||
1246 | 162 | self.ui._next_id = self.ui.current_user_page_id | 164 | self.ui._next_id = self.ui.current_user_page_id |
1247 | 163 | self.ui.next() | 165 | self.ui.next() |
1248 | 164 | self.ui.current_user.ui.email_edit.setText(EMAIL) | 166 | self.ui.current_user.ui.email_edit.setText(EMAIL) |
1249 | @@ -169,8 +171,6 @@ | |||
1250 | 169 | 171 | ||
1251 | 170 | def test_email_verification_page_params_from_setup(self): | 172 | def test_email_verification_page_params_from_setup(self): |
1252 | 171 | """Tests that email_verification_page receives the proper params.""" | 173 | """Tests that email_verification_page receives the proper params.""" |
1253 | 172 | self.ui.show() | ||
1254 | 173 | self.addCleanup(self.ui.hide) | ||
1255 | 174 | self.ui.setup_account.ui.email_edit.setText(EMAIL) | 174 | self.ui.setup_account.ui.email_edit.setText(EMAIL) |
1256 | 175 | self.ui.setup_account.ui.password_edit.setText(PASSWORD) | 175 | self.ui.setup_account.ui.password_edit.setText(PASSWORD) |
1257 | 176 | self.ui.setup_account.on_user_registered(APP_NAME, {}) | 176 | self.ui.setup_account.on_user_registered(APP_NAME, {}) |
Text conflict in ubuntu_ sso/qt/ tests/test_ email_verificat ion.py
1 conflicts encountered.