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

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
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_error_msg.
- Improved code for the 'sign in' button validation.

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.

Revision history for this message
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

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.

Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/qt/stylesheet.qss'
--- data/qt/stylesheet.qss 2012-03-05 20:30:57 +0000
+++ data/qt/stylesheet.qss 2012-03-14 13:30:25 +0000
@@ -95,17 +95,11 @@
95 font-size: 20px;95 font-size: 20px;
96}96}
9797
98QLabel#title_label {98WizardHeader {
99 font-size: 20px;
100}
101
102QFrame#header {
103 padding-top: 1px;99 padding-top: 1px;
104 padding-bottom: 1px;100 padding-bottom: 1px;
105}101}
106102
107QLabel#form_errors {103QLabel#form_errors {
108 font: bold 14px;
109 color: #df2d1f;
110 padding-bottom: 1px;104 padding-bottom: 1px;
111}105}
112106
=== modified file 'run-tests'
--- run-tests 2012-02-17 16:57:34 +0000
+++ run-tests 2012-03-14 13:30:25 +0000
@@ -57,7 +57,7 @@
5757
58echo "*** Running QT test suite for ""$MODULE"" ***"58echo "*** Running QT test suite for ""$MODULE"" ***"
59./setup.py build59./setup.py build
60USE_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"
61rm -rf _trial_temp61rm -rf _trial_temp
62rm -rf build62rm -rf build
6363
6464
=== modified file 'ubuntu_sso/qt/__init__.py'
--- ubuntu_sso/qt/__init__.py 2012-03-12 14:03:08 +0000
+++ ubuntu_sso/qt/__init__.py 2012-03-14 13:30:25 +0000
@@ -18,20 +18,26 @@
1818
19import collections19import collections
2020
21from PyQt4 import QtGui, QtCore
22
23from ubuntu_sso.logger import setup_gui_logging
24
25logger = setup_gui_logging('ubuntu_sso.qt')
2126
22LINK_STYLE = (u'<a href="{link_url}">'27LINK_STYLE = (u'<a href="{link_url}">'
23 '<span style="color:#df2d1f;">{link_text}</span></a>')28 '<span style="color:#df2d1f;">{link_text}</span></a>')
24ERROR_ALL = '__all__'29ERROR_ALL = '__all__'
25ERROR_STYLE = u'<font color="#df2d1f"><b>%s</b></font>'30ERROR_STYLE = u'<font color="#df2d1f" style="font-size:small"><b>%s</b></font>'
26ERROR_MESSAGE = 'message'31ERROR_MESSAGE = 'message'
27PREFERED_UI_SIZE = {'width': 550, 'height': 525}32PREFERED_UI_SIZE = {'width': 550, 'height': 525}
28TITLE_STYLE = u'<span style="font-size:24px">%s</span>'33TITLE_STYLE = u'<span style="font-size:xx-large">%s</span>'
29WINDOW_TITLE = 'Ubuntu Single Sign On'34WINDOW_TITLE = 'Ubuntu Single Sign On'
3035
3136
32# Based on the gtk implementation37# Based on the gtk implementation
33def build_general_error_message(errordict):38def build_general_error_message(errordict):
34 """Build a user-friendly error message from the errordict."""39 """Build a user-friendly error message from the errordict."""
40 logger.debug('build_general_error_message: errordict is: %r.', errordict)
35 result = ''41 result = ''
36 if isinstance(errordict, collections.Mapping):42 if isinstance(errordict, collections.Mapping):
37 msg1 = errordict.get(ERROR_ALL)43 msg1 = errordict.get(ERROR_ALL)
@@ -52,4 +58,22 @@
52 [('%s: %s' % (k, v)) for k, v in errordict.iteritems()])58 [('%s: %s' % (k, v)) for k, v in errordict.iteritems()])
53 else:59 else:
54 result = repr(errordict)60 result = repr(errordict)
61
62 logger.info('build_general_error_message: returning %r.', result)
55 return result63 return result
64
65
66def maybe_elide_text(label, text, width, markup=None):
67 """Set 'text' to be the 'label's text.
68
69 If 'text' is longer than 'width', set the label's tooltip to be the full
70 text, and the text itself to be the elided version of 'text'.
71
72 """
73 fm = QtGui.QFontMetrics(label.font())
74 elided_text = fm.elidedText(text, QtCore.Qt.ElideRight, width)
75 if elided_text != text:
76 label.setToolTip(text)
77 if markup is not None:
78 elided_text = markup % elided_text
79 label.setText(elided_text)
5680
=== modified file 'ubuntu_sso/qt/current_user_sign_in_page.py'
--- ubuntu_sso/qt/current_user_sign_in_page.py 2012-03-12 14:53:00 +0000
+++ ubuntu_sso/qt/current_user_sign_in_page.py 2012-03-14 13:30:25 +0000
@@ -119,12 +119,10 @@
119119
120 def _validate(self):120 def _validate(self):
121 """Perform input validation."""121 """Perform input validation."""
122 valid = True
123 correct_mail = is_correct_email(unicode(self.ui.email_edit.text()))122 correct_mail = is_correct_email(unicode(self.ui.email_edit.text()))
124 password = unicode(self.ui.password_edit.text())123 correct_password = len(unicode(self.ui.password_edit.text())) > 0
125 if not correct_mail or not password:124 enabled = correct_mail and correct_password
126 valid = False125 self.ui.sign_in_button.setEnabled(enabled)
127 self.ui.sign_in_button.setEnabled(valid)
128126
129 def login(self):127 def login(self):
130 """Perform the login using the self.backend."""128 """Perform the login using the self.backend."""
@@ -149,7 +147,7 @@
149 # let the user know147 # let the user know
150 logger.error('Got error when login %s, error: %s',148 logger.error('Got error when login %s, error: %s',
151 self.app_name, error)149 self.app_name, error)
152 self.show_error(self.app_name, build_general_error_message(error))150 self.show_error(build_general_error_message(error))
153151
154 def on_logged_in(self, app_name, result):152 def on_logged_in(self, app_name, result):
155 """We managed to log in."""153 """We managed to log in."""
156154
=== modified file 'ubuntu_sso/qt/email_verification_page.py'
--- ubuntu_sso/qt/email_verification_page.py 2012-03-09 17:27:30 +0000
+++ ubuntu_sso/qt/email_verification_page.py 2012-03-14 13:30:25 +0000
@@ -134,7 +134,7 @@
134 self.hide_overlay()134 self.hide_overlay()
135 msg = error.pop(ERROR_EMAIL_TOKEN, '')135 msg = error.pop(ERROR_EMAIL_TOKEN, '')
136 msg += build_general_error_message(error)136 msg += build_general_error_message(error)
137 self.show_error(self.app_name, msg)137 self.show_error(msg)
138138
139 # pylint: disable=C0103139 # pylint: disable=C0103
140140
141141
=== modified file 'ubuntu_sso/qt/forgotten_password_page.py'
--- ubuntu_sso/qt/forgotten_password_page.py 2012-03-09 17:27:30 +0000
+++ ubuntu_sso/qt/forgotten_password_page.py 2012-03-14 13:30:25 +0000
@@ -127,4 +127,4 @@
127 # set the error message127 # set the error message
128 self.hide_overlay()128 self.hide_overlay()
129 msg = REQUEST_PASSWORD_TOKEN_WRONG_EMAIL129 msg = REQUEST_PASSWORD_TOKEN_WRONG_EMAIL
130 self.show_error(self.app_name, msg)130 self.show_error(msg)
131131
=== modified file 'ubuntu_sso/qt/reset_password_page.py'
--- ubuntu_sso/qt/reset_password_page.py 2012-03-09 17:27:30 +0000
+++ ubuntu_sso/qt/reset_password_page.py 2012-03-14 13:30:25 +0000
@@ -169,7 +169,7 @@
169 """Let the user know that there was an error."""169 """Let the user know that there was an error."""
170 logger.error('Got error changing password for %s, error: %s',170 logger.error('Got error changing password for %s, error: %s',
171 self.app_name, error)171 self.app_name, error)
172 self.show_error(self.app_name, build_general_error_message(error))172 self.show_error(build_general_error_message(error))
173173
174 def set_new_password(self):174 def set_new_password(self):
175 """Request a new password to be set."""175 """Request a new password to be set."""
176176
=== modified file 'ubuntu_sso/qt/setup_account_page.py'
--- ubuntu_sso/qt/setup_account_page.py 2012-03-13 20:33:06 +0000
+++ ubuntu_sso/qt/setup_account_page.py 2012-03-14 13:30:25 +0000
@@ -322,10 +322,10 @@
322 self.captcha_image = pixmap_image322 self.captcha_image = pixmap_image
323 self.on_captcha_refresh_complete()323 self.on_captcha_refresh_complete()
324324
325 def on_captcha_generation_error(self, error, *args, **kwargs):325 @log_call(logger.error)
326 def on_captcha_generation_error(self, app_name, error):
326 """An error ocurred."""327 """An error ocurred."""
327 logger.error('Got error on captcha generation: %s', error)328 self.show_error(CAPTCHA_LOAD_ERROR)
328 self.show_error(self.app_name, CAPTCHA_LOAD_ERROR)
329 self.on_captcha_refresh_complete()329 self.on_captcha_refresh_complete()
330330
331 @log_call(logger.error)331 @log_call(logger.error)
@@ -337,7 +337,7 @@
337 self.set_error_message(self.ui.email_assistance, msg)337 self.set_error_message(self.ui.email_assistance, msg)
338 error_msg = build_general_error_message(error)338 error_msg = build_general_error_message(error)
339 if error_msg:339 if error_msg:
340 self.show_error(self.app_name, error_msg)340 self.show_error(error_msg)
341 self._refresh_captcha()341 self._refresh_captcha()
342342
343 @log_call(logger.info)343 @log_call(logger.info)
@@ -378,7 +378,7 @@
378 messages.append(CAPTCHA_REQUIRED_ERROR)378 messages.append(CAPTCHA_REQUIRED_ERROR)
379 if len(messages) > 0:379 if len(messages) > 0:
380 condition = False380 condition = False
381 self.show_error(self.app_name, '\n'.join(messages))381 self.show_error('\n'.join(messages))
382 return condition382 return condition
383383
384 def set_next_validation(self):384 def set_next_validation(self):
385385
=== modified file 'ubuntu_sso/qt/sso_wizard_page.py'
--- ubuntu_sso/qt/sso_wizard_page.py 2012-03-12 14:53:00 +0000
+++ ubuntu_sso/qt/sso_wizard_page.py 2012-03-14 13:30:25 +0000
@@ -23,31 +23,38 @@
23 QApplication,23 QApplication,
24 QCursor,24 QCursor,
25 QFrame,25 QFrame,
26 QFontMetrics,
27 QHBoxLayout,26 QHBoxLayout,
27 QLabel,
28 QStyle,
28 QVBoxLayout,29 QVBoxLayout,
29 QStyle,
30 QWizardPage,30 QWizardPage,
31 QLabel,
32)31)
33from twisted.internet import defer32from twisted.internet import defer
3433
35from ubuntu_sso import main34from ubuntu_sso import main
36from ubuntu_sso.logger import setup_gui_logging, log_call35from ubuntu_sso.logger import setup_gui_logging, log_call
37from ubuntu_sso.qt import PREFERED_UI_SIZE, TITLE_STYLE36from ubuntu_sso.qt import (
37 ERROR_STYLE,
38 maybe_elide_text,
39 PREFERED_UI_SIZE,
40 TITLE_STYLE,
41)
38from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR42from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR
3943
4044
41logger = setup_gui_logging('ubuntu_sso.sso_wizard_page')45logger = setup_gui_logging('ubuntu_sso.sso_wizard_page')
4246
4347
44class Header(QFrame):48class WizardHeader(QFrame):
45 """Header Class for Title and Subtitle in all wizard pages."""49 """WizardHeader Class for Title and Subtitle in all wizard pages."""
4650
47 def __init__(self):51 def __init__(self, max_width, parent=None):
48 """Create a new instance."""52 """Create a new instance."""
49 super(Header, self).__init__()53 super(WizardHeader, self).__init__(parent=parent)
50 self.setObjectName('header')54 self.max_width = max_width
55 self.max_title_width = self.max_width * 0.95
56 self.max_subtitle_width = self.max_width * 1.8
57
51 vbox = QVBoxLayout(self)58 vbox = QVBoxLayout(self)
52 vbox.setContentsMargins(0, 0, 0, 0)59 vbox.setContentsMargins(0, 0, 0, 0)
53 self.title_label = QLabel()60 self.title_label = QLabel()
@@ -64,11 +71,8 @@
64 def set_title(self, title):71 def set_title(self, title):
65 """Set the Title of the page or hide it otherwise"""72 """Set the Title of the page or hide it otherwise"""
66 if title:73 if title:
67 fm = QFontMetrics(self.subtitle_label.font())74 maybe_elide_text(self.title_label, title, self.max_title_width,
68 width = PREFERED_UI_SIZE['width'] * 0.9575 markup=TITLE_STYLE)
69 elided_text = fm.elidedText(title, Qt.ElideRight, width)
70 self.title_label.setToolTip(title)
71 self.title_label.setText(elided_text)
72 self.title_label.setVisible(True)76 self.title_label.setVisible(True)
73 else:77 else:
74 self.title_label.setVisible(False)78 self.title_label.setVisible(False)
@@ -76,28 +80,23 @@
76 def set_subtitle(self, subtitle):80 def set_subtitle(self, subtitle):
77 """Set the Subtitle of the page or hide it otherwise"""81 """Set the Subtitle of the page or hide it otherwise"""
78 if subtitle:82 if subtitle:
79 fm = QFontMetrics(self.subtitle_label.font())83 maybe_elide_text(self.subtitle_label, subtitle,
80 width = PREFERED_UI_SIZE['width'] * 1.884 self.max_subtitle_width)
81 elided_text = fm.elidedText(subtitle, Qt.ElideRight, width)
82 self.subtitle_label.setText(elided_text)
83 self.subtitle_label.setToolTip(subtitle)
84 self.subtitle_label.setVisible(True)85 self.subtitle_label.setVisible(True)
85 else:86 else:
86 self.subtitle_label.setVisible(False)87 self.subtitle_label.setVisible(False)
8788
8889
89class SSOWizardPage(QWizardPage):90class BaseWizardPage(QWizardPage):
90 """Root class for all wizard pages."""91 """Base class for all wizard pages."""
9192
92 ui_class = None93 ui_class = None
93 _signals = {} # override in children94 max_width = 0
94 processingStarted = pyqtSignal()95 processingStarted = pyqtSignal()
95 processingFinished = pyqtSignal()96 processingFinished = pyqtSignal()
9697
97 def __init__(self, app_name, **kwargs):98 def __init__(self, parent=None):
98 """Create a new instance."""99 super(BaseWizardPage, self).__init__(parent=parent)
99 parent = kwargs.pop('parent', None)
100 super(SSOWizardPage, self).__init__(parent=parent)
101100
102 self.ui = None101 self.ui = None
103 if self.ui_class is not None:102 if self.ui_class is not None:
@@ -105,55 +104,108 @@
105 self.ui = self.ui_class()104 self.ui = self.ui_class()
106 self.ui.setupUi(self)105 self.ui.setupUi(self)
107106
108 # store common useful data provided by the app107 if self.layout() is None:
109 self.app_name = app_name108 self.setLayout(QVBoxLayout(self))
110 self.ping_url = kwargs.get('ping_url', '')
111 self.tc_url = kwargs.get('tc_url', '')
112 self.policy_url = kwargs.get('policy_url', '')
113 self.help_text = kwargs.get('help_text', '')
114109
115 # Set the error area110 # Set the error area
116 self.form_errors_label = QLabel(' ')111 self.form_errors_label = QLabel()
117 self.form_errors_label.setObjectName('form_errors')112 self.form_errors_label.setObjectName('form_errors')
118 self.form_errors_label.setAlignment(Qt.AlignBottom)113 self.form_errors_label.setAlignment(Qt.AlignBottom)
119 self.layout().insertWidget(0, self.form_errors_label)114 self.layout().insertWidget(0, self.form_errors_label)
115
120 # Set the header116 # Set the header
121 self.header = Header()117 self.header = WizardHeader(max_width=self.max_width)
122 self.header.set_title(title='')118 self.header.set_title(title='')
123 self.header.set_subtitle(subtitle='')119 self.header.set_subtitle(subtitle='')
124 self.layout().insertWidget(0, self.header)120 self.layout().insertWidget(0, self.header)
125 self._signals_receivers = {}
126 self.backend = None
127121
128 self.layout().setAlignment(Qt.AlignLeft)122 self.layout().setAlignment(Qt.AlignLeft)
129123
130 self.setup_page()124 self._is_processing = False
125
126 def _get_is_processing(self):
127 """Is this widget processing any request?"""
128 return self._is_processing
129
130 def _set_is_processing(self, new_value):
131 """Set this widget to be processing a request."""
132 self._is_processing = new_value
133 self.setEnabled(not new_value)
134 if not self._is_processing:
135 self.processingFinished.emit()
136 else:
137 self.processingStarted.emit()
138
139 is_processing = property(fget=_get_is_processing, fset=_set_is_processing)
140
141 # pylint: disable=C0103
142
143 def cleanupPage(self):
144 """Hide the errors."""
145 self.hide_error()
146
147 def setTitle(self, title=''):
148 """Set the Wizard Page Title."""
149 self.header.set_title(title)
150
151 def setSubTitle(self, subtitle=''):
152 """Set the Wizard Page Subtitle."""
153 self.header.set_subtitle(subtitle)
154
155 def title(self):
156 """Return the header's title."""
157 return self.header.title_label.text()
158
159 def subTitle(self):
160 """Return the header's subtitle."""
161 return self.header.subtitle_label.text()
162
163 # pylint: enable=C0103
131164
132 @log_call(logger.error)165 @log_call(logger.error)
133 def show_error(self, app_name, message):166 def show_error(self, message):
134 """Show an error message inside the page."""167 """Show an error message inside the page."""
135 self.hide_overlay()168 self.is_processing = False
136 fm = QFontMetrics(self.form_errors_label.font())169 maybe_elide_text(self.form_errors_label, message,
137 width = PREFERED_UI_SIZE['width'] * 0.95170 self.max_width * 0.95, markup=ERROR_STYLE)
138 elided_text = fm.elidedText(message, Qt.ElideRight, width)
139 self.form_errors_label.setText(elided_text)
140 self.form_errors_label.setToolTip(message)
141171
142 def hide_error(self):172 def hide_error(self):
143 """Hide the label errors in the current page."""173 """Hide the label errors in the current page."""
144 # We actually want the label with one chat, because if it is an174 # We actually want the label with one empty char, because if it is an
145 # empty string, the height of the label is 0175 # empty string, the height of the label is 0
146 self.form_errors_label.setText(' ')176 self.form_errors_label.setText(' ')
147177
178
179class SSOWizardPage(BaseWizardPage):
180 """Root class for all SSO specific wizard pages."""
181
182 _signals = {} # override in children
183 max_width = PREFERED_UI_SIZE['width']
184
185 def __init__(self, app_name, **kwargs):
186 """Create a new instance."""
187 parent = kwargs.pop('parent', None)
188 super(SSOWizardPage, self).__init__(parent=parent)
189
190 # store common useful data provided by the app
191 self.app_name = app_name
192 self.ping_url = kwargs.get('ping_url', '')
193 self.tc_url = kwargs.get('tc_url', '')
194 self.policy_url = kwargs.get('policy_url', '')
195 self.help_text = kwargs.get('help_text', '')
196
197 self._signals_receivers = {}
198 self.backend = None
199
200 self.setup_page()
201
148 def hide_overlay(self):202 def hide_overlay(self):
149 """Emit the signal to notify the upper container that ends loading."""203 """Emit the signal to notify the upper container that ends loading."""
150 self.setEnabled(True)204 self.is_processing = False
151 self.processingFinished.emit()
152205
153 def show_overlay(self):206 def show_overlay(self):
154 """Emit the signal to notify the upper container that is loading."""207 """Emit the signal to notify the upper container that is loading."""
155 self.setEnabled(False)208 self.is_processing = True
156 self.processingStarted.emit()
157209
158 @defer.inlineCallbacks210 @defer.inlineCallbacks
159 def setup_page(self):211 def setup_page(self):
@@ -165,30 +217,6 @@
165 self._set_translated_strings()217 self._set_translated_strings()
166 self._connect_ui()218 self._connect_ui()
167219
168 # pylint: disable=C0103
169
170 def cleanupPage(self):
171 """Hide the errors."""
172 self.hide_error()
173
174 def setTitle(self, title=''):
175 """Set the Wizard Page Title."""
176 self.header.set_title(TITLE_STYLE % title)
177
178 def setSubTitle(self, subtitle=''):
179 """Set the Wizard Page Subtitle."""
180 self.header.set_subtitle(subtitle)
181
182 def title(self):
183 """Return the header's title."""
184 return self.header.title_label.text()
185
186 def subTitle(self):
187 """Return the header's subtitle."""
188 return self.header.subtitle_label.text()
189
190 # pylint: enable=C0103
191
192 def _filter_by_app_name(self, f):220 def _filter_by_app_name(self, f):
193 """Excecute the decorated function only for 'self.app_name'."""221 """Excecute the decorated function only for 'self.app_name'."""
194222
@@ -219,11 +247,9 @@
219247
220 def _set_translated_strings(self):248 def _set_translated_strings(self):
221 """Implement in each child."""249 """Implement in each child."""
222 raise NotImplementedError()
223250
224 def _connect_ui(self):251 def _connect_ui(self):
225 """Implement in each child."""252 """Implement in each child."""
226 raise NotImplementedError()
227253
228 def _handle_error(self, remote_call, handler, error):254 def _handle_error(self, remote_call, handler, error):
229 """Handle any error when calling the remote backend."""255 """Handle any error when calling the remote backend."""
230256
=== modified file 'ubuntu_sso/qt/tests/__init__.py'
--- ubuntu_sso/qt/tests/__init__.py 2012-03-05 21:18:15 +0000
+++ ubuntu_sso/qt/tests/__init__.py 2012-03-14 13:30:25 +0000
@@ -21,7 +21,7 @@
21from twisted.trial.unittest import TestCase21from twisted.trial.unittest import TestCase
2222
23from ubuntu_sso import main, NO_OP23from ubuntu_sso import main, NO_OP
24from ubuntu_sso.qt import TITLE_STYLE24from ubuntu_sso.qt import ERROR_STYLE, maybe_elide_text, TITLE_STYLE
25from ubuntu_sso.tests import (25from ubuntu_sso.tests import (
26 APP_NAME,26 APP_NAME,
27 HELP_TEXT,27 HELP_TEXT,
@@ -38,6 +38,15 @@
38# pylint: disable=W021238# pylint: disable=W0212
3939
4040
41def build_string_for_pixels(label, width):
42 """Return a random string that will be as big as with in pixels."""
43 char = 'a'
44 fm = QtGui.QFontMetrics(label.font())
45 pixel_width = fm.width(char)
46 chars = int(width / pixel_width)
47 return char * chars
48
49
41class FakedObject(object):50class FakedObject(object):
42 """Fake an object, record every call."""51 """Fake an object, record every call."""
4352
@@ -439,6 +448,9 @@
439 self.wizard = self.ui_wizard_class()448 self.wizard = self.ui_wizard_class()
440 self.patch(self.ui, 'wizard', lambda: self.wizard)449 self.patch(self.ui, 'wizard', lambda: self.wizard)
441450
451 self.ui.show()
452 self.addCleanup(self.ui.hide)
453
442 def _set_called(self, *args, **kwargs):454 def _set_called(self, *args, **kwargs):
443 """Store 'args' and 'kwargs' for test assertions."""455 """Store 'args' and 'kwargs' for test assertions."""
444 self._called = (args, kwargs)456 self._called = (args, kwargs)
@@ -467,6 +479,38 @@
467479
468 self.assertEqual(self.signal_results, [signal_args])480 self.assertEqual(self.signal_results, [signal_args])
469481
482 def assert_title_correct(self, title_label, expected, max_width):
483 """Check that the label's text is equal to 'expected'."""
484 label = QtGui.QLabel()
485 maybe_elide_text(label, expected, max_width)
486
487 self.assertEqual(TITLE_STYLE % unicode(label.text()),
488 unicode(title_label.text()))
489 self.assertEqual(unicode(label.toolTip()),
490 unicode(title_label.toolTip()))
491 self.assertTrue(title_label.isVisible())
492
493 def assert_subtitle_correct(self, subtitle_label, expected, max_width):
494 """Check that the subtitle is equal to 'expected'."""
495 label = QtGui.QLabel()
496 maybe_elide_text(label, expected, max_width)
497
498 self.assertEqual(unicode(label.text()), unicode(subtitle_label.text()))
499 self.assertEqual(unicode(label.toolTip()),
500 unicode(subtitle_label.toolTip()))
501 self.assertTrue(subtitle_label.isVisible())
502
503 def assert_error_correct(self, error_label, expected, max_width):
504 """Check that the error 'error_label' displays 'expected' as text."""
505 label = QtGui.QLabel()
506 maybe_elide_text(label, expected, max_width)
507
508 self.assertEqual(ERROR_STYLE % unicode(label.text()),
509 unicode(error_label.text()))
510 self.assertEqual(unicode(label.toolTip()),
511 unicode(error_label.toolTip()))
512 self.assertTrue(error_label.isVisible())
513
470 def get_pixmap_data(self, pixmap):514 def get_pixmap_data(self, pixmap):
471 """Get the raw data of a QPixmap."""515 """Get the raw data of a QPixmap."""
472 byte_array = QtCore.QByteArray()516 byte_array = QtCore.QByteArray()
@@ -550,14 +594,18 @@
550 self.assertEqual(self._overlay_hide_counter, 1)594 self.assertEqual(self._overlay_hide_counter, 1)
551 self.assertTrue(self.ui.isEnabled())595 self.assertTrue(self.ui.isEnabled())
552596
597 # pylint: disable=W0221
598
553 def assert_title_correct(self, expected):599 def assert_title_correct(self, expected):
554 """Check that the title is equal to 'expected'."""600 """Check that the title is equal to 'expected'."""
555 self.assertEqual(TITLE_STYLE % expected, unicode(self.ui.title()))601 check = super(PageBaseTestCase, self).assert_title_correct
602 check(self.ui.header.title_label, expected,
603 self.ui.header.max_title_width)
556604
557 def assert_subtitle_correct(self, expected):605 def assert_subtitle_correct(self, expected):
558 """Check that the subtitle is equal to 'expected'."""606 """Check that the subtitle is equal to 'expected'."""
559 elided_text = unicode(self.ui.subTitle())607 check = super(PageBaseTestCase, self).assert_subtitle_correct
560 elided_text = elided_text[:len(elided_text) - 1]608 check(self.ui.header.subtitle_label, expected,
609 self.ui.header.max_subtitle_width)
561610
562 self.assertTrue(expected.startswith(elided_text))611 # pylint: enable=W0221
563 self.assertEqual(self.ui.header.subtitle_label.toolTip(), expected)
564612
=== modified file 'ubuntu_sso/qt/tests/test_common.py'
--- ubuntu_sso/qt/tests/test_common.py 2011-10-28 10:41:18 +0000
+++ ubuntu_sso/qt/tests/test_common.py 2012-03-14 13:30:25 +0000
@@ -20,7 +20,9 @@
20from twisted.internet import defer20from twisted.internet import defer
21from twisted.trial.unittest import TestCase21from twisted.trial.unittest import TestCase
2222
23from ubuntu_sso.qt.common import (check_as_invalid,23from ubuntu_sso.qt import maybe_elide_text
24from ubuntu_sso.qt.common import (
25 check_as_invalid,
24 check_as_valid,26 check_as_valid,
25 password_assistance,27 password_assistance,
26 password_check_match,28 password_check_match,
@@ -30,7 +32,9 @@
30 PASSWORD_DIGIT,32 PASSWORD_DIGIT,
31 PASSWORD_LENGTH,33 PASSWORD_LENGTH,
32 PASSWORD_MATCH,34 PASSWORD_MATCH,
33 PASSWORD_UPPER)35 PASSWORD_UPPER,
36)
37from ubuntu_sso.qt.tests import build_string_for_pixels
3438
3539
36class PasswordTestCase(TestCase):40class PasswordTestCase(TestCase):
@@ -234,3 +238,46 @@
234 line_edit = QtGui.QLineEdit()238 line_edit = QtGui.QLineEdit()
235 check_as_invalid(line_edit)239 check_as_invalid(line_edit)
236 self.assertTrue(line_edit.property("formError").toBool())240 self.assertTrue(line_edit.property("formError").toBool())
241
242
243class ElidedTextTestCase(TestCase):
244 """The test case for the maybe_elide_text function."""
245
246 max_width = 100
247
248 @defer.inlineCallbacks
249 def setUp(self):
250 """Setup tests."""
251 yield super(ElidedTextTestCase, self).setUp()
252 self.ui = QtGui.QLabel()
253
254 def test_text_not_elided_if_too_short(self):
255 """If text is shorter than max_width, do not elide."""
256 text = build_string_for_pixels(self.ui, self.max_width - 1)
257
258 maybe_elide_text(self.ui, text, self.max_width)
259
260 self.assertEqual(self.ui.toolTip(), '')
261 self.assertEqual(self.ui.text(), text)
262 self.assertNotIn(u'\u2026', self.ui.text())
263
264 def test_text_not_elided_if_equals_max_width(self):
265 """If text is equal than max_width, do not elide."""
266 text = build_string_for_pixels(self.ui, self.max_width)
267
268 maybe_elide_text(self.ui, text, self.max_width)
269
270 self.assertEqual(self.ui.toolTip(), '')
271 self.assertEqual(self.ui.text(), text)
272 self.assertNotIn(u'\u2026', self.ui.text())
273
274 def test_text_elided_if_bigger_than_max_width(self):
275 """If text is equal than max_width, do not elide."""
276 text = build_string_for_pixels(self.ui, self.max_width + 10)
277
278 maybe_elide_text(self.ui, text, self.max_width)
279
280 self.assertEqual(self.ui.toolTip(), text)
281 expected = unicode(self.ui.text())
282 self.assertTrue(expected.endswith(u'\u2026'))
283 self.assertTrue(text.startswith(expected[:-1]))
237284
=== modified file 'ubuntu_sso/qt/tests/test_current_user_sign_in_page.py'
--- ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-03-12 19:47:07 +0000
+++ ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-03-14 13:30:25 +0000
@@ -142,13 +142,13 @@
142 def test_on_login_error(self):142 def test_on_login_error(self):
143 """Test the on_login_error method."""143 """Test the on_login_error method."""
144 self.patch(self.ui, "show_error", self._set_called)144 self.patch(self.ui, "show_error", self._set_called)
145 app_name = 'my_app'
146 self.ui.app_name = app_name
147 error = {'errtype': 'UserNotValidated'}145 error = {'errtype': 'UserNotValidated'}
148 self.ui.on_login_error(app_name, error)146
147 self.ui.on_login_error(self.app_name, error)
148
149 self.assertEqual(self._overlay_hide_counter, 0)149 self.assertEqual(self._overlay_hide_counter, 0)
150 self.assertTrue(self.ui.isEnabled())150 self.assertTrue(self.ui.isEnabled())
151 expected = ((self.ui, 'my_app', ''), {})151 expected = ((self.ui, self.app_name, ''), {})
152 self.assertTrue(expected, self._called)152 self.assertTrue(expected, self._called)
153153
154 def test_on_logged_in(self):154 def test_on_logged_in(self):
155155
=== modified file 'ubuntu_sso/qt/tests/test_email_verification.py'
--- ubuntu_sso/qt/tests/test_email_verification.py 2012-03-12 19:47:07 +0000
+++ ubuntu_sso/qt/tests/test_email_verification.py 2012-03-14 13:30:25 +0000
@@ -78,14 +78,12 @@
78 email = 'mail@example'78 email = 'mail@example'
79 self.ui.email = email79 self.ui.email = email
80 self.ui.set_titles(email)80 self.ui.set_titles(email)
81 self.assertEqual(unicode(self.ui.header.title_label.text()),81 self.assert_title_correct(email_verification_page.VERIFY_EMAIL_TITLE)
82 email_verification_page.VERIFY_EMAIL_TITLE)
83 expected = email_verification_page.VERIFY_EMAIL_CONTENT % {82 expected = email_verification_page.VERIFY_EMAIL_CONTENT % {
84 "app_name": self.app_name,83 "app_name": self.app_name,
85 "email": email,84 "email": email,
86 }85 }
87 self.assertEqual(unicode(self.ui.header.subtitle_label.toolTip()),86 self.assert_subtitle_correct(expected)
88 expected)
8987
90 def test_initialize_page(self):88 def test_initialize_page(self):
91 """Test the initialization method."""89 """Test the initialization method."""
@@ -100,10 +98,11 @@
100 def test_on_email_validation_error(self):98 def test_on_email_validation_error(self):
101 """Test the validate_email method."""99 """Test the validate_email method."""
102 self.patch(self.ui, "show_error", self._set_called)100 self.patch(self.ui, "show_error", self._set_called)
103 app_name = 'my_app'
104 error = {email_verification_page: 'error in email_verification_page'}101 error = {email_verification_page: 'error in email_verification_page'}
105 self.ui.on_email_validation_error(app_name, error)102
106 expected = ((self.ui, app_name, ''), {})103 self.ui.on_email_validation_error(self.app_name, error)
104
105 expected = ((self.ui, ''), {})
107 self.assertTrue(expected, self._called)106 self.assertTrue(expected, self._called)
108 self.assertEqual(self._overlay_hide_counter, 1)107 self.assertEqual(self._overlay_hide_counter, 1)
109108
110109
=== modified file 'ubuntu_sso/qt/tests/test_forgotten_password.py'
--- ubuntu_sso/qt/tests/test_forgotten_password.py 2012-03-12 19:47:07 +0000
+++ ubuntu_sso/qt/tests/test_forgotten_password.py 2012-03-14 13:30:25 +0000
@@ -113,7 +113,8 @@
113 """Test on_password_reset_error method."""113 """Test on_password_reset_error method."""
114 self.patch(self.ui, "show_error", self._set_called)114 self.patch(self.ui, "show_error", self._set_called)
115 error = {'errtype': 'FooBarBaz'}115 error = {'errtype': 'FooBarBaz'}
116
116 self.ui.on_password_reset_error(self.app_name, error)117 self.ui.on_password_reset_error(self.app_name, error)
117 expected = ((self.ui, self.app_name,118
118 gui.REQUEST_PASSWORD_TOKEN_WRONG_EMAIL), {})119 expected = ((self.ui, gui.REQUEST_PASSWORD_TOKEN_WRONG_EMAIL), {})
119 self.assertTrue(expected, self._called)120 self.assertTrue(expected, self._called)
120121
=== modified file 'ubuntu_sso/qt/tests/test_loadingoverlay.py'
--- ubuntu_sso/qt/tests/test_loadingoverlay.py 2012-02-23 19:49:02 +0000
+++ ubuntu_sso/qt/tests/test_loadingoverlay.py 2012-03-14 13:30:25 +0000
@@ -29,8 +29,5 @@
2929
30 def test_status_correct(self):30 def test_status_correct(self):
31 """Test if the necessary variables for the animation exists"""31 """Test if the necessary variables for the animation exists"""
32 self.ui.show()
33 self.addCleanup(self.ui.hide)
34
35 self.assertTrue(self.ui.counter is not None)32 self.assertTrue(self.ui.counter is not None)
36 self.assertTrue(self.ui.orientation is not None)33 self.assertTrue(self.ui.orientation is not None)
3734
=== modified file 'ubuntu_sso/qt/tests/test_reset_password.py'
--- ubuntu_sso/qt/tests/test_reset_password.py 2012-03-12 19:47:07 +0000
+++ ubuntu_sso/qt/tests/test_reset_password.py 2012-03-14 13:30:25 +0000
@@ -70,9 +70,7 @@
7070
71 def test_initialize(self):71 def test_initialize(self):
72 """Check the Title and Subtitle."""72 """Check the Title and Subtitle."""
73 self.ui.show()
74 self.ui.initializePage()73 self.ui.initializePage()
75 self.addCleanup(self.ui.hide)
76 self.assert_title_correct(RESET_TITLE)74 self.assert_title_correct(RESET_TITLE)
77 self.assert_subtitle_correct(RESET_SUBTITLE)75 self.assert_subtitle_correct(RESET_SUBTITLE)
78 self.assertEqual(unicode(self.ui.ui.password_label.text()),76 self.assertEqual(unicode(self.ui.ui.password_label.text()),
@@ -84,15 +82,11 @@
8482
85 def test_focus_changed_password_visibility(self):83 def test_focus_changed_password_visibility(self):
86 """Check visibility changes when focus_changed() is executed."""84 """Check visibility changes when focus_changed() is executed."""
87 self.ui.show()
88 self.addCleanup(self.ui.hide)
89 self.ui.focus_changed(None, self.ui.ui.password_line_edit)85 self.ui.focus_changed(None, self.ui.ui.password_line_edit)
90 self.assertTrue(self.ui.ui.password_assistance.isVisible())86 self.assertTrue(self.ui.ui.password_assistance.isVisible())
9187
92 def test_show_hide_event(self):88 def test_show_hide_event(self):
93 """Check connections to focusChanged on show and hide event."""89 """Check connections to focusChanged on show and hide event."""
94 self.ui.show()
95 self.addCleanup(self.ui.hide)
96 self.assertEqual(QtGui.QApplication.instance().receivers(90 self.assertEqual(QtGui.QApplication.instance().receivers(
97 QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 1)91 QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 1)
98 self.ui.hide()92 self.ui.hide()
@@ -104,24 +98,20 @@
104 def test_focus_changed_1(self):98 def test_focus_changed_1(self):
105 """Check functions execution when focus_changed() is executed."""99 """Check functions execution when focus_changed() is executed."""
106 self.patch(common, 'password_default_assistance', self._set_called)100 self.patch(common, 'password_default_assistance', self._set_called)
107
108 self.ui.show()
109 self.addCleanup(self.ui.hide)
110
111 self.assertFalse(self._called)101 self.assertFalse(self._called)
102
112 self.ui.focus_changed(None, self.ui.ui.password_line_edit)103 self.ui.focus_changed(None, self.ui.ui.password_line_edit)
104
113 self.assertTrue(self.ui.ui.password_assistance.isVisible())105 self.assertTrue(self.ui.ui.password_assistance.isVisible())
114 self.assertTrue(self._called)106 self.assertTrue(self._called)
115107
116 def test_focus_changed_2(self):108 def test_focus_changed_2(self):
117 """Check functions execution when focus_changed() is executed."""109 """Check functions execution when focus_changed() is executed."""
118 self.patch(common, 'password_check_match', self._set_called)110 self.patch(common, 'password_check_match', self._set_called)
119
120 self.ui.show()
121 self.addCleanup(self.ui.hide)
122
123 self.assertFalse(self._called)111 self.assertFalse(self._called)
112
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)
114
125 self.assertTrue(self.ui.ui.password_assistance.isVisible())115 self.assertTrue(self.ui.ui.password_assistance.isVisible())
126 self.assertTrue(self._called)116 self.assertTrue(self._called)
127117
128118
=== modified file 'ubuntu_sso/qt/tests/test_setup_account.py'
--- ubuntu_sso/qt/tests/test_setup_account.py 2012-03-12 19:47:07 +0000
+++ ubuntu_sso/qt/tests/test_setup_account.py 2012-03-14 13:30:25 +0000
@@ -43,13 +43,9 @@
43 """43 """
44 self.ui.ui.name_edit.setText("")44 self.ui.ui.name_edit.setText("")
45 self.ui.name_assistance()45 self.ui.name_assistance()
46 self.ui.show()
47 self.addCleanup(self.ui.hide)
48 self.assertTrue(self.ui.ui.name_assistance.isVisible())46 self.assertTrue(self.ui.ui.name_assistance.isVisible())
49 self.assertEqual(47 self.assert_error_correct(self.ui.ui.name_assistance, gui.EMPTY_NAME,
50 unicode(self.ui.ui.name_assistance.text()),48 max_width=self.ui.header.max_title_width)
51 gui.ERROR_STYLE % gui.EMPTY_NAME)
52 self.ui.hide()
5349
54 def test_enable_setup_button_with_visible_check(self):50 def test_enable_setup_button_with_visible_check(self):
55 """Test _enable_setup_button method with terms check visible."""51 """Test _enable_setup_button method with terms check visible."""
@@ -65,8 +61,6 @@
65 self.ui.ui.captcha_solution_edit.setText('captcha solution')61 self.ui.ui.captcha_solution_edit.setText('captcha solution')
66 self.ui.terms_checkbox.setChecked(True)62 self.ui.terms_checkbox.setChecked(True)
6763
68 self.ui.show()
69 self.addCleanup(self.ui.hide)
70 self.ui.terms_checkbox.setVisible(True)64 self.ui.terms_checkbox.setVisible(True)
71 self.ui.ui.captcha_solution_edit.textEdited.emit('')65 self.ui.ui.captcha_solution_edit.textEdited.emit('')
72 self.assertTrue(self.ui.set_up_button.isEnabled())66 self.assertTrue(self.ui.set_up_button.isEnabled())
@@ -84,8 +78,6 @@
84 self.ui.ui.confirm_password_edit.setText(password)78 self.ui.ui.confirm_password_edit.setText(password)
85 self.ui.ui.captcha_solution_edit.setText('captcha solution')79 self.ui.ui.captcha_solution_edit.setText('captcha solution')
8680
87 self.ui.show()
88 self.addCleanup(self.ui.hide)
89 self.ui.terms_checkbox.setVisible(False)81 self.ui.terms_checkbox.setVisible(False)
90 self.ui.ui.captcha_solution_edit.textEdited.emit('')82 self.ui.ui.captcha_solution_edit.textEdited.emit('')
91 self.assertTrue(self.ui.set_up_button.isEnabled())83 self.assertTrue(self.ui.set_up_button.isEnabled())
@@ -114,8 +106,6 @@
114106
115 def test_password_focus_gain(self):107 def test_password_focus_gain(self):
116 """Check functions execution when focus_changed() is executed."""108 """Check functions execution when focus_changed() is executed."""
117 self.ui.show()
118 self.addCleanup(self.ui.hide)
119 self.ui.ui.password_assistance.setVisible(False)109 self.ui.ui.password_assistance.setVisible(False)
120 self.assertFalse(self.ui.ui.password_assistance.isVisible())110 self.assertFalse(self.ui.ui.password_assistance.isVisible())
121 self.patch(self.ui, 'name_assistance', self._set_called)111 self.patch(self.ui, 'name_assistance', self._set_called)
@@ -192,8 +182,6 @@
192 def test_initialize_page(self):182 def test_initialize_page(self):
193 """Widgets are properly initialized."""183 """Widgets are properly initialized."""
194 self.ui.initializePage()184 self.ui.initializePage()
195 self.ui.show()
196 self.addCleanup(self.ui.hide)
197185
198 # set up account button186 # set up account button
199 expected = [QtGui.QWizard.BackButton, QtGui.QWizard.Stretch,187 expected = [QtGui.QWizard.BackButton, QtGui.QWizard.Stretch,
@@ -232,8 +220,6 @@
232 self.patch(self.ui, 'set_next_validation', self._set_called)220 self.patch(self.ui, 'set_next_validation', self._set_called)
233 self.ui.initializePage()221 self.ui.initializePage()
234 self.ui.captcha_received = True222 self.ui.captcha_received = True
235 self.ui.show()
236 self.addCleanup(self.ui.hide)
237223
238 self.ui.set_up_button.clicked.emit(False)224 self.ui.set_up_button.clicked.emit(False)
239 self.assertEqual(self._called, ((False,), {}))225 self.assertEqual(self._called, ((False,), {}))
@@ -241,13 +227,10 @@
241 def test_set_error_message(self):227 def test_set_error_message(self):
242 """Check the state of the label after calling: set_error_message."""228 """Check the state of the label after calling: set_error_message."""
243 self.ui.email_assistance()229 self.ui.email_assistance()
244 self.ui.show()
245 self.addCleanup(self.ui.hide)
246 self.ui.set_error_message(self.ui.ui.email_assistance, "message")230 self.ui.set_error_message(self.ui.ui.email_assistance, "message")
247 self.assertTrue(self.ui.ui.email_assistance.isVisible())231 self.assertTrue(self.ui.ui.email_assistance.isVisible())
248 self.assertEqual(232 self.assert_error_correct(self.ui.ui.email_assistance, "message",
249 unicode(self.ui.ui.email_assistance.text()),233 max_width=self.ui.header.max_title_width)
250 gui.ERROR_STYLE % "message")
251234
252 def test_blank_name(self):235 def test_blank_name(self):
253 """Status when the name field is blank (spaces).236 """Status when the name field is blank (spaces).
@@ -257,13 +240,9 @@
257 """240 """
258 self.ui.ui.name_edit.setText(" ")241 self.ui.ui.name_edit.setText(" ")
259 self.ui.name_assistance()242 self.ui.name_assistance()
260 self.ui.show()
261 self.addCleanup(self.ui.hide)
262 self.assertTrue(self.ui.ui.name_assistance.isVisible())243 self.assertTrue(self.ui.ui.name_assistance.isVisible())
263 self.assertEqual(244 self.assert_error_correct(self.ui.ui.name_assistance, gui.EMPTY_NAME,
264 unicode(self.ui.ui.name_assistance.text()),245 max_width=self.ui.header.max_title_width)
265 gui.ERROR_STYLE % gui.EMPTY_NAME)
266 self.ui.hide()
267246
268 def test_valid_name(self):247 def test_valid_name(self):
269 """Status when the name field is valid.248 """Status when the name field is valid.
@@ -272,10 +251,7 @@
272 """251 """
273 self.ui.ui.name_edit.setText("John Doe")252 self.ui.ui.name_edit.setText("John Doe")
274 self.ui.name_assistance()253 self.ui.name_assistance()
275 self.ui.show()
276 self.addCleanup(self.ui.hide)
277 self.assertFalse(self.ui.ui.name_assistance.isVisible())254 self.assertFalse(self.ui.ui.name_assistance.isVisible())
278 self.ui.hide()
279255
280 def test_invalid_email(self):256 def test_invalid_email(self):
281 """Status when the email field has no @.257 """Status when the email field has no @.
@@ -285,12 +261,10 @@
285 """261 """
286 self.ui.ui.email_edit.setText("foobar")262 self.ui.ui.email_edit.setText("foobar")
287 self.ui.email_assistance()263 self.ui.email_assistance()
288 self.ui.show()
289 self.addCleanup(self.ui.hide)
290 self.assertTrue(self.ui.ui.email_assistance.isVisible())264 self.assertTrue(self.ui.ui.email_assistance.isVisible())
291 self.assertEqual(265 self.assert_error_correct(self.ui.ui.email_assistance,
292 unicode(self.ui.ui.email_assistance.text()),266 gui.INVALID_EMAIL,
293 gui.ERROR_STYLE % gui.INVALID_EMAIL)267 max_width=self.ui.header.max_title_width)
294268
295 def test_valid_email(self):269 def test_valid_email(self):
296 """Status when the email field has a @.270 """Status when the email field has a @.
@@ -299,10 +273,7 @@
299 """273 """
300 self.ui.ui.email_edit.setText("foo@bar")274 self.ui.ui.email_edit.setText("foo@bar")
301 self.ui.email_assistance()275 self.ui.email_assistance()
302 self.ui.show()
303 self.addCleanup(self.ui.hide)
304 self.assertFalse(self.ui.ui.email_assistance.isVisible())276 self.assertFalse(self.ui.ui.email_assistance.isVisible())
305 self.ui.hide()
306277
307 def test_matching_emails(self):278 def test_matching_emails(self):
308 """Status when the email fields match.279 """Status when the email fields match.
@@ -312,10 +283,7 @@
312 self.ui.ui.email_edit.setText("foo@bar")283 self.ui.ui.email_edit.setText("foo@bar")
313 self.ui.ui.confirm_email_edit.setText("foo@bar")284 self.ui.ui.confirm_email_edit.setText("foo@bar")
314 self.ui.confirm_email_assistance()285 self.ui.confirm_email_assistance()
315 self.ui.show()
316 self.addCleanup(self.ui.hide)
317 self.assertFalse(self.ui.ui.confirm_email_assistance.isVisible())286 self.assertFalse(self.ui.ui.confirm_email_assistance.isVisible())
318 self.ui.hide()
319287
320 def test_not_matching_emails(self):288 def test_not_matching_emails(self):
321 """Status when the email fields don't match.289 """Status when the email fields don't match.
@@ -326,18 +294,13 @@
326 self.ui.ui.email_edit.setText("foo@bar")294 self.ui.ui.email_edit.setText("foo@bar")
327 self.ui.ui.confirm_email_edit.setText("foo@baz")295 self.ui.ui.confirm_email_edit.setText("foo@baz")
328 self.ui.confirm_email_assistance()296 self.ui.confirm_email_assistance()
329 self.ui.show()
330 self.addCleanup(self.ui.hide)
331 self.assertTrue(self.ui.ui.confirm_email_assistance.isVisible())297 self.assertTrue(self.ui.ui.confirm_email_assistance.isVisible())
332 self.assertEqual(298 self.assert_error_correct(self.ui.ui.confirm_email_assistance,
333 unicode(self.ui.ui.confirm_email_assistance.text()),299 gui.EMAIL_MATCH,
334 gui.ERROR_STYLE % gui.EMAIL_MATCH)300 max_width=self.ui.header.max_title_width)
335 self.ui.hide()
336301
337 def test_focus_changed_password_visibility(self):302 def test_focus_changed_password_visibility(self):
338 """Check visibility changes when focus_changed() is executed."""303 """Check visibility changes when focus_changed() is executed."""
339 self.ui.show()
340 self.addCleanup(self.ui.hide)
341 self.ui.focus_changed(None, self.ui.ui.password_edit)304 self.ui.focus_changed(None, self.ui.ui.password_edit)
342 self.assertTrue(self.ui.ui.password_assistance.isVisible())305 self.assertTrue(self.ui.ui.password_assistance.isVisible())
343306
@@ -352,33 +315,41 @@
352 self.ui.showEvent(QtGui.QShowEvent())315 self.ui.showEvent(QtGui.QShowEvent())
353 self.ui.hideEvent(QtGui.QHideEvent())316 self.ui.hideEvent(QtGui.QHideEvent())
354317
355 def test_on_captcha_refreshing(self):318 def test_on_captcha_refreshing_visible(self):
356 """Check the state of the overlay on captcha refreshing."""319 """Check the state of the overlay on captcha refreshing."""
357 self.assertEqual(self._overlay_show_counter, 0)320 self.ui.hide_overlay()
358 self.ui.on_captcha_refreshing()321
359 self.assertEqual(self._overlay_show_counter, 0)322 self.assertEqual(self._overlay_show_counter, 0)
360 self.assertTrue(self.ui.isEnabled())323 self.assertTrue(self.ui.isEnabled())
361 self.ui.captcha_received = True324
362 self.ui.show()325 self.ui.on_captcha_refreshing()
363 self.addCleanup(self.ui.hide)326
364 self.assertEqual(self._overlay_show_counter, 0)
365 self.assertTrue(self.ui.isEnabled())
366 self.ui.on_captcha_refreshing()
367 self.assertFalse(self.ui.isEnabled())327 self.assertFalse(self.ui.isEnabled())
368 self.assertEqual(self._overlay_show_counter, 1)328 self.assertEqual(self._overlay_show_counter, 1)
369329
330 def test_on_captcha_refreshing_not_visible(self):
331 """Check the state of the overlay on captcha refreshing."""
332 self.ui.hide_overlay()
333
334 self.assertEqual(self._overlay_show_counter, 0)
335 self.assertTrue(self.ui.isEnabled())
336
337 self.ui.hide()
338 self.ui.on_captcha_refreshing()
339
340 self.assertEqual(self._overlay_show_counter, 0)
341 self.assertTrue(self.ui.isEnabled())
342
370 def test_on_captcha_refresh_complete(self):343 def test_on_captcha_refresh_complete(self):
371 """Check the state of the overlay on captcha refreshing complete."""344 """Check the state of the overlay on captcha refreshing complete."""
372 self.assertEqual(self._overlay_hide_counter, 0)345 self.assertEqual(self._overlay_hide_counter, 0)
373 self.assertTrue(self.ui.isEnabled())346
374 self.ui.on_captcha_refresh_complete()347 self.ui.on_captcha_refresh_complete()
348
375 self.assertEqual(self._overlay_hide_counter, 1)349 self.assertEqual(self._overlay_hide_counter, 1)
376 self.assertTrue(self.ui.isEnabled())
377350
378 def test_hide_error_on_refresh_captcha(self):351 def test_hide_error_on_refresh_captcha(self):
379 """Test that the errors are hidden on refresh captcha."""352 """Test that the errors are hidden on refresh captcha."""
380 self.ui.show()353 self.ui.show_error('error-message')
381 self.addCleanup(self.ui.hide)
382 self.ui.show_error(self.app_name, 'error-message')
383 self.ui.ui.refresh_label.linkActivated.emit('link')354 self.ui.ui.refresh_label.linkActivated.emit('link')
384 self.assertEqual(self.ui.form_errors_label.text(), ' ')355 self.assertEqual(self.ui.form_errors_label.text(), ' ')
385356
=== modified file 'ubuntu_sso/qt/tests/test_sso_wizard_page.py'
--- ubuntu_sso/qt/tests/test_sso_wizard_page.py 2012-03-05 18:56:50 +0000
+++ ubuntu_sso/qt/tests/test_sso_wizard_page.py 2012-03-14 13:30:25 +0000
@@ -16,98 +16,127 @@
1616
17"""Test the SSOWizardPage and related."""17"""Test the SSOWizardPage and related."""
1818
19from twisted.internet import defer19from ubuntu_sso.qt import PREFERED_UI_SIZE, sso_wizard_page as gui
2020from ubuntu_sso.qt.tests import (
21from ubuntu_sso.qt import PREFERED_UI_SIZE21 APP_NAME,
22from ubuntu_sso.qt.setup_account_page import SetupAccountPage22 BaseTestCase,
23from ubuntu_sso.qt.sso_wizard_page import Header23 build_string_for_pixels,
24from ubuntu_sso.qt.tests import BaseTestCase, PageBaseTestCase24 PageBaseTestCase,
2525)
2626
27class HeaderTest(BaseTestCase):27
28MAX_WIDTH = 100
29
30
31class WizardHeaderTestCase(BaseTestCase):
2832
29 """Tests for injected Header in each Wizard Page."""33 """Tests for injected Header in each Wizard Page."""
3034
31 @defer.inlineCallbacks35 kwargs = dict(max_width=MAX_WIDTH)
32 def setUp(self):36 ui_class = gui.WizardHeader
33 yield super(HeaderTest, self).setUp()37 ui_wizard_class = None
34 self.header = Header()
3538
36 def test_label_state(self):39 def test_label_state(self):
37 """Check the title and subtitle properties."""40 """Check the title and subtitle properties."""
38 self.assertTrue(self.header.title_label.wordWrap())41 self.assertTrue(self.ui.title_label.wordWrap())
39 self.assertTrue(self.header.subtitle_label.wordWrap())42 self.assertTrue(self.ui.subtitle_label.wordWrap())
40 self.assertFalse(self.header.title_label.isVisible())43 self.assertFalse(self.ui.title_label.isVisible())
41 self.assertFalse(self.header.subtitle_label.isVisible())44 self.assertFalse(self.ui.subtitle_label.isVisible())
4245
43 def test_set_title(self):46 def test_set_title(self):
44 """Check if set_title works ok, showing the widget if necessary."""47 """Check if set_title works ok, showing the widget if necessary."""
45 self.header.set_title('title')48 max_width = self.ui.max_title_width
46 self.assertEqual(self.header.title_label.text(), 'title')49 text = build_string_for_pixels(self.ui.title_label, max_width)
47 self.header.show()50
48 self.assertTrue(self.header.title_label.isVisible())51 self.ui.set_title(text)
49 self.header.hide()52
53 self.assert_title_correct(self.ui.title_label, text, max_width)
5054
51 def test_set_elided_title(self):55 def test_set_elided_title(self):
52 """Check if set_title adds the ellipsis when necessary."""56 """Check if set_title adds the ellipsis when necessary."""
53 # add an extra letter so we ensure this needs to be trimmed57 # add an extra letter so we ensure this needs to be trimmed
54 title = 'a' * int(PREFERED_UI_SIZE['width'] * 0.95) + 'a'58 max_width = self.ui.max_title_width
55 self.header.set_title(title)59 text = build_string_for_pixels(self.ui.title_label, max_width + 10)
56 self.assertEqual(self.header.title_label.toolTip(), title)60
57 expected = unicode(self.header.title_label.text())61 self.ui.set_title(text)
58 self.assertTrue(expected.endswith(u'\u2026'))62
63 self.assert_title_correct(self.ui.title_label, text, max_width)
5964
60 def test_set_empty_title(self):65 def test_set_empty_title(self):
61 """Check if the widget is hidden for empty title."""66 """Check if the widget is hidden for empty title."""
62 self.header.set_title('')67 self.ui.set_title('')
63 self.assertFalse(self.header.title_label.isVisible())68
69 self.assertEqual(self.ui.title_label.toolTip(), '')
70 self.assertFalse(self.ui.title_label.isVisible())
6471
65 def test_set_subtitle(self):72 def test_set_subtitle(self):
66 """Check if set_subtitle works ok, showing the widget if necessary."""73 """Check if set_subtitle works ok, showing the widget if necessary."""
67 self.header.set_subtitle('subtitle')74 max_width = self.ui.max_subtitle_width
68 self.assertEqual(self.header.subtitle_label.text(), 'subtitle')75 text = build_string_for_pixels(self.ui.subtitle_label, max_width)
69 self.header.show()76
70 self.assertTrue(self.header.subtitle_label.isVisible())77 self.ui.set_subtitle(text)
71 self.header.hide()78
79 self.assert_subtitle_correct(self.ui.subtitle_label, text, max_width)
7280
73 def test_set_elided_subtitle(self):81 def test_set_elided_subtitle(self):
74 """Check if set_subtitle adds the ellipsis when necessary."""82 """Check if set_subtitle adds the ellipsis when necessary."""
75 subtitle = 'a' * int(PREFERED_UI_SIZE['width'] * 0.95) + 'a'83 max_width = self.ui.max_subtitle_width
76 self.header.set_subtitle(subtitle)84 text = build_string_for_pixels(self.ui.subtitle_label, max_width + 10)
77 self.assertEqual(self.header.subtitle_label.toolTip(), subtitle)85
78 expected = unicode(self.header.subtitle_label.text())86 self.ui.set_subtitle(text)
79 self.assertTrue(expected.endswith(u'\u2026'))87
88 self.assert_subtitle_correct(self.ui.subtitle_label, text, max_width)
8089
81 def test_set_empty_subtitle(self):90 def test_set_empty_subtitle(self):
82 """Check if the widget is hidden for empty subtitle."""91 """Check if the widget is hidden for empty subtitle."""
83 self.header.set_title('')92 self.ui.set_subtitle('')
84 self.assertFalse(self.header.title_label.isVisible())93
8594 self.assertEqual(self.ui.subtitle_label.toolTip(), '')
8695 self.assertFalse(self.ui.subtitle_label.isVisible())
87class SSOWizardPageTest(PageBaseTestCase):96
8897
89 """Tests for SSOWizardPage."""98class BaseWizardPageTestCase(PageBaseTestCase):
9099
91 ui_class = SetupAccountPage100 """Tests for SSOWizardPage."""
101
102 kwargs = {}
103 ui_class = gui.BaseWizardPage
104
105 def test_max_width(self):
106 """The max_width is correct."""
107 self.assertEqual(self.ui.max_width, 0)
108
109
110class SSOWizardPageTestCase(BaseWizardPageTestCase):
111
112 """Tests for SSOWizardPage."""
113
114 kwargs = dict(app_name=APP_NAME)
115 ui_class = gui.SSOWizardPage
116
117 def test_max_width(self):
118 """The max_width is correct."""
119 self.assertEqual(self.ui.max_width, PREFERED_UI_SIZE['width'])
92120
93 def test_show_error(self):121 def test_show_error(self):
94 """Test show_error with a normal length string."""122 """Test show_error with a normal length string."""
95 message = 'error-message'123 message = 'error-message'
96 self.ui.show_error(self.app_name, message)124 self.ui.show_error(message)
97 self.assertEqual(self.ui.form_errors_label.toolTip(), message)125
98 expected = unicode(self.ui.form_errors_label.text())126 self.assert_error_correct(self.ui.form_errors_label, message,
99 self.assertEqual(expected, message)127 self.ui.header.max_title_width)
100128
101 def test_show_error_long_text(self):129 def test_show_error_long_text(self):
102 """Test show_error with a long length string."""130 """Test show_error with a long length string."""
103 message = 'a' * int(PREFERED_UI_SIZE['width'] * 0.95) + 'a'131 message = build_string_for_pixels(self.ui.form_errors_label,
104 self.ui.show_error(self.app_name, message)132 self.ui.header.max_title_width + 10)
105 self.assertEqual(self.ui.form_errors_label.toolTip(), message)133 self.ui.show_error(message)
106 expected = unicode(self.ui.form_errors_label.text())134
107 self.assertTrue(expected.endswith(u'\u2026'))135 self.assert_error_correct(self.ui.form_errors_label, message,
136 self.ui.header.max_title_width)
108137
109 def test_hide_error(self):138 def test_hide_error(self):
110 """Test show_error with a long length string."""139 """Test show_error with a long length string."""
111 message = ' '
112 self.ui.hide_error()140 self.ui.hide_error()
113 self.assertEqual(self.ui.form_errors_label.text(), message)141
142 self.assertEqual(self.ui.form_errors_label.text(), ' ')
114143
=== modified file 'ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py'
--- ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-03-13 20:33:06 +0000
+++ ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-03-14 13:30:25 +0000
@@ -112,8 +112,6 @@
112112
113 def test_window_size(self):113 def test_window_size(self):
114 """check the window size."""114 """check the window size."""
115 self.ui.show()
116 self.addCleanup(self.ui.hide)
117 size = self.ui.size()115 size = self.ui.size()
118 self.assertTrue(size.height() >= PREFERED_UI_SIZE['height'])116 self.assertTrue(size.height() >= PREFERED_UI_SIZE['height'])
119 self.assertTrue(size.width() >= PREFERED_UI_SIZE['width'])117 self.assertTrue(size.width() >= PREFERED_UI_SIZE['width'])
@@ -131,6 +129,9 @@
131129
132 def test_overlay_shows(self):130 def test_overlay_shows(self):
133 """Test if the signals call the overlay.show properly."""131 """Test if the signals call the overlay.show properly."""
132 # reset the counter
133 self.ui.overlay.show_counter = 0
134
134 for page in self.ui._pages:135 for page in self.ui._pages:
135 page.show_overlay()136 page.show_overlay()
136137
@@ -138,6 +139,9 @@
138139
139 def test_overlay_hides(self):140 def test_overlay_hides(self):
140 """Test if the signals call the overlay.show properly."""141 """Test if the signals call the overlay.show properly."""
142 # reset the counter
143 self.ui.overlay.show_counter = 0
144
141 for page in self.ui._pages:145 for page in self.ui._pages:
142 page.hide_overlay()146 page.hide_overlay()
143147
@@ -157,8 +161,6 @@
157161
158 def test_email_verification_page_params_from_current_user(self):162 def test_email_verification_page_params_from_current_user(self):
159 """Tests that email_verification_page receives the proper params."""163 """Tests that email_verification_page receives the proper params."""
160 self.ui.show()
161 self.addCleanup(self.ui.hide)
162 self.ui._next_id = self.ui.current_user_page_id164 self.ui._next_id = self.ui.current_user_page_id
163 self.ui.next()165 self.ui.next()
164 self.ui.current_user.ui.email_edit.setText(EMAIL)166 self.ui.current_user.ui.email_edit.setText(EMAIL)
@@ -169,8 +171,6 @@
169171
170 def test_email_verification_page_params_from_setup(self):172 def test_email_verification_page_params_from_setup(self):
171 """Tests that email_verification_page receives the proper params."""173 """Tests that email_verification_page receives the proper params."""
172 self.ui.show()
173 self.addCleanup(self.ui.hide)
174 self.ui.setup_account.ui.email_edit.setText(EMAIL)174 self.ui.setup_account.ui.email_edit.setText(EMAIL)
175 self.ui.setup_account.ui.password_edit.setText(PASSWORD)175 self.ui.setup_account.ui.password_edit.setText(PASSWORD)
176 self.ui.setup_account.on_user_registered(APP_NAME, {})176 self.ui.setup_account.on_user_registered(APP_NAME, {})

Subscribers

People subscribed via source and target branches