Merge lp:~nataliabidart/ubuntu-sso-client/reusable-headers into lp:ubuntu-sso-client

Proposed by Natalia Bidart on 2012-03-13
Status: Merged
Approved by: Natalia Bidart on 2012-03-14
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
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) 2012-03-13 Approve on 2012-03-14
Roberto Alsina (community) Approve on 2012-03-14
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_error_msg.
- Improved code for the 'sign in' button validation.

To post a comment you must log in.
914. By Natalia Bidart on 2012-03-13

Fixed tests.

915. By Natalia Bidart on 2012-03-13

Fixed lint issues.

916. By Natalia Bidart on 2012-03-13

Pep8 fixes.

Diego Sarmentero (diegosarmentero) wrote :

Text conflict in ubuntu_sso/qt/tests/test_email_verification.py
1 conflicts encountered.

review: Needs Fixing
917. By Natalia Bidart on 2012-03-14

Merged trunk in.

918. By Natalia Bidart on 2012-03-14

- Added some minor logging to build_general_error_msg.

919. By Natalia Bidart on 2012-03-14

- 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 on 2012-03-14

Revert error hiding and fiule bug for it.

921. By Natalia Bidart on 2012-03-14

- Improved code for 'sign in' button validation.

Roberto Alsina (ralsina) wrote :

+1

review: Approve
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve

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

Subscribers

People subscribed via source and target branches