Merge lp:~nataliabidart/ubuntu-sso-client/use-login-only into lp:ubuntu-sso-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 899
Merged at revision: 888
Proposed branch: lp:~nataliabidart/ubuntu-sso-client/use-login-only
Merge into: lp:ubuntu-sso-client
Diff against target: 2912 lines (+562/-1252)
28 files modified
data/qt/choose_sign_in.ui (+0/-163)
run-tests.bat (+1/-1)
ubuntu_sso/qt/current_user_sign_in_page.py (+9/-18)
ubuntu_sso/qt/email_verification_page.py (+18/-21)
ubuntu_sso/qt/error_page.py (+11/-4)
ubuntu_sso/qt/forgotten_password_page.py (+13/-20)
ubuntu_sso/qt/loadingoverlay.py (+4/-11)
ubuntu_sso/qt/network_detection_page.py (+17/-8)
ubuntu_sso/qt/reset_password_page.py (+22/-29)
ubuntu_sso/qt/setup_account_page.py (+66/-68)
ubuntu_sso/qt/sign_in_page.py (+0/-97)
ubuntu_sso/qt/sso_wizard_page.py (+51/-18)
ubuntu_sso/qt/success_page.py (+13/-4)
ubuntu_sso/qt/tests/__init__.py (+89/-37)
ubuntu_sso/qt/tests/test_current_user_sign_in_page.py (+4/-70)
ubuntu_sso/qt/tests/test_email_verification.py (+16/-66)
ubuntu_sso/qt/tests/test_enchanced_line_edit.py (+2/-5)
ubuntu_sso/qt/tests/test_error_page.py (+26/-0)
ubuntu_sso/qt/tests/test_forgotten_password.py (+7/-59)
ubuntu_sso/qt/tests/test_loadingoverlay.py (+8/-8)
ubuntu_sso/qt/tests/test_network_detection.py (+19/-33)
ubuntu_sso/qt/tests/test_reset_password.py (+19/-48)
ubuntu_sso/qt/tests/test_setup_account.py (+19/-58)
ubuntu_sso/qt/tests/test_sign_in_page.py (+0/-69)
ubuntu_sso/qt/tests/test_sso_wizard_page.py (+12/-96)
ubuntu_sso/qt/tests/test_success_page.py (+26/-0)
ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py (+24/-48)
ubuntu_sso/qt/ubuntu_sso_wizard.py (+66/-193)
To merge this branch: bzr merge lp:~nataliabidart/ubuntu-sso-client/use-login-only
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+94455@code.launchpad.net

Commit message

- Move the 'choose sign in page' to client code (U1 control panel
  in this case) (LP: #933576).
- Make use of the 'login_only' parameter that is being passed to the
  UbuntuSSOWizard (LP: #939558).

To post a comment you must log in.
890. By Natalia Bidart

- Also remove choose_sign_in.ui file (no longer needed in this project).

891. By Natalia Bidart

Merged trunk in.

892. By Natalia Bidart

- Fixed window tests run.

893. By Natalia Bidart

Movind the line_edit connects to _connect_ui method.

894. By Natalia Bidart

Merged dependency branch in.

895. By Natalia Bidart

Making test pass.

896. By Natalia Bidart

Merged trunk in.

897. By Natalia Bidart

Fixing another test.

898. By Natalia Bidart

Lint fixes.

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

+1

review: Approve
899. By Natalia Bidart

Fixed pep8 issues.

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
=== removed file 'data/qt/choose_sign_in.ui'
--- data/qt/choose_sign_in.ui 2012-02-22 16:58:08 +0000
+++ data/qt/choose_sign_in.ui 1970-01-01 00:00:00 +0000
@@ -1,163 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>ChooseSignInPage</class>
4 <widget class="QWizardPage" name="ChooseSignInPage">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>432</width>
10 <height>387</height>
11 </rect>
12 </property>
13 <layout class="QVBoxLayout" name="verticalLayout_2">
14 <property name="leftMargin">
15 <number>0</number>
16 </property>
17 <property name="topMargin">
18 <number>0</number>
19 </property>
20 <property name="rightMargin">
21 <number>0</number>
22 </property>
23 <item>
24 <layout class="QHBoxLayout" name="horizontalLayout_2">
25 <item>
26 <widget class="QLabel" name="image_label">
27 <property name="sizePolicy">
28 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
29 <horstretch>0</horstretch>
30 <verstretch>0</verstretch>
31 </sizepolicy>
32 </property>
33 <property name="minimumSize">
34 <size>
35 <width>400</width>
36 <height>150</height>
37 </size>
38 </property>
39 <property name="text">
40 <string/>
41 </property>
42 <property name="textFormat">
43 <enum>Qt::PlainText</enum>
44 </property>
45 <property name="alignment">
46 <set>Qt::AlignCenter</set>
47 </property>
48 <property name="wordWrap">
49 <bool>true</bool>
50 </property>
51 </widget>
52 </item>
53 </layout>
54 </item>
55 <item>
56 <widget class="QLabel" name="message_label">
57 <property name="font">
58 <font>
59 <pointsize>11</pointsize>
60 <weight>50</weight>
61 <bold>false</bold>
62 </font>
63 </property>
64 <property name="text">
65 <string notr="true">Congratulations, app_name is installed!</string>
66 </property>
67 <property name="alignment">
68 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
69 </property>
70 </widget>
71 </item>
72 <item>
73 <spacer name="verticalSpacer_3">
74 <property name="orientation">
75 <enum>Qt::Vertical</enum>
76 </property>
77 <property name="sizeType">
78 <enum>QSizePolicy::Fixed</enum>
79 </property>
80 <property name="sizeHint" stdset="0">
81 <size>
82 <width>20</width>
83 <height>30</height>
84 </size>
85 </property>
86 </spacer>
87 </item>
88 <item>
89 <layout class="QHBoxLayout" name="horizontalLayout">
90 <item>
91 <spacer name="horizontalSpacer_2">
92 <property name="orientation">
93 <enum>Qt::Horizontal</enum>
94 </property>
95 <property name="sizeHint" stdset="0">
96 <size>
97 <width>20</width>
98 <height>20</height>
99 </size>
100 </property>
101 </spacer>
102 </item>
103 <item>
104 <layout class="QVBoxLayout" name="verticalLayout">
105 <item>
106 <widget class="QPushButton" name="existing_account_button">
107 <property name="text">
108 <string notr="true"/>
109 </property>
110 </widget>
111 </item>
112 <item>
113 <widget class="QPushButton" name="setup_account_button">
114 <property name="text">
115 <string notr="true"/>
116 </property>
117 </widget>
118 </item>
119 <item>
120 <widget class="QPushButton" name="cancel_button">
121 <property name="text">
122 <string notr="true"/>
123 </property>
124 </widget>
125 </item>
126 </layout>
127 </item>
128 <item>
129 <spacer name="horizontalSpacer">
130 <property name="orientation">
131 <enum>Qt::Horizontal</enum>
132 </property>
133 <property name="sizeType">
134 <enum>QSizePolicy::Expanding</enum>
135 </property>
136 <property name="sizeHint" stdset="0">
137 <size>
138 <width>20</width>
139 <height>20</height>
140 </size>
141 </property>
142 </spacer>
143 </item>
144 </layout>
145 </item>
146 <item>
147 <spacer name="verticalSpacer_2">
148 <property name="orientation">
149 <enum>Qt::Vertical</enum>
150 </property>
151 <property name="sizeHint" stdset="0">
152 <size>
153 <width>20</width>
154 <height>50</height>
155 </size>
156 </property>
157 </spacer>
158 </item>
159 </layout>
160 </widget>
161 <resources/>
162 <connections/>
163</ui>
1640
=== modified file 'run-tests.bat'
--- run-tests.bat 2012-01-31 19:02:36 +0000
+++ run-tests.bat 2012-02-24 17:28:19 +0000
@@ -99,7 +99,7 @@
99"%PYTHONEXEPATH%\python.exe" setup.py build99"%PYTHONEXEPATH%\python.exe" setup.py build
100ECHO Running tests100ECHO Running tests
101:: execute the tests with a number of ignored linux only modules101:: execute the tests with a number of ignored linux only modules
102"%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" -i "test_linux.py, test_txsecrets.py" -p "ubuntu_sso\gtk" --reactor=qt4 --gui %PARAMS% ubuntu_sso 102"%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" -i "test_linux.py, test_txsecrets.py, test_qt.py, test_glib.py" -p "ubuntu_sso\gtk" --reactor=qt4 --gui %PARAMS% ubuntu_sso
103:: Clean the build from the setupt.py103:: Clean the build from the setupt.py
104ECHO Cleaning the generated code104ECHO Cleaning the generated code
105"%PYTHONEXEPATH%\python.exe" setup.py clean105"%PYTHONEXEPATH%\python.exe" setup.py clean
106106
=== modified file 'ubuntu_sso/qt/current_user_sign_in_page.py'
--- ubuntu_sso/qt/current_user_sign_in_page.py 2012-02-18 15:02:49 +0000
+++ ubuntu_sso/qt/current_user_sign_in_page.py 2012-02-24 17:28:19 +0000
@@ -19,12 +19,12 @@
19from functools import partial19from functools import partial
2020
21from PyQt4 import QtGui, QtCore21from PyQt4 import QtGui, QtCore
22from twisted.internet import defer
2322
24from ubuntu_sso import NO_OP23from ubuntu_sso import NO_OP
24from ubuntu_sso.logger import setup_logging
25from ubuntu_sso.qt import build_general_error_message25from ubuntu_sso.qt import build_general_error_message
26from ubuntu_sso.qt.gui import SSOWizardPage26from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage
27from ubuntu_sso.logger import setup_logging27from ubuntu_sso.qt.ui.current_user_sign_in_ui import Ui_CurrentUserSignInPage
28from ubuntu_sso.utils.ui import (28from ubuntu_sso.utils.ui import (
29 CANCEL_BUTTON,29 CANCEL_BUTTON,
30 EMAIL_LABEL,30 EMAIL_LABEL,
@@ -45,15 +45,15 @@
45class CurrentUserSignInPage(SSOWizardPage):45class CurrentUserSignInPage(SSOWizardPage):
46 """Wizard Page that lets a current user Sign into Ubuntu Single Sign On."""46 """Wizard Page that lets a current user Sign into Ubuntu Single Sign On."""
4747
48 ui_class = Ui_CurrentUserSignInPage
48 userLoggedIn = QtCore.pyqtSignal('QString', 'QString')49 userLoggedIn = QtCore.pyqtSignal('QString', 'QString')
49 passwordForgotten = QtCore.pyqtSignal()50 passwordForgotten = QtCore.pyqtSignal()
50 userNotValidated = QtCore.pyqtSignal('QString', 'QString')51 userNotValidated = QtCore.pyqtSignal('QString', 'QString')
5152
52 def __init__(self, ui, ping_url, *args, **kwargs):53 @property
53 super(CurrentUserSignInPage, self).__init__(ui, *args, **kwargs)54 def _signals(self):
54 self.ping_url = ping_url55 """The signals to connect to the backend."""
5556 result = {
56 self._signals = {
57 'LoggedIn':57 'LoggedIn':
58 self._filter_by_app_name(self.on_logged_in),58 self._filter_by_app_name(self.on_logged_in),
59 'LoginError':59 'LoginError':
@@ -61,7 +61,7 @@
61 'UserNotValidated':61 'UserNotValidated':
62 self._filter_by_app_name(self.on_user_not_validated),62 self._filter_by_app_name(self.on_user_not_validated),
63 }63 }
64 self.setup_page()64 return result
6565
66 def on_user_not_validated(self, *args):66 def on_user_not_validated(self, *args):
67 """Show the validate email page."""67 """Show the validate email page."""
@@ -69,15 +69,6 @@
69 password = unicode(self.ui.password_edit.text())69 password = unicode(self.ui.password_edit.text())
70 self.userNotValidated.emit(email, password)70 self.userNotValidated.emit(email, password)
7171
72 @defer.inlineCallbacks
73 def setup_page(self):
74 """Setup the widget components."""
75 self.backend = yield self.get_backend()
76 self._set_translated_strings()
77 # lets add call backs to be execute for the calls we are interested
78 self._setup_signals()
79 self._connect_ui()
80
81 # Invalid names of Qt-inherited methods72 # Invalid names of Qt-inherited methods
82 # pylint: disable=C010373 # pylint: disable=C0103
8374
8475
=== modified file 'ubuntu_sso/qt/email_verification_page.py'
--- ubuntu_sso/qt/email_verification_page.py 2012-02-22 16:58:08 +0000
+++ ubuntu_sso/qt/email_verification_page.py 2012-02-24 17:28:19 +0000
@@ -19,19 +19,19 @@
19from functools import partial19from functools import partial
2020
21from PyQt4 import QtCore21from PyQt4 import QtCore
22from twisted.internet import defer
2322
24from ubuntu_sso import NO_OP23from ubuntu_sso import NO_OP
24from ubuntu_sso.logger import setup_logging
25from ubuntu_sso.qt import build_general_error_message25from ubuntu_sso.qt import build_general_error_message
26from ubuntu_sso.qt.gui import SSOWizardPage26from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage
27from ubuntu_sso.logger import setup_logging27from ubuntu_sso.qt.ui.email_verification_ui import Ui_EmailVerificationPage
28from ubuntu_sso.utils.ui import (28from ubuntu_sso.utils.ui import (
29 ERROR_EMAIL_TOKEN,
29 NEXT,30 NEXT,
30 VERIFICATION_CODE,31 VERIFICATION_CODE,
31 VERIFY_EMAIL_TITLE,32 VERIFY_EMAIL_TITLE,
32 VERIFY_EMAIL_CONTENT,33 VERIFY_EMAIL_CONTENT,
33)34)
34from ubuntu_sso.utils.ui import ERROR_EMAIL_TOKEN
3535
3636
37logger = setup_logging('ubuntu_sso.email_verification_page')37logger = setup_logging('ubuntu_sso.email_verification_page')
@@ -40,27 +40,24 @@
40class EmailVerificationPage(SSOWizardPage):40class EmailVerificationPage(SSOWizardPage):
41 """Widget used to input the email verification code."""41 """Widget used to input the email verification code."""
4242
43 ui_class = Ui_EmailVerificationPage
43 registrationSuccess = QtCore.pyqtSignal('QString', 'QString')44 registrationSuccess = QtCore.pyqtSignal('QString', 'QString')
4445
45 def __init__(self, ui, ping_url, *args, **kwargs):46 def __init__(self, *args, **kwargs):
46 super(EmailVerificationPage, self).__init__(ui, *args, **kwargs)
47 self.ping_url = ping_url
48 self.email = ''47 self.email = ''
49 self.password = ''48 self.password = ''
50 self._signals = {49 super(EmailVerificationPage, self).__init__(*args, **kwargs)
50
51 @property
52 def _signals(self):
53 """The signals to connect to the backend."""
54 result = {
51 'EmailValidated':55 'EmailValidated':
52 self._filter_by_app_name(self.on_email_validated),56 self._filter_by_app_name(self.on_email_validated),
53 'EmailValidationError':57 'EmailValidationError':
54 self._filter_by_app_name(self.on_email_validation_error),58 self._filter_by_app_name(self.on_email_validation_error),
55 }59 }
56 self.setup_page()60 return result
57
58 @defer.inlineCallbacks
59 def setup_page(self):
60 """Setup the ui components."""
61 self.backend = yield self.get_backend()
62 self._setup_signals()
63 self._connect_ui_elements()
6461
65 @property62 @property
66 def verification_code(self):63 def verification_code(self):
@@ -72,9 +69,9 @@
72 """Return the button that move to the next stage."""69 """Return the button that move to the next stage."""
73 return self.ui.next_button70 return self.ui.next_button
7471
75 def _connect_ui_elements(self):72 def _connect_ui(self):
76 """Set the connection of signals."""73 """Set the connection of signals."""
77 logger.debug('EmailVerificationController._connect_ui_elements')74 logger.debug('EmailVerificationController._connect_ui')
78 self.ui.verification_code_edit.textChanged.connect(75 self.ui.verification_code_edit.textChanged.connect(
79 self.validate_form)76 self.validate_form)
80 self.next_button.clicked.connect(self.validate_email)77 self.next_button.clicked.connect(self.validate_email)
@@ -89,7 +86,7 @@
89 self.next_button.style().unpolish(self.next_button)86 self.next_button.style().unpolish(self.next_button)
90 self.next_button.style().polish(self.next_button)87 self.next_button.style().polish(self.next_button)
9188
92 def _set_titles(self):89 def _set_translated_strings(self):
93 """Set the different titles."""90 """Set the different titles."""
94 logger.debug('EmailVerificationController._set_titles')91 logger.debug('EmailVerificationController._set_titles')
95 self.header.set_title(VERIFY_EMAIL_TITLE)92 self.header.set_title(VERIFY_EMAIL_TITLE)
@@ -104,9 +101,9 @@
104 """This class needs to have a public set_titles.101 """This class needs to have a public set_titles.
105102
106 Since the subtitle contains data that is only known after SetupAccount103 Since the subtitle contains data that is only known after SetupAccount
107 and _set_titles is only called on initialization.104 and _set_translated_strings is only called on initialization.
108 """105 """
109 self._set_titles()106 self._set_translated_strings()
110107
111 def validate_email(self):108 def validate_email(self):
112 """Call the next action."""109 """Call the next action."""
113110
=== modified file 'ubuntu_sso/qt/error_page.py'
--- ubuntu_sso/qt/error_page.py 2012-02-07 18:59:36 +0000
+++ ubuntu_sso/qt/error_page.py 2012-02-24 17:28:19 +0000
@@ -16,14 +16,21 @@
1616
17"""Email Verification page UI."""17"""Email Verification page UI."""
1818
19from ubuntu_sso.qt.gui import SSOWizardPage19from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage
20from ubuntu_sso.qt.ui.error_message_ui import Ui_ErrorPage
20from ubuntu_sso.utils.ui import ERROR21from ubuntu_sso.utils.ui import ERROR
2122
2223
23class ErrorPage(SSOWizardPage):24class ErrorPage(SSOWizardPage):
24 """Widget used to show the diff errors."""25 """Widget used to show the diff errors."""
2526
26 def __init__(self, ui, *args, **kwargs):27 ui_class = Ui_ErrorPage
27 super(ErrorPage, self).__init__(ui, *args, **kwargs)28 next = None
29
30 def _set_translated_strings(self):
31 """Set the translated strings."""
32 self.ui.error_message_label.setText(ERROR)
33
34 def _connect_ui(self):
35 """Connect the buttons to perform actions."""
28 self.next = -136 self.next = -1
29 self.ui.error_message_label.setText(ERROR)
3037
=== modified file 'ubuntu_sso/qt/forgotten_password_page.py'
--- ubuntu_sso/qt/forgotten_password_page.py 2012-02-16 14:13:36 +0000
+++ ubuntu_sso/qt/forgotten_password_page.py 2012-02-24 17:28:19 +0000
@@ -19,10 +19,10 @@
19from functools import partial19from functools import partial
2020
21from PyQt4 import QtCore21from PyQt4 import QtCore
22from twisted.internet import defer
2322
24from ubuntu_sso import NO_OP23from ubuntu_sso import NO_OP
25from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage24from ubuntu_sso.qt.sso_wizard_page import SSOWizardEnhancedEditPage
25from ubuntu_sso.qt.ui.forgotten_password_ui import Ui_ForgottenPasswordPage
26from ubuntu_sso.utils.ui import (26from ubuntu_sso.utils.ui import (
27 EMAIL_LABEL,27 EMAIL_LABEL,
28 is_correct_email,28 is_correct_email,
@@ -37,29 +37,19 @@
37class ForgottenPasswordPage(SSOWizardEnhancedEditPage):37class ForgottenPasswordPage(SSOWizardEnhancedEditPage):
38 """Widget used to deal with users that forgot the password."""38 """Widget used to deal with users that forgot the password."""
3939
40 ui_class = Ui_ForgottenPasswordPage
40 passwordResetTokenSent = QtCore.pyqtSignal()41 passwordResetTokenSent = QtCore.pyqtSignal()
4142
42 def __init__(self, ui, *args, **kwargs):43 @property
43 super(ForgottenPasswordPage, self).__init__(ui, *args, **kwargs)44 def _signals(self):
44 self._signals = {45 """The signals to connect to the backend."""
46 result = {
45 'PasswordResetTokenSent':47 'PasswordResetTokenSent':
46 self._filter_by_app_name(self.on_password_reset_token_sent),48 self._filter_by_app_name(self.on_password_reset_token_sent),
47 'PasswordResetError':49 'PasswordResetError':
48 self._filter_by_app_name(self.on_password_reset_error),50 self._filter_by_app_name(self.on_password_reset_error),
49 }51 }
50 self.setup_page()52 return result
51
52 @defer.inlineCallbacks
53 def setup_page(self):
54 """Setup the widget components."""
55 self.backend = yield self.get_backend()
56 self._setup_signals()
57 # hide the error label
58 self.try_again_widget.setVisible(False)
59 self._set_translated_strings()
60 self._connect_ui()
61 self._set_enhanced_line_edit()
62 self._register_fields()
6353
64 @property54 @property
65 def email_widget(self):55 def email_widget(self):
@@ -144,8 +134,13 @@
144 self.email_address_line_edit.textChanged.connect(self._validate)134 self.email_address_line_edit.textChanged.connect(self._validate)
145135
146 self.send_button.clicked.connect(self.request_new_password)136 self.send_button.clicked.connect(self.request_new_password)
137
138 self.try_again_widget.setVisible(False)
147 self.try_again_button.clicked.connect(self.on_try_again)139 self.try_again_button.clicked.connect(self.on_try_again)
148140
141 self._set_enhanced_line_edit()
142 self._register_fields()
143
149 def request_new_password(self):144 def request_new_password(self):
150 """Send the request password operation."""145 """Send the request password operation."""
151 args = (self.app_name, self.email_address)146 args = (self.app_name, self.email_address)
@@ -171,13 +166,11 @@
171 self.try_again_widget.setVisible(False)166 self.try_again_widget.setVisible(False)
172 self.email_widget.setVisible(True)167 self.email_widget.setVisible(True)
173168
174 # pylint: disable=W0212
175 def on_password_reset_token_sent(self, app_name, result):169 def on_password_reset_token_sent(self, app_name, result):
176 """Action taken when we managed to get the password reset done."""170 """Action taken when we managed to get the password reset done."""
177 # ignore the result and move to the reset page171 # ignore the result and move to the reset page
178 self.overlay.hide()172 self.overlay.hide()
179 self.passwordResetTokenSent.emit()173 self.passwordResetTokenSent.emit()
180 # pylint: enable=W0212
181174
182 def on_password_reset_error(self, app_name, error):175 def on_password_reset_error(self, app_name, error):
183 """Action taken when there was an error requesting the reset."""176 """Action taken when there was an error requesting the reset."""
184177
=== modified file 'ubuntu_sso/qt/loadingoverlay.py'
--- ubuntu_sso/qt/loadingoverlay.py 2012-02-22 16:58:08 +0000
+++ ubuntu_sso/qt/loadingoverlay.py 2012-02-24 17:28:19 +0000
@@ -1,5 +1,5 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
22#
3# Copyright 2012 Canonical Ltd.3# Copyright 2012 Canonical Ltd.
4#4#
5# This program is free software: you can redistribute it and/or modify it5# This program is free software: you can redistribute it and/or modify it
@@ -45,7 +45,7 @@
4545
46 self.ui.label.setText(LOADING_OVERLAY)46 self.ui.label.setText(LOADING_OVERLAY)
4747
48 # Invalid name "paintEvent"48 # Invalid name "paintEvent", "eventFilter", "showEvent", "timerEvent"
49 # pylint: disable=C010349 # pylint: disable=C0103
5050
51 def paintEvent(self, event):51 def paintEvent(self, event):
@@ -60,9 +60,6 @@
60 painter.end()60 painter.end()
61 QtGui.QFrame.paintEvent(self, event)61 QtGui.QFrame.paintEvent(self, event)
6262
63 # Invalid name "eventFilter"
64 # pylint: disable=C0103
65
66 def eventFilter(self, obj, event):63 def eventFilter(self, obj, event):
67 """Filter events from Frame content to draw the dot animation."""64 """Filter events from Frame content to draw the dot animation."""
68 if getattr(self, 'ui', None) is not None and \65 if getattr(self, 'ui', None) is not None and \
@@ -99,9 +96,6 @@
99 painter.end()96 painter.end()
100 return False97 return False
10198
102 # Invalid name "showEvent"
103 # pylint: disable=C0103
104
105 def showEvent(self, event):99 def showEvent(self, event):
106 """Start the dot animation."""100 """Start the dot animation."""
107 self.ui.frm_box.installEventFilter(self)101 self.ui.frm_box.installEventFilter(self)
@@ -112,9 +106,6 @@
112 if not self.timer:106 if not self.timer:
113 self.timer = self.startTimer(200)107 self.timer = self.startTimer(200)
114108
115 # Invalid name "timerEvent"
116 # pylint: disable=C0103
117
118 def timerEvent(self, event):109 def timerEvent(self, event):
119 """Execute a loop to update the dot animation."""110 """Execute a loop to update the dot animation."""
120 if self.counter in (0, 4):111 if self.counter in (0, 4):
@@ -124,3 +115,5 @@
124 else:115 else:
125 self.counter -= 1116 self.counter -= 1
126 self.update()117 self.update()
118
119 # pylint: enable=C0103
127120
=== modified file 'ubuntu_sso/qt/network_detection_page.py'
--- ubuntu_sso/qt/network_detection_page.py 2012-02-22 16:58:08 +0000
+++ ubuntu_sso/qt/network_detection_page.py 2012-02-24 17:28:19 +0000
@@ -1,5 +1,5 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
22#
3# Copyright 2012 Canonical Ltd.3# Copyright 2012 Canonical Ltd.
4#4#
5# This program is free software: you can redistribute it and/or modify it5# This program is free software: you can redistribute it and/or modify it
@@ -21,6 +21,7 @@
2121
22from ubuntu_sso import networkstate22from ubuntu_sso import networkstate
2323
24from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage
24from ubuntu_sso.qt.ui import network_detection_ui25from ubuntu_sso.qt.ui import network_detection_ui
25from ubuntu_sso.utils.ui import (26from ubuntu_sso.utils.ui import (
26 CLOSE_AND_SETUP_LATER,27 CLOSE_AND_SETUP_LATER,
@@ -30,21 +31,21 @@
30)31)
3132
3233
33class NetworkDetectionPage(QtGui.QWizardPage):34class NetworkDetectionPage(SSOWizardPage):
3435
35 """Widget to show if we don't detect a network connection."""36 """Widget to show if we don't detect a network connection."""
3637
37 def __init__(self, app_name, banner_pixmap=None, parent=None):38 ui_class = network_detection_ui.Ui_Form
38 super(NetworkDetectionPage, self).__init__(parent)39
39 self.app_name = app_name40 def __init__(self, *args, **kwargs):
40 self.setTitle(NETWORK_DETECTION_TITLE)41 super(NetworkDetectionPage, self).__init__(*args, **kwargs)
41 self.ui = network_detection_ui.Ui_Form()42 banner_pixmap = kwargs.pop('banner_pixmap', None)
42 self.ui.setupUi(self)
43 if banner_pixmap is not None:43 if banner_pixmap is not None:
44 self.ui.image_label.setPixmap(banner_pixmap)44 self.ui.image_label.setPixmap(banner_pixmap)
45 self.btn_try_again = None45 self.btn_try_again = None
4646
47 # pylint: disable=C010347 # pylint: disable=C0103
48
48 def initializePage(self):49 def initializePage(self):
49 """Set UI details."""50 """Set UI details."""
50 self.wizard()._next_id = None51 self.wizard()._next_id = None
@@ -70,6 +71,7 @@
70 self.btn_try_again.style().unpolish(self.btn_try_again)71 self.btn_try_again.style().unpolish(self.btn_try_again)
71 self.btn_try_again.style().polish(self.btn_try_again)72 self.btn_try_again.style().polish(self.btn_try_again)
72 self.wizard().customButtonClicked.connect(self.try_again)73 self.wizard().customButtonClicked.connect(self.try_again)
74
73 # pylint: enable=C010375 # pylint: enable=C0103
7476
75 @defer.inlineCallbacks77 @defer.inlineCallbacks
@@ -81,3 +83,10 @@
81 self.wizard()._next_id = self.wizard().SIGN_IN_PAGE_ID83 self.wizard()._next_id = self.wizard().SIGN_IN_PAGE_ID
82 self.wizard().next()84 self.wizard().next()
83 self.wizard()._next_id = None85 self.wizard()._next_id = None
86
87 def _set_translated_strings(self):
88 """Implement in each child."""
89 self.setTitle(NETWORK_DETECTION_TITLE)
90
91 def _connect_ui(self):
92 """Implement in each child."""
8493
=== modified file 'ubuntu_sso/qt/reset_password_page.py'
--- ubuntu_sso/qt/reset_password_page.py 2012-02-16 14:13:36 +0000
+++ ubuntu_sso/qt/reset_password_page.py 2012-02-24 17:28:19 +0000
@@ -18,15 +18,14 @@
1818
19from functools import partial19from functools import partial
2020
21from PyQt4.QtCore import SIGNAL21from PyQt4.QtCore import SIGNAL, pyqtSignal
22from PyQt4.QtCore import pyqtSignal
23from PyQt4.QtGui import QApplication22from PyQt4.QtGui import QApplication
24from twisted.internet import defer
2523
26from ubuntu_sso import NO_OP24from ubuntu_sso import NO_OP
27from ubuntu_sso.qt import build_general_error_message25from ubuntu_sso.logger import setup_logging
28from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage26from ubuntu_sso.qt import build_general_error_message, common
29from ubuntu_sso.qt import common27from ubuntu_sso.qt.sso_wizard_page import SSOWizardEnhancedEditPage
28from ubuntu_sso.qt.ui.reset_password_ui import Ui_ResetPasswordPage
30from ubuntu_sso.utils.ui import (29from ubuntu_sso.utils.ui import (
31 is_min_required_password,30 is_min_required_password,
32 PASSWORD1_ENTRY,31 PASSWORD1_ENTRY,
@@ -37,7 +36,6 @@
37 RESET_TITLE,36 RESET_TITLE,
38 RESET_SUBTITLE,37 RESET_SUBTITLE,
39)38)
40from ubuntu_sso.logger import setup_logging
4139
4240
43logger = setup_logging('ubuntu_sso.reset_password_page')41logger = setup_logging('ubuntu_sso.reset_password_page')
@@ -46,35 +44,19 @@
46class ResetPasswordPage(SSOWizardEnhancedEditPage):44class ResetPasswordPage(SSOWizardEnhancedEditPage):
47 """Widget used to allow the user change his password."""45 """Widget used to allow the user change his password."""
4846
47 ui_class = Ui_ResetPasswordPage
49 passwordChanged = pyqtSignal('QString')48 passwordChanged = pyqtSignal('QString')
5049
51 def __init__(self, ui, app_name=None, parent=None):50 @property
52 """Create a new instance."""51 def _signals(self):
53 super(ResetPasswordPage, self).__init__(ui, app_name, parent)52 """The signals to connect to the backend."""
54 self.ui.password_line_edit.textEdited.connect(53 result = {
55 lambda: common.password_assistance(self.ui.password_line_edit,
56 self.ui.password_assistance,
57 common.NORMAL))
58 self.ui.confirm_password_line_edit.textEdited.connect(
59 lambda: common.password_check_match(self.ui.password_line_edit,
60 self.ui.confirm_password_line_edit,
61 self.ui.password_assistance))
62 self._signals = {
63 'PasswordChanged':54 'PasswordChanged':
64 self._filter_by_app_name(self.on_password_changed),55 self._filter_by_app_name(self.on_password_changed),
65 'PasswordChangeError':56 'PasswordChangeError':
66 self._filter_by_app_name(self.on_password_change_error),57 self._filter_by_app_name(self.on_password_change_error),
67 }58 }
68 self.setup_page()59 return result
69
70 @defer.inlineCallbacks
71 def setup_page(self):
72 """Setup the widget components."""
73 self.backend = yield self.get_backend()
74 self._setup_signals()
75 self._set_translated_strings()
76 self._connect_ui()
77 self._add_line_edits_validations()
7860
79 def focus_changed(self, old, now):61 def focus_changed(self, old, now):
80 """Check who has the focus to activate password popups if necessary."""62 """Check who has the focus to activate password popups if necessary."""
@@ -136,6 +118,15 @@
136118
137 def _connect_ui(self):119 def _connect_ui(self):
138 """Connect the different ui signals."""120 """Connect the different ui signals."""
121 self.ui.password_line_edit.textEdited.connect(
122 lambda: common.password_assistance(self.ui.password_line_edit,
123 self.ui.password_assistance,
124 common.NORMAL))
125 self.ui.confirm_password_line_edit.textEdited.connect(
126 lambda: common.password_check_match(self.ui.password_line_edit,
127 self.ui.confirm_password_line_edit,
128 self.ui.password_assistance))
129
139 self.ui.reset_password_button.clicked.connect(130 self.ui.reset_password_button.clicked.connect(
140 self.set_new_password)131 self.set_new_password)
141 self.ui.reset_code_line_edit.textChanged.connect(self._validate)132 self.ui.reset_code_line_edit.textChanged.connect(self._validate)
@@ -143,6 +134,8 @@
143 self.ui.confirm_password_line_edit.textChanged.connect(134 self.ui.confirm_password_line_edit.textChanged.connect(
144 self._validate)135 self._validate)
145136
137 self._add_line_edits_validations()
138
146 def _validate(self):139 def _validate(self):
147 """Enable the submit button if data is valid."""140 """Enable the submit button if data is valid."""
148 enabled = True141 enabled = True
149142
=== modified file 'ubuntu_sso/qt/setup_account_page.py'
--- ubuntu_sso/qt/setup_account_page.py 2012-02-24 14:58:30 +0000
+++ ubuntu_sso/qt/setup_account_page.py 2012-02-24 17:28:19 +0000
@@ -29,13 +29,16 @@
29# pylint: enable=F040129# pylint: enable=F0401
3030
31from PyQt4 import QtGui, QtCore31from PyQt4 import QtGui, QtCore
32from twisted.internet import defer
3332
34from ubuntu_sso import NO_OP33from ubuntu_sso import NO_OP
35from ubuntu_sso.qt import build_general_error_message34from ubuntu_sso.logger import setup_logging
36from ubuntu_sso.qt import common35from ubuntu_sso.qt import (
37from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage36 build_general_error_message,
38from ubuntu_sso.qt import enhanced_check_box37 common,
38 enhanced_check_box,
39)
40from ubuntu_sso.qt.sso_wizard_page import SSOWizardEnhancedEditPage
41from ubuntu_sso.qt.ui.setup_account_ui import Ui_SetUpAccountPage
39from ubuntu_sso.utils.ui import (42from ubuntu_sso.utils.ui import (
40 AGREE_TO_PRIVACY_POLICY,43 AGREE_TO_PRIVACY_POLICY,
41 AGREE_TO_TERMS,44 AGREE_TO_TERMS,
@@ -71,12 +74,10 @@
71 TERMS_TEXT,74 TERMS_TEXT,
72 TITLE,75 TITLE,
73)76)
74from ubuntu_sso.logger import setup_logging
7577
7678
77logger = setup_logging('ubuntu_sso.setup_account_page')79logger = setup_logging('ubuntu_sso.setup_account_page')
7880
79# pylint: disable=C0103
80ERROR = u'<font color="#df2d1f"><b> %s </b></font>'81ERROR = u'<font color="#df2d1f"><b> %s </b></font>'
81TITLE_STYLE = "<span style=\"font-size:24px\">%s</span>"82TITLE_STYLE = "<span style=\"font-size:24px\">%s</span>"
8283
@@ -92,47 +93,21 @@
92class SetupAccountPage(SSOWizardEnhancedEditPage):93class SetupAccountPage(SSOWizardEnhancedEditPage):
93 """Customized Setup Account page for SSO."""94 """Customized Setup Account page for SSO."""
9495
96 ui_class = Ui_SetUpAccountPage
95 userRegistered = QtCore.pyqtSignal('QString', 'QString')97 userRegistered = QtCore.pyqtSignal('QString', 'QString')
9698
97 def __init__(self, ui, subtitle, toc_link, policy_link, *args, **kwargs):99 def __init__(self, *args, **kwargs):
98 super(SetupAccountPage, self).__init__(ui, *args, **kwargs)100 self.captcha_file = None
99 self._subtitle = subtitle
100 self.captcha_id = None101 self.captcha_id = None
101 self.captcha_file = None102 self.captcha_received = False
102 self.ui.captcha_view.setPixmap(QtGui.QPixmap())
103 self.ui.password_edit.textEdited.connect(
104 lambda: common.password_assistance(self.ui.password_edit,
105 self.ui.password_assistance,
106 common.NORMAL))
107
108 if toc_link:
109 terms_links = TERMS_LINK.format(toc_link=toc_link,
110 terms_text=TERMS_TEXT)
111 if policy_link:
112 privacy_policy_link = PRIVACY_POLICY_LINK.format(
113 policy_link=policy_link,
114 privacy_policy_text=PRIVACY_POLICY_TEXT)
115
116 terms = ''
117 if toc_link and policy_link:
118 terms = AGREE_TO_TERMS_AND_PRIVACY_POLICY.format(
119 app_name=self.app_name,
120 terms_and_conditions=terms_links,
121 privacy_policy=privacy_policy_link)
122 elif toc_link:
123 terms = AGREE_TO_TERMS.format(app_name=self.app_name,
124 terms_and_conditions=terms_links)
125 elif policy_link:
126 terms = AGREE_TO_PRIVACY_POLICY.format(app_name=self.app_name,
127 privacy_policy=privacy_policy_link)
128
129 self.terms_checkbox = enhanced_check_box.EnhancedCheckBox(terms)
130 self.ui.hlayout_check.addWidget(self.terms_checkbox)
131 self.terms_checkbox.setVisible(bool(toc_link or policy_link))
132
133 self.set_up_button = None103 self.set_up_button = None
134 self.captcha_received = False104 self.terms_checkbox = None
135 self._signals = {105 super(SetupAccountPage, self).__init__(*args, **kwargs)
106
107 @property
108 def _signals(self):
109 """The signals to connect to the backend."""
110 result = {
136 'CaptchaGenerated':111 'CaptchaGenerated':
137 self._filter_by_app_name(self.on_captcha_generated),112 self._filter_by_app_name(self.on_captcha_generated),
138 'CaptchaGenerationError':113 'CaptchaGenerationError':
@@ -142,31 +117,16 @@
142 'UserRegistrationError':117 'UserRegistrationError':
143 self._filter_by_app_name(self.on_user_registration_error),118 self._filter_by_app_name(self.on_user_registration_error),
144 }119 }
145 self.setup_page()120 return result
146
147 @defer.inlineCallbacks
148 def setup_page(self):
149 """Setup the widget components."""
150 # request the backend to be used with the ui
151 self.backend = yield self.get_backend()
152 # set the callbacks for the captcha generation
153 self._setup_signals()
154 self._connect_ui_elements()
155 self._refresh_captcha()
156 self._set_translated_strings()
157 self._set_line_edits_validations()
158 self._register_fields()
159121
160 # Invalid name "initializePage"122 # Invalid name "initializePage"
161 # pylint: disable=C0103123 # pylint: disable=C0103
162124
163 def initializePage(self):125 def initializePage(self):
164 """Setup UI details."""126 """Setup UI details."""
165 # We need to override some texts from SSO
166 # to match our spec
167 title_page = TITLE_STYLE % TITLE.format(app_name=self.app_name)127 title_page = TITLE_STYLE % TITLE.format(app_name=self.app_name)
168 self.setTitle(title_page)128 self.setTitle(title_page)
169 self.setSubTitle(self._subtitle)129 self.setSubTitle(self.help_text)
170 # Set Setup Account button130 # Set Setup Account button
171 self.wizard().setOption(QtGui.QWizard.HaveCustomButton3, True)131 self.wizard().setOption(QtGui.QWizard.HaveCustomButton3, True)
172 try:132 try:
@@ -199,7 +159,8 @@
199 self.ui.confirm_email_assistance.setVisible(False)159 self.ui.confirm_email_assistance.setVisible(False)
200 self.ui.password_assistance.setVisible(False)160 self.ui.password_assistance.setVisible(False)
201 self.ui.refresh_label.setVisible(True)161 self.ui.refresh_label.setVisible(True)
202 #pylint: enable=C0103162
163 # pylint: enable=C0103
203164
204 def _set_translated_strings(self):165 def _set_translated_strings(self):
205 """Set the strings."""166 """Set the strings."""
@@ -218,6 +179,33 @@
218 self.ui.refresh_label.setText(CAPTCHA_RELOAD_MESSAGE %179 self.ui.refresh_label.setText(CAPTCHA_RELOAD_MESSAGE %
219 {'reload_link': link})180 {'reload_link': link})
220181
182 if self.tc_url:
183 terms_links = TERMS_LINK.format(toc_link=self.tc_url,
184 terms_text=TERMS_TEXT)
185 if self.policy_url:
186 privacy_policy_link = PRIVACY_POLICY_LINK.format(
187 policy_link=self.policy_url,
188 privacy_policy_text=PRIVACY_POLICY_TEXT)
189
190 terms = ''
191 if self.tc_url and self.policy_url:
192 terms = AGREE_TO_TERMS_AND_PRIVACY_POLICY.format(
193 app_name=self.app_name,
194 terms_and_conditions=terms_links,
195 privacy_policy=privacy_policy_link)
196 elif self.tc_url:
197 terms = AGREE_TO_TERMS.format(app_name=self.app_name,
198 terms_and_conditions=terms_links)
199 elif self.policy_url:
200 terms = AGREE_TO_PRIVACY_POLICY.format(app_name=self.app_name,
201 privacy_policy=privacy_policy_link)
202
203 self.terms_checkbox = enhanced_check_box.EnhancedCheckBox(terms)
204 self.ui.hlayout_check.addWidget(self.terms_checkbox)
205 self.terms_checkbox.setVisible(bool(self.tc_url or self.policy_url))
206
207 self._register_fields()
208
221 def _set_line_edits_validations(self):209 def _set_line_edits_validations(self):
222 """Set the validations to be performed on the edits."""210 """Set the validations to be performed on the edits."""
223 logger.debug('SetUpAccountPage._set_line_edits_validations')211 logger.debug('SetUpAccountPage._set_line_edits_validations')
@@ -240,9 +228,17 @@
240 self.ui.password_edit.textChanged.connect(228 self.ui.password_edit.textChanged.connect(
241 self.ui.confirm_password_edit.textChanged.emit)229 self.ui.confirm_password_edit.textChanged.emit)
242230
243 def _connect_ui_elements(self):231 def _connect_ui(self):
244 """Set the connection of signals."""232 """Set the connection of signals."""
245 logger.debug('SetUpAccountPage._connect_ui_elements')233 logger.debug('SetUpAccountPage._connect_ui')
234 self._set_line_edits_validations()
235
236 self.ui.captcha_view.setPixmap(QtGui.QPixmap())
237 self.ui.password_edit.textEdited.connect(
238 lambda: common.password_assistance(self.ui.password_edit,
239 self.ui.password_assistance,
240 common.NORMAL))
241
246 self.ui.refresh_label.linkActivated.connect(lambda url: \242 self.ui.refresh_label.linkActivated.connect(lambda url: \
247 self._refresh_captcha())243 self._refresh_captcha())
248 # We need to check if we enable the button on many signals244 # We need to check if we enable the button on many signals
@@ -257,6 +253,8 @@
257 self._enable_setup_button)253 self._enable_setup_button)
258 self.terms_checkbox.stateChanged.connect(self._enable_setup_button)254 self.terms_checkbox.stateChanged.connect(self._enable_setup_button)
259255
256 self._refresh_captcha()
257
260 def _enable_setup_button(self):258 def _enable_setup_button(self):
261 """Only enable the setup button if the form is valid."""259 """Only enable the setup button if the form is valid."""
262 name = unicode(self.ui.name_edit.text()).strip()260 name = unicode(self.ui.name_edit.text()).strip()
@@ -393,7 +391,6 @@
393 self.message_box.critical(self, self.app_name, '\n'.join(messages))391 self.message_box.critical(self, self.app_name, '\n'.join(messages))
394 return condition392 return condition
395393
396 # pylint: disable=W0212
397 def set_next_validation(self):394 def set_next_validation(self):
398 """Set the validation as the next page."""395 """Set the validation as the next page."""
399 logger.debug('SetUpAccountPage.set_next_validation')396 logger.debug('SetUpAccountPage.set_next_validation')
@@ -413,7 +410,6 @@
413 f(*args, reply_handler=NO_OP, error_handler=error_handler)410 f(*args, reply_handler=NO_OP, error_handler=error_handler)
414 # Update validation page's title, which contains the email411 # Update validation page's title, which contains the email
415 self.userRegistered.emit(email, password)412 self.userRegistered.emit(email, password)
416 # pylint: enable=W0212
417413
418 def is_correct_email(self, email_address):414 def is_correct_email(self, email_address):
419 """Return if the email is correct."""415 """Return if the email is correct."""
@@ -484,7 +480,8 @@
484 label.setText(ERROR % msg)480 label.setText(ERROR % msg)
485 label.setVisible(True)481 label.setVisible(True)
486482
487 #pylint: disable=C0103483 # pylint: disable=C0103
484
488 def showEvent(self, event):485 def showEvent(self, event):
489 """Set set_up_button as default button when the page is shown."""486 """Set set_up_button as default button when the page is shown."""
490 # This method should stays here because if we move it to initializePage487 # This method should stays here because if we move it to initializePage
@@ -514,7 +511,8 @@
514 except TypeError:511 except TypeError:
515 pass512 pass
516 super(SetupAccountPage, self).hideEvent(event)513 super(SetupAccountPage, self).hideEvent(event)
517 #pylint: enable=C0103514
515 # pylint: enable=C0103
518516
519 def on_captcha_refreshing(self):517 def on_captcha_refreshing(self):
520 """Show overlay when captcha is refreshing."""518 """Show overlay when captcha is refreshing."""
521519
=== removed file 'ubuntu_sso/qt/sign_in_page.py'
--- ubuntu_sso/qt/sign_in_page.py 2012-02-17 18:43:17 +0000
+++ ubuntu_sso/qt/sign_in_page.py 1970-01-01 00:00:00 +0000
@@ -1,97 +0,0 @@
1# -*- coding: utf-8 -*-
2#
3# Copyright 2012 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""Page to allow the user to sign in."""
18
19from PyQt4 import QtGui, QtCore
20
21from ubuntu_sso.qt.gui import SSOWizardPage
22from ubuntu_sso.logger import setup_logging
23from ubuntu_sso.utils.ui import (
24 CLOSE_AND_SETUP_LATER,
25 EXISTING_ACCOUNT_CHOICE_BUTTON,
26 SET_UP_ACCOUNT_CHOICE_BUTTON,
27)
28
29
30logger = setup_logging('ubuntu_sso.sing_in_page')
31
32
33class SignInPage(SSOWizardPage):
34 """Wizard Page that lets the user Sign into Ubuntu Single Sign On."""
35
36 existingAccountSelected = QtCore.pyqtSignal()
37 newAccountSelected = QtCore.pyqtSignal()
38 singInCanceled = QtCore.pyqtSignal()
39
40 def __init__(self, ui, image_pixmap, *args, **kwargs):
41 super(SignInPage, self).__init__(ui, *args, **kwargs)
42 self.ui.image_label.setPixmap(image_pixmap)
43 self._set_up_translated_strings()
44 self._connect_buttons()
45
46 def _set_up_translated_strings(self):
47 """Set the correct strings for the UI."""
48 logger.debug('SingInPage._set_up_translated_strings')
49 self.ui.message_label.setText('')
50 self.ui.existing_account_button.setText(
51 EXISTING_ACCOUNT_CHOICE_BUTTON)
52 self.ui.setup_account_button.setText(
53 SET_UP_ACCOUNT_CHOICE_BUTTON)
54
55 def _connect_buttons(self):
56 """Connect the buttons to the actions to perform."""
57 logger.debug('SingInPage._connect_buttons')
58 self.ui.existing_account_button.clicked.connect(
59 self._set_next_existing)
60 self.ui.setup_account_button.clicked.connect(self._set_next_new)
61
62 def _set_next_existing(self):
63 """Set the next id and fire signal."""
64 logger.debug('SignInPage._set_next_existing')
65 self.existingAccountSelected.emit()
66
67 def _set_next_new(self):
68 """Set the next id and fire signal."""
69 logger.debug('SignInPage._set_next_new')
70 self.newAccountSelected.emit()
71
72 # Invalid names of Qt-inherited methods
73 # pylint: disable=C0103
74
75 def initializePage(self):
76 """Setup UI details."""
77 self.ui.cancel_button.setText(CLOSE_AND_SETUP_LATER)
78 self.ui.cancel_button.clicked.connect(self.singInCanceled.emit)
79 # Layout without custom button 1,
80 # without finish button
81 # without cancel
82 self.wizard().setButtonLayout([
83 QtGui.QWizard.Stretch,
84 QtGui.QWizard.NextButton])
85
86 def showEvent(self, event):
87 """Set existing_account_button as default when the page is shown."""
88 super(SignInPage, self).showEvent(event)
89 self.ui.existing_account_button.setDefault(True)
90 self.ui.existing_account_button.style().unpolish(
91 self.ui.existing_account_button)
92 self.ui.existing_account_button.style().polish(
93 self.ui.existing_account_button)
94
95 def nextId(self):
96 """Provide the next id."""
97 return self.next
980
=== renamed file 'ubuntu_sso/qt/gui.py' => 'ubuntu_sso/qt/sso_wizard_page.py'
--- ubuntu_sso/qt/gui.py 2012-02-23 20:16:46 +0000
+++ ubuntu_sso/qt/sso_wizard_page.py 2012-02-24 17:28:19 +0000
@@ -35,13 +35,13 @@
35from twisted.internet import defer35from twisted.internet import defer
3636
37from ubuntu_sso import main37from ubuntu_sso import main
38from ubuntu_sso.logger import setup_logging
38from ubuntu_sso.qt import PREFERED_UI_SIZE39from ubuntu_sso.qt import PREFERED_UI_SIZE
39from ubuntu_sso.qt.loadingoverlay import LoadingOverlay40from ubuntu_sso.qt.loadingoverlay import LoadingOverlay
40from ubuntu_sso.logger import setup_logging
41from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR41from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR
4242
4343
44logger = setup_logging('ubuntu_sso.gui')44logger = setup_logging('ubuntu_sso.sso_wizard_page')
4545
4646
47class Header(QFrame):47class Header(QFrame):
@@ -92,32 +92,53 @@
92class SSOWizardPage(QWizardPage):92class SSOWizardPage(QWizardPage):
93 """Root class for all wizard pages."""93 """Root class for all wizard pages."""
9494
95 def __init__(self, ui, app_name=None, title='', subtitle='', parent=None):95 ui_class = None
96 _signals = {} # override in children
97
98 def __init__(self, app_name, **kwargs):
96 """Create a new instance."""99 """Create a new instance."""
97 super(SSOWizardPage, self).__init__(parent)100 parent = kwargs.pop('parent', None)
98 self.ui = ui101 super(SSOWizardPage, self).__init__(parent=parent)
99 self.ui.setupUi(self)102
103 self.ui = None
104 if self.ui_class is not None:
105 # self.ui_class is not callable, pylint: disable=E1102
106 self.ui = self.ui_class()
107 self.ui.setupUi(self)
108
100 self.overlay = LoadingOverlay(self)109 self.overlay = LoadingOverlay(self)
101 self.overlay.hide()110 self.overlay.hide()
111
112 # store common useful data provided by the app
102 self.app_name = app_name113 self.app_name = app_name
114 self.ping_url = kwargs.get('ping_url', '')
115 self.tc_url = kwargs.get('tc_url', '')
116 self.policy_url = kwargs.get('policy_url', '')
117 self.help_text = kwargs.get('help_text', '')
118
103 self.header = Header()119 self.header = Header()
104 self.header.set_title(title)120 self.header.set_title(title='')
105 self.header.set_subtitle(subtitle)121 self.header.set_subtitle(subtitle='')
106 self.layout().insertWidget(0, self.header)122 self.layout().insertWidget(0, self.header)
123
107 self.message_box = QMessageBox124 self.message_box = QMessageBox
108 self._signals = {}
109 self._signals_receivers = {}125 self._signals_receivers = {}
110 self.backend = None126 self.backend = None
111127
128 self.setup_page()
129
112 @defer.inlineCallbacks130 @defer.inlineCallbacks
113 def get_backend(self):131 def setup_page(self):
114 """Return the backend used by the controller."""132 """Setup the widget components."""
115 if self.backend is None:133 client = yield main.get_sso_client()
116 client = yield main.get_sso_client()134 self.backend = client.sso_login
117 self.backend = client.sso_login135
118 defer.returnValue(self.backend)136 self._setup_signals()
137 self._set_translated_strings()
138 self._connect_ui()
119139
120 # pylint: disable=C0103140 # pylint: disable=C0103
141
121 def resizeEvent(self, event):142 def resizeEvent(self, event):
122 """Resize the overlay to fit all the widget."""143 """Resize the overlay to fit all the widget."""
123 QWizardPage.resizeEvent(self, event)144 QWizardPage.resizeEvent(self, event)
@@ -130,6 +151,7 @@
130 def setSubTitle(self, subtitle=''):151 def setSubTitle(self, subtitle=''):
131 """Set the Wizard Page Subtitle."""152 """Set the Wizard Page Subtitle."""
132 self.header.set_subtitle(subtitle)153 self.header.set_subtitle(subtitle)
154
133 # pylint: enable=C0103155 # pylint: enable=C0103
134156
135 def _filter_by_app_name(self, f):157 def _filter_by_app_name(self, f):
@@ -160,6 +182,14 @@
160 match = self.backend.connect_to_signal(signal, method)182 match = self.backend.connect_to_signal(signal, method)
161 self._signals_receivers[signal] = match183 self._signals_receivers[signal] = match
162184
185 def _set_translated_strings(self):
186 """Implement in each child."""
187 raise NotImplementedError()
188
189 def _connect_ui(self):
190 """Implement in each child."""
191 raise NotImplementedError()
192
163 def _handle_error(self, remote_call, handler, error):193 def _handle_error(self, remote_call, handler, error):
164 """Handle any error when calling the remote backend."""194 """Handle any error when calling the remote backend."""
165 logger.error('Remote call %r failed with: %r', remote_call, error)195 logger.error('Remote call %r failed with: %r', remote_call, error)
@@ -210,11 +240,14 @@
210class SSOWizardEnhancedEditPage(SSOWizardPage):240class SSOWizardEnhancedEditPage(SSOWizardPage):
211 """Page that contains enhanced line edits."""241 """Page that contains enhanced line edits."""
212242
213 def __init__(self, ui, app_name=None, parent=None):243 # Method '_connect_ui', '_set_translated_strings' is abstract in class
244 # 'SSOWizardPage' but is not overridden
245 # pylint: disable=W0223
246
247 def __init__(self, *args, **kwargs):
214 """Create a new instance."""248 """Create a new instance."""
215 self._enhanced_edits = {}249 self._enhanced_edits = {}
216 super(SSOWizardEnhancedEditPage, self).__init__(ui,250 super(SSOWizardEnhancedEditPage, self).__init__(*args, **kwargs)
217 app_name=app_name, parent=parent)
218251
219 def set_line_edit_validation_rule(self, edit, cb):252 def set_line_edit_validation_rule(self, edit, cb):
220 """Set a new enhanced edit so that we can show an icon."""253 """Set a new enhanced edit so that we can show an icon."""
221254
=== modified file 'ubuntu_sso/qt/success_page.py'
--- ubuntu_sso/qt/success_page.py 2012-02-13 18:08:13 +0000
+++ ubuntu_sso/qt/success_page.py 2012-02-24 17:28:19 +0000
@@ -16,15 +16,24 @@
1616
17"""Success page UI."""17"""Success page UI."""
1818
19from ubuntu_sso.qt.gui import SSOWizardPage19from PyQt4 import QtGui
20
21from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage
22from ubuntu_sso.qt.ui.success_message_ui import Ui_SuccessPage
20from ubuntu_sso.utils.ui import SUCCESS23from ubuntu_sso.utils.ui import SUCCESS
2124
2225
23class SuccessPage(SSOWizardPage):26class SuccessPage(SSOWizardPage):
24 """Page used to display success message."""27 """Page used to display success message."""
2528
26 def __init__(self, ui, image_pixmap, *args, **kwargs):29 ui_class = Ui_SuccessPage
27 super(SuccessPage, self).__init__(ui, *args, **kwargs)30
28 self.ui.image_label.setPixmap(image_pixmap)31 def _set_translated_strings(self):
32 """Set proper strings to widgets."""
33 # we may want to customize the image_label in some future
34 self.ui.image_label.setPixmap(QtGui.QPixmap())
29 message = SUCCESS % {'app_name': self.app_name}35 message = SUCCESS % {'app_name': self.app_name}
30 self.ui.success_message_body.setText(message)36 self.ui.success_message_body.setText(message)
37
38 def _connect_ui(self):
39 """Nothing to connect."""
3140
=== modified file 'ubuntu_sso/qt/tests/__init__.py'
--- ubuntu_sso/qt/tests/__init__.py 2012-02-15 17:33:40 +0000
+++ ubuntu_sso/qt/tests/__init__.py 2012-02-24 17:28:19 +0000
@@ -19,20 +19,30 @@
19from PyQt4 import QtGui, QtCore19from PyQt4 import QtGui, QtCore
20from twisted.internet import defer20from twisted.internet import defer
21from twisted.trial.unittest import TestCase21from twisted.trial.unittest import TestCase
22from ubuntu_sso.qt import loadingoverlay
2322
24from ubuntu_sso import (23from ubuntu_sso import main, NO_OP
25 main,24from ubuntu_sso.qt import sso_wizard_page
26 NO_OP,25from ubuntu_sso.tests import (
26 APP_NAME,
27 HELP_TEXT,
28 PING_URL,
29 POLICY_URL,
30 TC_URL,
31 WINDOW_ID,
27)32)
2833
34KWARGS = dict(app_name=APP_NAME, help_text=HELP_TEXT, ping_url=PING_URL,
35 policy_url=POLICY_URL, tc_url=TC_URL, window_id=WINDOW_ID)
36
37# is ok to access private method/attrs in tests
38# pylint: disable=W0212
39
2940
30class FakedObject(object):41class FakedObject(object):
31 """Fake an object, record every call."""42 """Fake an object, record every call."""
3243
33 next_result = None44 next_result = None
34 exposed_methods = ['connect_to_signal',45 exposed_methods = []
35 'generate_captcha', 'request_password_reset_token']
3646
37 def __init__(self, *args, **kwargs):47 def __init__(self, *args, **kwargs):
38 self._args = args48 self._args = args
@@ -52,10 +62,26 @@
52 return inner62 return inner
5363
5464
65class FakedSSOLoginBackend(FakedObject):
66 """A faked sso_login backend."""
67
68 exposed_methods = [
69 'connect_to_signal',
70 'generate_captcha',
71 'login',
72 'login_and_ping',
73 'register_user',
74 'request_password_reset_token',
75 'set_new_password',
76 'validate_email',
77 'validate_email_and_ping',
78 ]
79
80
55class FakedBackend(object):81class FakedBackend(object):
56 """A faked backend."""82 """A faked backend."""
5783
58 sso_login = FakedObject()84 sso_login = FakedSSOLoginBackend()
5985
6086
61class FakePageUiStyle(object):87class FakePageUiStyle(object):
@@ -203,7 +229,7 @@
203 self.overlay = FakeOverlay()229 self.overlay = FakeOverlay()
204 self.local_folders_page = FakeWizardPage()230 self.local_folders_page = FakeWizardPage()
205 self.folders_page = FakeWizardPage()231 self.folders_page = FakeWizardPage()
206 self.app_name = 'app_name'232 self.app_name = APP_NAME
207233
208 def show(self):234 def show(self):
209 """Fake method."""235 """Fake method."""
@@ -250,6 +276,7 @@
250276
251277
252class FakeWizard(object):278class FakeWizard(object):
279
253 """Replace wizard() function on wizard pages."""280 """Replace wizard() function on wizard pages."""
254281
255 customButtonClicked = QtCore.QObject()282 customButtonClicked = QtCore.QObject()
@@ -374,6 +401,12 @@
374class BaseTestCase(TestCase):401class BaseTestCase(TestCase):
375 """The base test case."""402 """The base test case."""
376403
404 kwargs = None
405 ui_class = None
406 ui_signals = ()
407 ui_backend_signals = ()
408 ui_wizard_class = FakeWizard
409
377 @defer.inlineCallbacks410 @defer.inlineCallbacks
378 def setUp(self):411 def setUp(self):
379 yield super(BaseTestCase, self).setUp()412 yield super(BaseTestCase, self).setUp()
@@ -383,11 +416,31 @@
383 self.patch(main, 'get_sso_client',416 self.patch(main, 'get_sso_client',
384 lambda *a: defer.succeed(backend))417 lambda *a: defer.succeed(backend))
385418
419 self.patch(sso_wizard_page, 'LoadingOverlay', FakeOverlay)
420
421 self.app_name = APP_NAME
422 self.ping_url = PING_URL
423 self.signals_results = []
424
425 # self.ui_class is not callable
426 # pylint: disable=E1102, C0103, W0212
427 self.ui = None
428 self.wizard = None
429 if self.ui_class is not None:
430 kwargs = dict(KWARGS) if self.kwargs is None else self.kwargs
431 self.ui = self.ui_class(**kwargs)
432
433 for signal in self.ui_signals:
434 self.patch(self.ui_class, signal, FakeSignal())
435
436 if self.ui_wizard_class is not None:
437 self.wizard = self.ui_wizard_class()
438 self.patch(self.ui, 'wizard', lambda: self.wizard)
439
386 def _set_called(self, *args, **kwargs):440 def _set_called(self, *args, **kwargs):
387 """Store 'args' and 'kwargs' for test assertions."""441 """Store 'args' and 'kwargs' for test assertions."""
388 self._called = (args, kwargs)442 self._called = (args, kwargs)
389443
390 # pylint: disable=E1101, W0212
391 def assert_backend_called(self, method, *args, **kwargs):444 def assert_backend_called(self, method, *args, **kwargs):
392 """Check that 'method(*args, **kwargs)' was called in the backend."""445 """Check that 'method(*args, **kwargs)' was called in the backend."""
393 self.assertIn(method, self.ui.backend._called)446 self.assertIn(method, self.ui.backend._called)
@@ -402,34 +455,6 @@
402 self.assertEqual(error_handler.func, self.ui._handle_error)455 self.assertEqual(error_handler.func, self.ui._handle_error)
403456
404 self.assertEqual(call[1], kwargs)457 self.assertEqual(call[1], kwargs)
405 # pylint: enable=E1101, W0212
406
407
408class BaseTestCaseUI(TestCase):
409 """Base Test Case."""
410
411 class_ui = None
412 kwargs = {}
413
414 @defer.inlineCallbacks
415 def setUp(self):
416 yield super(BaseTestCaseUI, self).setUp()
417 # self.class_ui is not callable
418 # pylint: disable=E1102, C0103, W0212
419 self.ui = None
420 self._called = False
421 if self.class_ui is not None:
422 self.ui = self.class_ui(**self.kwargs)
423
424 if hasattr(self.ui, 'backend'):
425 # clean backend calls
426 self.ui.backend._called.clear()
427
428 self.patch(loadingoverlay, 'LoadingOverlay', FakeOverlay)
429
430 def _set_called(self, *args, **kwargs):
431 """Store 'args' and 'kwargs' for test assertions."""
432 self._called = (args, kwargs)
433458
434 def get_pixmap_data(self, pixmap):459 def get_pixmap_data(self, pixmap):
435 """Get the raw data of a QPixmap."""460 """Get the raw data of a QPixmap."""
@@ -446,3 +471,30 @@
446 d1 = self.get_pixmap_data(pixmap1)471 d1 = self.get_pixmap_data(pixmap1)
447 d2 = self.get_pixmap_data(pixmap2)472 d2 = self.get_pixmap_data(pixmap2)
448 self.assertEqual(d1, d2)473 self.assertEqual(d1, d2)
474
475 # pylint: enable=C0103
476
477 @defer.inlineCallbacks
478 def test_setup_page(self):
479 """Test the backend signal connection."""
480 if self.ui is None or getattr(self.ui, 'setup_page', None) is None:
481 return
482
483 called = []
484 self.patch(self.ui, '_setup_signals',
485 lambda *a: called.append('_setup_signals'))
486 self.patch(self.ui, '_connect_ui',
487 lambda *a: called.append('_connect_ui'))
488 self.patch(self.ui, '_set_translated_strings',
489 lambda *a: called.append('_set_translated_strings'))
490
491 yield self.ui.setup_page()
492
493 self.assertEqual(self.ui.backend, self.sso_login_backend)
494
495 for signal in self.ui_backend_signals:
496 self.assertIn(signal, self.ui._signals)
497 self.assertTrue(callable(self.ui._signals[signal]))
498
499 expected = ['_setup_signals', '_set_translated_strings', '_connect_ui']
500 self.assertEqual(expected, called)
449501
=== 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-02-16 18:40:41 +0000
+++ ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-02-24 17:28:19 +0000
@@ -17,78 +17,22 @@
17"""Tests for the Setup Account page Qt UI."""17"""Tests for the Setup Account page Qt UI."""
1818
19from PyQt4 import QtGui, QtCore19from PyQt4 import QtGui, QtCore
20from twisted.internet import defer
2120
22from ubuntu_sso.qt import gui
23from ubuntu_sso.qt import current_user_sign_in_page21from ubuntu_sso.qt import current_user_sign_in_page
24from ubuntu_sso.qt.tests import (22from ubuntu_sso.qt.tests import (
25 BaseTestCase,23 BaseTestCase,
26 FakedBackend,
27 FakedObject,
28 FakeOverlay,
29 FakePageUiStyle,24 FakePageUiStyle,
30 FakeSignal,
31 FakeWizard,
32 FakeWizardButtonStyle,25 FakeWizardButtonStyle,
33)26)
34from ubuntu_sso.qt.ui import current_user_sign_in_ui
3527
3628
37# pylint: disable=W021229# pylint: disable=W0212
38class CurrentUserSignInTestCase(BaseTestCase):30class CurrentUserSignInTestCase(BaseTestCase):
39 """Test the SetupAccountPage code."""31 """Test the SetupAccountPage code."""
4032
41 @defer.inlineCallbacks33 ui_class = current_user_sign_in_page.CurrentUserSignInPage
42 def setUp(self):34 ui_signals = ('userLoggedIn', 'passwordForgotten', 'userNotValidated')
43 yield super(CurrentUserSignInTestCase, self).setUp()35 ui_backend_signals = ('LoggedIn', 'LoginError', 'UserNotValidated')
44 self.patch(gui, "LoadingOverlay", FakeOverlay)
45 self.patch(gui.main, "get_sso_client", FakedBackend)
46 self.signals_results = []
47 self.patch(current_user_sign_in_page.CurrentUserSignInPage,
48 "userLoggedIn", FakeSignal())
49 self.patch(current_user_sign_in_page.CurrentUserSignInPage,
50 "passwordForgotten", FakeSignal())
51 self.patch(current_user_sign_in_page.CurrentUserSignInPage,
52 "userNotValidated", FakeSignal())
53 self.app_name = 'my_app'
54 self.ui = current_user_sign_in_page.CurrentUserSignInPage(
55 current_user_sign_in_ui.Ui_CurrentUserSignInPage(),
56 '',
57 app_name=self.app_name,
58 parent=None)
59 self.wizard = FakeWizard()
60 self.patch(self.ui, 'wizard', lambda: self.wizard)
61
62 def test_init(self):
63 """Test the construction of the object."""
64 self.assertIn('LoggedIn', self.ui._signals)
65 self.assertIn('LoginError', self.ui._signals)
66 self.assertIn('UserNotValidated', self.ui._signals)
67 self.assertTrue(callable(self.ui._signals['LoggedIn']))
68 self.assertTrue(callable(self.ui._signals['LoginError']))
69 self.assertTrue(callable(self.ui._signals['UserNotValidated']))
70 self.assertEqual(self.ui.backend, FakedBackend.sso_login)
71
72 # pylint: disable=E1101
73 def test_setup_page(self):
74 """Test that the backend is received and the methods are called."""
75 exposed_methods = [
76 '_set_translated_strings',
77 '_setup_signals',
78 '_connect_ui']
79 self.patch(FakedObject, "exposed_methods", exposed_methods)
80 faked_object = FakedObject()
81 self.patch(self.ui, "_set_translated_strings",
82 faked_object._set_translated_strings)
83 self.patch(self.ui, "_setup_signals",
84 faked_object._setup_signals)
85 self.patch(self.ui, "_connect_ui",
86 faked_object._connect_ui)
87 self.ui.setup_page()
88 self.assertIn('_set_translated_strings', faked_object._called)
89 self.assertIn('_setup_signals', faked_object._called)
90 self.assertIn('_connect_ui', faked_object._called)
91 # pylint: enable=E1101
9236
93 def test_on_user_not_validated(self):37 def test_on_user_not_validated(self):
94 """Test the navigation flow on user not validated."""38 """Test the navigation flow on user not validated."""
@@ -176,12 +120,6 @@
176120
177 def test_login_with_ping(self):121 def test_login_with_ping(self):
178 """Test the login method."""122 """Test the login method."""
179 ping = 'http://ping.me'
180 self.ui.ping_url = ping
181 exposed_methods = ['login', 'login_and_ping']
182 self.patch(FakedObject, "exposed_methods", exposed_methods)
183 faked_object = FakedObject()
184 self.patch(self.ui, "backend", faked_object)
185 email = 'valid@email'123 email = 'valid@email'
186 password = '123456'124 password = '123456'
187 self.ui.ui.email_edit.setText(email)125 self.ui.ui.email_edit.setText(email)
@@ -189,15 +127,11 @@
189 self.ui.login()127 self.ui.login()
190 self.assertEqual(self.ui.overlay.show_counter, 1)128 self.assertEqual(self.ui.overlay.show_counter, 1)
191 self.assert_backend_called('login_and_ping',129 self.assert_backend_called('login_and_ping',
192 self.app_name, email, password, ping)130 self.app_name, email, password, self.ping_url)
193131
194 def test_login_without_ping(self):132 def test_login_without_ping(self):
195 """Test the login method."""133 """Test the login method."""
196 self.ui.ping_url = ''134 self.ui.ping_url = ''
197 exposed_methods = ['login']
198 self.patch(FakedObject, "exposed_methods", exposed_methods)
199 faked_object = FakedObject()
200 self.patch(self.ui, "backend", faked_object)
201 email = 'valid@email'135 email = 'valid@email'
202 password = '123456'136 password = '123456'
203 self.ui.ui.email_edit.setText(email)137 self.ui.ui.email_edit.setText(email)
204138
=== modified file 'ubuntu_sso/qt/tests/test_email_verification.py'
--- ubuntu_sso/qt/tests/test_email_verification.py 2012-02-23 20:16:46 +0000
+++ ubuntu_sso/qt/tests/test_email_verification.py 2012-02-24 17:28:19 +0000
@@ -17,62 +17,23 @@
17"""Tests for the Setup Account page Qt UI."""17"""Tests for the Setup Account page Qt UI."""
1818
19from PyQt4 import QtGui, QtCore19from PyQt4 import QtGui, QtCore
20from twisted.internet import defer
2120
22from ubuntu_sso.qt import gui
23from ubuntu_sso.qt import email_verification_page21from ubuntu_sso.qt import email_verification_page
24from ubuntu_sso.qt.tests import (22from ubuntu_sso.qt.tests import (
25 BaseTestCase,23 BaseTestCase,
26 FakedBackend,
27 FakedObject,
28 FakePageUiStyle,24 FakePageUiStyle,
29 FakeSignal,
30 FakeWizard,
31)25)
32from ubuntu_sso.qt.ui import email_verification_ui26
3327# is ok to access private method/attrs in tests
34
35# pylint: disable=W021228# pylint: disable=W0212
29
30
36class EmailVerificationTestCase(BaseTestCase):31class EmailVerificationTestCase(BaseTestCase):
37 """Test the SetupAccountPage code."""32 """Test the SetupAccountPage code."""
3833
39 @defer.inlineCallbacks34 ui_class = email_verification_page.EmailVerificationPage
40 def setUp(self):35 ui_signals = ('registrationSuccess',)
41 yield super(EmailVerificationTestCase, self).setUp()36 ui_backend_signals = ('EmailValidated', 'EmailValidationError')
42 self.signals_results = []
43 self.patch(gui.main, "get_sso_client", FakedBackend)
44 self.patch(email_verification_page.EmailVerificationPage,
45 "registrationSuccess", FakeSignal())
46 self.ui = email_verification_page.EmailVerificationPage(
47 email_verification_ui.Ui_EmailVerificationPage(), '',
48 parent=None)
49 self.wizard = FakeWizard()
50 self.patch(self.ui, 'wizard', lambda: self.wizard)
51
52 def test_init(self):
53 """Test the construction of the object."""
54 self.assertIn('EmailValidated', self.ui._signals)
55 self.assertIn('EmailValidationError', self.ui._signals)
56 self.assertTrue(callable(self.ui._signals['EmailValidated']))
57 self.assertTrue(callable(self.ui._signals['EmailValidationError']))
58 self.assertEqual(self.ui.backend, FakedBackend.sso_login)
59
60 # pylint: disable=E1101
61 def test_setup_page(self):
62 """Test that the backend is received and the methods are called."""
63 exposed_methods = [
64 '_setup_signals',
65 '_connect_ui_elements']
66 self.patch(FakedObject, "exposed_methods", exposed_methods)
67 faked_object = FakedObject()
68 self.patch(self.ui, "_setup_signals",
69 faked_object._setup_signals)
70 self.patch(self.ui, "_connect_ui_elements",
71 faked_object._connect_ui_elements)
72 self.ui.setup_page()
73 self.assertIn('_setup_signals', faked_object._called)
74 self.assertIn('_connect_ui_elements', faked_object._called)
75 # pylint: enable=E1101
7637
77 def test_verification_code(self):38 def test_verification_code(self):
78 """Test the verification value returned."""39 """Test the verification value returned."""
@@ -87,9 +48,9 @@
87 self.assertEqual(value, self.ui.ui.next_button)48 self.assertEqual(value, self.ui.ui.next_button)
88 self.assertTrue(isinstance(value, QtGui.QPushButton))49 self.assertTrue(isinstance(value, QtGui.QPushButton))
8950
90 def test_connect_ui_elements(self):51 def test_connect_ui(self):
91 """Test the connect ui method."""52 """Test the connect ui method."""
92 self.ui._connect_ui_elements()53 self.ui._connect_ui()
93 # We expect 2 values because _connect_ui is called in the init too.54 # We expect 2 values because _connect_ui is called in the init too.
94 self.assertEqual(self.ui.ui.verification_code_edit.receivers(55 self.assertEqual(self.ui.ui.verification_code_edit.receivers(
95 QtCore.SIGNAL("textChanged(const QString&)")), 2)56 QtCore.SIGNAL("textChanged(const QString&)")), 2)
@@ -170,40 +131,29 @@
170131
171 def test_validate_email_with_ping(self):132 def test_validate_email_with_ping(self):
172 """Test the login method."""133 """Test the login method."""
173 ping = 'http://ping.me'
174 app_name = 'app_name'
175 email = 'email@example.com'134 email = 'email@example.com'
176 password = 'password'135 password = 'password'
177 code = 'code'136 code = 'code'
178 self.ui.ping_url = ping
179 self.ui.app_name = app_name
180 self.ui.email = email137 self.ui.email = email
181 self.ui.password = password138 self.ui.password = password
182 self.ui.ui.verification_code_edit.setText(code)139 self.ui.ui.verification_code_edit.setText(code)
183 exposed_methods = ['validate_email', 'validate_email_and_ping']140
184 self.patch(FakedObject, "exposed_methods", exposed_methods)
185 faked_object = FakedObject()
186 self.patch(self.ui, "backend", faked_object)
187 self.ui.validate_email()141 self.ui.validate_email()
142
188 self.assert_backend_called('validate_email_and_ping',143 self.assert_backend_called('validate_email_and_ping',
189 app_name, email, password, code, ping)144 self.app_name, email, password, code, self.ping_url)
190145
191 def test_validate_email_without_ping(self):146 def test_validate_email_without_ping(self):
192 """Test the login method."""147 """Test the login method."""
193 ping = ''148 self.ui.ping_url = ''
194 app_name = 'app_name'
195 email = 'email@example.com'149 email = 'email@example.com'
196 password = 'password'150 password = 'password'
197 code = 'code'151 code = 'code'
198 self.ui.ping_url = ping
199 self.ui.app_name = app_name
200 self.ui.email = email152 self.ui.email = email
201 self.ui.password = password153 self.ui.password = password
202 self.ui.ui.verification_code_edit.setText(code)154 self.ui.ui.verification_code_edit.setText(code)
203 exposed_methods = ['validate_email', 'validate_email_and_ping']155
204 self.patch(FakedObject, "exposed_methods", exposed_methods)
205 faked_object = FakedObject()
206 self.patch(self.ui, "backend", faked_object)
207 self.ui.validate_email()156 self.ui.validate_email()
157
208 self.assert_backend_called('validate_email',158 self.assert_backend_called('validate_email',
209 app_name, email, password, code)159 self.app_name, email, password, code)
210160
=== modified file 'ubuntu_sso/qt/tests/test_enchanced_line_edit.py'
--- ubuntu_sso/qt/tests/test_enchanced_line_edit.py 2012-01-26 15:34:16 +0000
+++ ubuntu_sso/qt/tests/test_enchanced_line_edit.py 2012-02-24 17:28:19 +0000
@@ -18,13 +18,10 @@
1818
19import collections19import collections
2020
21from PyQt4 import QtGui, QtCore
21from twisted.trial.unittest import TestCase22from twisted.trial.unittest import TestCase
2223
23# pylint: disable=E110124from ubuntu_sso.qt.sso_wizard_page import EnhancedLineEdit
24
25from PyQt4 import QtGui, QtCore
26
27from ubuntu_sso.qt.gui import EnhancedLineEdit
2825
2926
30class EnhancedLineEditTestCase(TestCase):27class EnhancedLineEditTestCase(TestCase):
3128
=== added file 'ubuntu_sso/qt/tests/test_error_page.py'
--- ubuntu_sso/qt/tests/test_error_page.py 1970-01-01 00:00:00 +0000
+++ ubuntu_sso/qt/tests/test_error_page.py 2012-02-24 17:28:19 +0000
@@ -0,0 +1,26 @@
1# -*- coding: utf-8 -*-
2#
3# Copyright 2012 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""Test the error page."""
18
19from ubuntu_sso.qt.error_page import ErrorPage
20from ubuntu_sso.qt.tests import BaseTestCase
21
22
23class ErrorPageTestCase(BaseTestCase):
24 """Test that the correct widgets are used."""
25
26 ui_class = ErrorPage
027
=== modified file 'ubuntu_sso/qt/tests/test_forgotten_password.py'
--- ubuntu_sso/qt/tests/test_forgotten_password.py 2012-02-18 15:12:09 +0000
+++ ubuntu_sso/qt/tests/test_forgotten_password.py 2012-02-24 17:28:19 +0000
@@ -17,48 +17,23 @@
17"""Tests for the Setup Account page Qt UI."""17"""Tests for the Setup Account page Qt UI."""
1818
19from PyQt4 import QtGui, QtCore19from PyQt4 import QtGui, QtCore
20from twisted.internet import defer
2120
22from ubuntu_sso.qt import gui
23from ubuntu_sso.qt import forgotten_password_page21from ubuntu_sso.qt import forgotten_password_page
24from ubuntu_sso.qt.tests import (22from ubuntu_sso.qt.tests import (
25 BaseTestCase,23 BaseTestCase,
26 FakedBackend,
27 FakedObject,
28 FakeOverlay,
29 FakePageUiStyle,24 FakePageUiStyle,
30 FakeSignal,
31 FakeWizard,
32)25)
33from ubuntu_sso.qt.ui import forgotten_password_ui26
3427# is ok to access private method/attrs in tests
35
36# pylint: disable=W0212, E110128# pylint: disable=W0212, E1101
29
30
37class ForgottenPasswordTestCase(BaseTestCase):31class ForgottenPasswordTestCase(BaseTestCase):
38 """Test the SetupAccountPage code."""32 """Test the SetupAccountPage code."""
3933
40 @defer.inlineCallbacks34 ui_class = forgotten_password_page.ForgottenPasswordPage
41 def setUp(self):35 ui_siganls = ('passwordResetTokenSent',)
42 yield super(ForgottenPasswordTestCase, self).setUp()36 ui_backend_siganls = ('PasswordResetTokenSent', 'PasswordResetError')
43 self.signals_results = []
44 self.patch(gui, "LoadingOverlay", FakeOverlay)
45 self.patch(gui.main, "get_sso_client", FakedBackend)
46 self.patch(forgotten_password_page.ForgottenPasswordPage,
47 "passwordResetTokenSent", FakeSignal())
48 self.app_name = 'my_app'
49 self.ui = forgotten_password_page.ForgottenPasswordPage(
50 forgotten_password_ui.Ui_ForgottenPasswordPage(),
51 app_name=self.app_name, parent=None)
52 self.wizard = FakeWizard()
53 self.patch(self.ui, 'wizard', lambda: self.wizard)
54
55 def test_init(self):
56 """Test the construction of the object."""
57 self.assertIn('PasswordResetTokenSent', self.ui._signals)
58 self.assertIn('PasswordResetError', self.ui._signals)
59 self.assertTrue(callable(self.ui._signals['PasswordResetTokenSent']))
60 self.assertTrue(callable(self.ui._signals['PasswordResetError']))
61 self.assertEqual(self.ui.backend, FakedBackend.sso_login)
6237
63 def test_request_new_password(self):38 def test_request_new_password(self):
64 """Test the request_new_password function."""39 """Test the request_new_password function."""
@@ -71,33 +46,6 @@
71 self.assert_backend_called('request_password_reset_token',46 self.assert_backend_called('request_password_reset_token',
72 app_name, email)47 app_name, email)
7348
74 def test_setup_page(self):
75 """Test that the backend is received and the methods are called."""
76 exposed_methods = [
77 '_setup_signals',
78 '_set_translated_strings',
79 '_connect_ui',
80 '_set_enhanced_line_edit',
81 '_register_fields']
82 self.patch(FakedObject, "exposed_methods", exposed_methods)
83 faked_object = FakedObject()
84 self.patch(self.ui, "_setup_signals",
85 faked_object._setup_signals)
86 self.patch(self.ui, "_set_translated_strings",
87 faked_object._set_translated_strings)
88 self.patch(self.ui, "_connect_ui",
89 faked_object._connect_ui)
90 self.patch(self.ui, "_set_enhanced_line_edit",
91 faked_object._set_enhanced_line_edit)
92 self.patch(self.ui, "_register_fields",
93 faked_object._register_fields)
94 self.ui.setup_page()
95 self.assertIn('_setup_signals', faked_object._called)
96 self.assertIn('_set_translated_strings', faked_object._called)
97 self.assertIn('_connect_ui', faked_object._called)
98 self.assertIn('_set_enhanced_line_edit', faked_object._called)
99 self.assertIn('_register_fields', faked_object._called)
100
101 def test_email_widget(self):49 def test_email_widget(self):
102 """Test the email_widget property."""50 """Test the email_widget property."""
103 value = self.ui.email_widget51 value = self.ui.email_widget
10452
=== modified file 'ubuntu_sso/qt/tests/test_loadingoverlay.py'
--- ubuntu_sso/qt/tests/test_loadingoverlay.py 2012-02-03 14:51:41 +0000
+++ ubuntu_sso/qt/tests/test_loadingoverlay.py 2012-02-24 17:28:19 +0000
@@ -1,5 +1,5 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
22#
3# Copyright 2012 Canonical Ltd.3# Copyright 2012 Canonical Ltd.
4#4#
5# This program is free software: you can redistribute it and/or modify it5# This program is free software: you can redistribute it and/or modify it
@@ -16,21 +16,21 @@
1616
17"""Tests for the Loading Overlay."""17"""Tests for the Loading Overlay."""
1818
19from ubuntu_sso.qt import loadingoverlay as gui19from ubuntu_sso.qt.loadingoverlay import LoadingOverlay
20from ubuntu_sso.qt.tests import BaseTestCase20from ubuntu_sso.qt.tests import BaseTestCase
2121
2222
23class LoadingOverlayTestCase(BaseTestCase):23class LoadingOverlayTestCase(BaseTestCase):
24 """Test the qt control panel."""24 """Test the qt control panel."""
2525
26 innerclass_ui = gui.loadingoverlay_ui26 kwargs = {}
27 innerclass_name = "Ui_Form"27 ui_class = LoadingOverlay
28 class_ui = gui.LoadingOverlay28 ui_wizard_class = None
2929
30 # pylint: disable=E110130 def test_status_correct(self):
31 def assert_status_correct(self):
32 """Test if the necessary variables for the animation exists"""31 """Test if the necessary variables for the animation exists"""
33 self.ui.show()32 self.ui.show()
33 self.addCleanup(self.ui.hide)
34
34 self.assertTrue(self.ui.counter is not None)35 self.assertTrue(self.ui.counter is not None)
35 self.assertTrue(self.ui.orientation is not None)36 self.assertTrue(self.ui.orientation is not None)
36 # pylint: enable=E1101
3737
=== modified file 'ubuntu_sso/qt/tests/test_network_detection.py'
--- ubuntu_sso/qt/tests/test_network_detection.py 2012-02-22 16:58:08 +0000
+++ ubuntu_sso/qt/tests/test_network_detection.py 2012-02-24 17:28:19 +0000
@@ -16,39 +16,28 @@
1616
17"""The test suite for Network Detection UI."""17"""The test suite for Network Detection UI."""
1818
19from twisted.internet import defer
20
21from PyQt4 import QtGui19from PyQt4 import QtGui
2220
23from ubuntu_sso.tests import APP_NAME
24from ubuntu_sso.qt import network_detection_page21from ubuntu_sso.qt import network_detection_page
25from ubuntu_sso.qt.tests import (22from ubuntu_sso.qt.tests import (
26 BaseTestCase,23 BaseTestCase,
27 FakeWizardButtonStyle,24 FakeWizardButtonStyle,
28)25)
2926
27# is ok to access private method/attrs in tests
28# pylint: disable=W0212, E1101
29
3030
31class NetworkDetectionTestCase(BaseTestCase):31class NetworkDetectionTestCase(BaseTestCase):
3232
33 """Test the CurrentUserController."""33 """Test the CurrentUserController."""
3434
35 @defer.inlineCallbacks35 ui_class = network_detection_page.NetworkDetectionPage
36 def setUp(self):36 ui_wizard_class = FakeWizardButtonStyle
37 """Initialize this test instance."""37
38 yield super(NetworkDetectionTestCase, self).setUp()
39 self.wizard = FakeWizardButtonStyle()
40 self.network_detection = network_detection_page.NetworkDetectionPage(
41 app_name=APP_NAME)
42 self.patch(self.network_detection, 'wizard', self._get_wizard)
43
44 def _get_wizard(self):
45 """Fake wizard method for wizard page."""
46 return self.wizard
47
48 # pylint: disable=W0212
49 def test_initialize_page(self):38 def test_initialize_page(self):
50 """Check Network detection initialize page."""39 """Check Network detection initialize page."""
51 self.network_detection.initializePage()40 self.ui.initializePage()
52 self.assertEqual(self.wizard._next_id, None)41 self.assertEqual(self.wizard._next_id, None)
53 self.assertTrue(('setButtonLayout', ([42 self.assertTrue(('setButtonLayout', ([
54 QtGui.QWizard.Stretch,43 QtGui.QWizard.Stretch,
@@ -58,18 +47,16 @@
5847
59 def test_initialize_page_button_property(self):48 def test_initialize_page_button_property(self):
60 """Test the Try Again button properties."""49 """Test the Try Again button properties."""
61 self.patch(self.network_detection,50 self.ui.initializePage()
62 "wizard", FakeWizardButtonStyle)51 self.assertTrue(self.ui.btn_try_again.isDefault())
63 self.network_detection.initializePage()52 self.assertIn('polish', self.ui.btn_try_again.data)
64 self.assertTrue(self.network_detection.btn_try_again.isDefault())53 self.assertIn('unpolish', self.ui.btn_try_again.data)
65 self.assertIn('polish', self.network_detection.btn_try_again.data)54 self.assertEqual(
66 self.assertIn('unpolish', self.network_detection.btn_try_again.data)55 self.ui.btn_try_again.data['polish'],
67 self.assertEqual(56 self.ui.btn_try_again)
68 self.network_detection.btn_try_again.data['polish'],57 self.assertEqual(
69 self.network_detection.btn_try_again)58 self.ui.btn_try_again.data['unpolish'],
70 self.assertEqual(59 self.ui.btn_try_again)
71 self.network_detection.btn_try_again.data['unpolish'],
72 self.network_detection.btn_try_again)
7360
74 def test_try_again_with_connection(self):61 def test_try_again_with_connection(self):
75 """Check try again method with connection."""62 """Check try again method with connection."""
@@ -78,7 +65,7 @@
78 self.wizard._next_id = -165 self.wizard._next_id = -1
79 if 'next' in self.wizard.data:66 if 'next' in self.wizard.data:
80 self.wizard.data.pop('next')67 self.wizard.data.pop('next')
81 self.network_detection.try_again()68 self.ui.try_again()
82 self.assertEqual(self.wizard._next_id, None)69 self.assertEqual(self.wizard._next_id, None)
83 self.assertTrue(self.wizard.data.get('next', False))70 self.assertTrue(self.wizard.data.get('next', False))
8471
@@ -89,7 +76,6 @@
89 self.wizard._next_id = -176 self.wizard._next_id = -1
90 if 'next' in self.wizard.data:77 if 'next' in self.wizard.data:
91 self.wizard.data.pop('next')78 self.wizard.data.pop('next')
92 self.network_detection.try_again()79 self.ui.try_again()
93 self.assertEqual(self.wizard._next_id, -1)80 self.assertEqual(self.wizard._next_id, -1)
94 self.assertFalse(self.wizard.data.get('next', False))81 self.assertFalse(self.wizard.data.get('next', False))
95 # pylint: enable=W0212
9682
=== modified file 'ubuntu_sso/qt/tests/test_reset_password.py'
--- ubuntu_sso/qt/tests/test_reset_password.py 2012-02-15 17:33:40 +0000
+++ ubuntu_sso/qt/tests/test_reset_password.py 2012-02-24 17:28:19 +0000
@@ -18,40 +18,19 @@
18# pylint: disable=F0401,E0611,E110118# pylint: disable=F0401,E0611,E1101
1919
20from PyQt4 import QtGui, QtCore20from PyQt4 import QtGui, QtCore
21from twisted.internet import defer
2221
23from ubuntu_sso.utils.ui import (22from ubuntu_sso.utils.ui import (
24 PASSWORD1_ENTRY,23 PASSWORD1_ENTRY,
25 PASSWORD2_ENTRY,24 PASSWORD2_ENTRY,
26 RESET_CODE_ENTRY)25 RESET_CODE_ENTRY,
27from ubuntu_sso.qt import gui26)
28from ubuntu_sso.qt import common27from ubuntu_sso.qt import common
29from ubuntu_sso.qt.reset_password_page import (28from ubuntu_sso.qt.reset_password_page import (
30 ResetPasswordPage,29 ResetPasswordPage,
31 RESET_SUBTITLE,30 RESET_SUBTITLE,
32 RESET_TITLE,31 RESET_TITLE,
33)32)
34from ubuntu_sso.qt.ui.reset_password_ui import Ui_ResetPasswordPage33from ubuntu_sso.qt.tests import BaseTestCase
35from ubuntu_sso.qt.tests import (
36 BaseTestCase,
37 FakedBackend,
38 FakedObject,
39 FakeWizard,
40)
41
42
43class FakePasswordAssistance(object):
44 """Fake password_assistance_* calls."""
45
46 _called = False
47
48 def call(self, *args, **kwargs):
49 """Check if the method was called."""
50 FakePasswordAssistance._called = True
51
52 def clenaup(self):
53 """Clean up the variable."""
54 FakePasswordAssistance._called = False
5534
5635
57# We need this Fake until a future refactor.36# We need this Fake until a future refactor.
@@ -78,19 +57,11 @@
78class ResetPasswordTestCase(BaseTestCase):57class ResetPasswordTestCase(BaseTestCase):
79 """Test the ResetPasswordPage code."""58 """Test the ResetPasswordPage code."""
8059
81 @defer.inlineCallbacks60 ui_class = ResetPasswordPage
82 def setUp(self):61 ui_signals = ('passwordChanged',)
83 yield super(ResetPasswordTestCase, self).setUp()62 ui_backend_siganls = ('PasswordChanged', 'PasswordChangeError')
84 self.patch(gui.main, "get_sso_client", FakedBackend)
85 self.app_name = 'my_app'
86 self.ui = ResetPasswordPage(Ui_ResetPasswordPage(),
87 app_name=self.app_name,
88 parent=None)
89 self.wizard = FakeWizard()
90 self.patch(self.ui, 'wizard', lambda: self.wizard)
91 self.fake = FakePasswordAssistance()
9263
93 def test_init(self):64 def test_password_line(self):
94 """Check the initial state of ResetPassword."""65 """Check the initial state of ResetPassword."""
95 self.assertEqual(self.ui.ui.password_line_edit.receivers(66 self.assertEqual(self.ui.ui.password_line_edit.receivers(
96 QtCore.SIGNAL('textEdited(QString)')), 1)67 QtCore.SIGNAL('textEdited(QString)')), 1)
@@ -131,25 +102,27 @@
131102
132 def test_focus_changed_1(self):103 def test_focus_changed_1(self):
133 """Check functions execution when focus_changed() is executed."""104 """Check functions execution when focus_changed() is executed."""
134 self.patch(common, 'password_default_assistance', self.fake.call)105 self.patch(common, 'password_default_assistance', self._set_called)
135 self.addCleanup(self.fake.clenaup)106
136 self.ui.show()107 self.ui.show()
137 self.addCleanup(self.ui.hide)108 self.addCleanup(self.ui.hide)
138 self.assertFalse(FakePasswordAssistance._called)109
110 self.assertFalse(self._called)
139 self.ui.focus_changed(None, self.ui.ui.password_line_edit)111 self.ui.focus_changed(None, self.ui.ui.password_line_edit)
140 self.assertTrue(self.ui.ui.password_assistance.isVisible())112 self.assertTrue(self.ui.ui.password_assistance.isVisible())
141 self.assertTrue(FakePasswordAssistance._called)113 self.assertTrue(self._called)
142114
143 def test_focus_changed_2(self):115 def test_focus_changed_2(self):
144 """Check functions execution when focus_changed() is executed."""116 """Check functions execution when focus_changed() is executed."""
145 self.patch(common, 'password_check_match', self.fake.call)117 self.patch(common, 'password_check_match', self._set_called)
146 self.addCleanup(self.fake.clenaup)118
147 self.ui.show()119 self.ui.show()
148 self.addCleanup(self.ui.hide)120 self.addCleanup(self.ui.hide)
149 self.assertFalse(FakePasswordAssistance._called)121
122 self.assertFalse(self._called)
150 self.ui.focus_changed(None, self.ui.ui.confirm_password_line_edit)123 self.ui.focus_changed(None, self.ui.ui.confirm_password_line_edit)
151 self.assertTrue(self.ui.ui.password_assistance.isVisible())124 self.assertTrue(self.ui.ui.password_assistance.isVisible())
152 self.assertTrue(FakePasswordAssistance._called)125 self.assertTrue(self._called)
153126
154 # pylint: enable=W0212127 # pylint: enable=W0212
155128
@@ -161,12 +134,10 @@
161 forgotten = FakeForgottenPage()134 forgotten = FakeForgottenPage()
162 forgotten.setText(email)135 forgotten.setText(email)
163 self.patch(self.wizard, "forgotten", forgotten)136 self.patch(self.wizard, "forgotten", forgotten)
164 exposed_methods = ['set_new_password']
165 self.patch(FakedObject, "exposed_methods", exposed_methods)
166 faked_object = FakedObject()
167 self.patch(self.ui, "backend", faked_object)
168 self.ui.ui.reset_code_line_edit.setText(code)137 self.ui.ui.reset_code_line_edit.setText(code)
169 self.ui.ui.password_line_edit.setText(password)138 self.ui.ui.password_line_edit.setText(password)
139
170 self.ui.set_new_password()140 self.ui.set_new_password()
141
171 self.assert_backend_called('set_new_password',142 self.assert_backend_called('set_new_password',
172 self.app_name, email, code, password)143 self.app_name, email, code, password)
173144
=== modified file 'ubuntu_sso/qt/tests/test_setup_account.py'
--- ubuntu_sso/qt/tests/test_setup_account.py 2012-02-18 15:12:09 +0000
+++ ubuntu_sso/qt/tests/test_setup_account.py 2012-02-24 17:28:19 +0000
@@ -18,45 +18,22 @@
1818
19from PyQt4 import QtGui, QtCore19from PyQt4 import QtGui, QtCore
2020
21from twisted.internet import defer21from ubuntu_sso.qt import common, setup_account_page
22
23from ubuntu_sso.qt import gui
24from ubuntu_sso.qt import common
25from ubuntu_sso.qt import setup_account_page
26from ubuntu_sso.qt.tests import (22from ubuntu_sso.qt.tests import (
27 BaseTestCase,23 BaseTestCase,
28 FakedBackend,24 HELP_TEXT,
29 FakedObject,
30 FakeOverlay,
31 FakeSignal,
32 FakeWizard,
33)25)
34from ubuntu_sso.qt.ui import setup_account_ui
3526
3627
37class SetupAccountTestCase(BaseTestCase):28class SetupAccountTestCase(BaseTestCase):
38 """Test the SetupAccountPage code."""29 """Test the SetupAccountPage code."""
3930
40 @defer.inlineCallbacks31 ui_class = setup_account_page.SetupAccountPage
41 def setUp(self):32 ui_signals = ('userRegistered',)
42 yield super(SetupAccountTestCase, self).setUp()33 ui_backend_signals = ('CaptchaGenerated', 'CaptchaGenerationError',
43 self.patch(gui.main, "get_sso_client", FakedBackend)34 'UserRegistered', 'UserRegistrationError')
44 self.signals_results = []
45 self.patch(setup_account_page.SetupAccountPage,
46 "userRegistered", FakeSignal())
47 self.app_name = 'my_app'
48 self.ui = setup_account_page.SetupAccountPage(
49 setup_account_ui.Ui_SetUpAccountPage(),
50 'subtitle',
51 'toc_link',
52 'policy_link',
53 app_name=self.app_name,
54 parent=None)
55 self.wizard = FakeWizard()
56 self.patch(self.ui, 'wizard', lambda: self.wizard)
57 self.patch(self.ui, "set_up_button", QtGui.QPushButton())
5835
59 def test_init(self):36 def test_password_receiver(self):
60 """Check the initial state of SetupAccount."""37 """Check the initial state of SetupAccount."""
61 self.assertEqual(self.ui.ui.password_edit.receivers(38 self.assertEqual(self.ui.ui.password_edit.receivers(
62 QtCore.SIGNAL('textEdited(QString)')), 2)39 QtCore.SIGNAL('textEdited(QString)')), 2)
@@ -79,6 +56,8 @@
7956
80 def test_enable_setup_button_with_visible_check(self):57 def test_enable_setup_button_with_visible_check(self):
81 """Test _enable_setup_button method with terms check visible."""58 """Test _enable_setup_button method with terms check visible."""
59 self.patch(self.ui, "set_up_button", QtGui.QPushButton())
60
82 self.ui.ui.name_edit.setText('name')61 self.ui.ui.name_edit.setText('name')
83 email = 'email@example.com'62 email = 'email@example.com'
84 self.ui.ui.email_edit.setText(email)63 self.ui.ui.email_edit.setText(email)
@@ -97,6 +76,8 @@
9776
98 def test_enable_setup_button_without_visible_check(self):77 def test_enable_setup_button_without_visible_check(self):
99 """Test _enable_setup_button method with terms check not visible."""78 """Test _enable_setup_button method with terms check not visible."""
79 self.patch(self.ui, "set_up_button", QtGui.QPushButton())
80
100 self.ui.ui.name_edit.setText('name')81 self.ui.ui.name_edit.setText('name')
101 email = 'email@example.com'82 email = 'email@example.com'
102 self.ui.ui.email_edit.setText(email)83 self.ui.ui.email_edit.setText(email)
@@ -170,10 +151,6 @@
170151
171 def test_on_user_registered(self):152 def test_on_user_registered(self):
172 """Test on_user_registered method."""153 """Test on_user_registered method."""
173 exposed_methods = ['register_user']
174 self.patch(FakedObject, "exposed_methods", exposed_methods)
175 faked_object = FakedObject()
176 self.patch(self.ui, "backend", faked_object)
177 self.patch(self.ui, "validate_form", lambda: True)154 self.patch(self.ui, "validate_form", lambda: True)
178155
179 email = 'email@example'156 email = 'email@example'
@@ -190,8 +167,11 @@
190 def slot(email, password):167 def slot(email, password):
191 """Fake slot."""168 """Fake slot."""
192 self.signals_results.append((email, password))169 self.signals_results.append((email, password))
170
193 self.ui.userRegistered.connect(slot)171 self.ui.userRegistered.connect(slot)
172
194 self.ui.set_next_validation()173 self.ui.set_next_validation()
174
195 self.assertIn((email, password), self.signals_results)175 self.assertIn((email, password), self.signals_results)
196 self.assert_backend_called('register_user',176 self.assert_backend_called('register_user',
197 self.app_name, email, password, name, captcha_id,177 self.app_name, email, password, name, captcha_id,
@@ -217,29 +197,6 @@
217 self.assert_backend_called('generate_captcha',197 self.assert_backend_called('generate_captcha',
218 self.app_name, self.ui.captcha_file)198 self.app_name, self.ui.captcha_file)
219199
220
221class SetupAccountFakeWizardTestCase(BaseTestCase):
222 """Test the SetupAccountPage code."""
223
224 @defer.inlineCallbacks
225 def setUp(self):
226 """Initialize this test instance."""
227 # Faking each SSO object instead of doing it lower
228 # so we don't rely on any SSO behaviour
229 yield super(SetupAccountFakeWizardTestCase, self).setUp()
230 self.patch(gui, "LoadingOverlay", FakeOverlay)
231 self.app_name = 'my_app'
232 self._subtitle = 'subtitle'
233 self.ui = setup_account_page.SetupAccountPage(
234 setup_account_ui.Ui_SetUpAccountPage(),
235 self._subtitle,
236 'toc_link',
237 'policy_link',
238 app_name=self.app_name,
239 parent=None)
240 self.wizard = FakeWizard()
241 self.patch(self.ui, 'wizard', lambda: self.wizard)
242
243 def test_initialize_page(self):200 def test_initialize_page(self):
244 """Widgets are properly initialized."""201 """Widgets are properly initialized."""
245 self.ui.initializePage()202 self.ui.initializePage()
@@ -251,7 +208,11 @@
251 title_expected = (setup_account_page.TITLE_STYLE %208 title_expected = (setup_account_page.TITLE_STYLE %
252 setup_account_page.TITLE.format(app_name=self.app_name))209 setup_account_page.TITLE.format(app_name=self.app_name))
253 self.assertEqual(title, title_expected)210 self.assertEqual(title, title_expected)
254 self.assertEqual(self.ui.header.subtitle_label.text(), self._subtitle)211
212 elided_text = unicode(self.ui.header.subtitle_label.text())
213 elided_text = elided_text[:len(elided_text) - 1]
214 self.assertTrue(HELP_TEXT.startswith(elided_text))
215 self.assertEqual(self.ui.header.subtitle_label.toolTip(), HELP_TEXT)
255216
256 # set up account button217 # set up account button
257 expected = [QtGui.QWizard.BackButton, QtGui.QWizard.Stretch,218 expected = [QtGui.QWizard.BackButton, QtGui.QWizard.Stretch,
258219
=== removed file 'ubuntu_sso/qt/tests/test_sign_in_page.py'
--- ubuntu_sso/qt/tests/test_sign_in_page.py 2012-02-15 17:33:40 +0000
+++ ubuntu_sso/qt/tests/test_sign_in_page.py 1970-01-01 00:00:00 +0000
@@ -1,69 +0,0 @@
1# -*- coding: utf-8 -*-
2#
3# Copyright 2012 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""The test suite for Sign In UI."""
18
19from PyQt4 import QtGui
20from twisted.internet import defer
21
22from ubuntu_sso.qt import sign_in_page as gui
23from ubuntu_sso.qt.ui.choose_sign_in_ui import Ui_ChooseSignInPage
24from ubuntu_sso.qt.tests import BaseTestCase, FakeMainWindow, FakeSignal
25
26
27class SignInPageTestCase(BaseTestCase):
28 """Test the SignInPage code."""
29
30 @defer.inlineCallbacks
31 def setUp(self):
32 """Initialize this test instance."""
33 yield super(SignInPageTestCase, self).setUp()
34 self.signals_results = []
35 self.patch(gui.SignInPage, "existingAccountSelected", FakeSignal())
36 self.patch(gui.SignInPage, "newAccountSelected", FakeSignal())
37 self.patch(gui.SignInPage, "singInCanceled", FakeSignal())
38 self.ui = gui.SignInPage(Ui_ChooseSignInPage(), QtGui.QPixmap())
39
40 def test_show_event(self):
41 """Check the page is initialized correctly."""
42 wizard = FakeMainWindow()
43 self.patch(self.ui, 'wizard', lambda *args: wizard)
44 self.ui.initializePage()
45 self.ui.show()
46 self.addCleanup(self.ui.hide)
47 self.assertTrue(self.ui.ui.existing_account_button.isDefault())
48
49 # pylint: disable=W0212
50 def test_set_next_existing(self):
51 """Test _set_next_existing method."""
52
53 def slot():
54 """Fake slot."""
55 self.signals_results.append(1)
56 self.ui.existingAccountSelected.connect(slot)
57 self.ui._set_next_existing()
58 self.assertIn(1, self.signals_results)
59
60 def test_set_next_new(self):
61 """Test _set_next_existing method."""
62
63 def slot():
64 """Fake slot."""
65 self.signals_results.append(1)
66 self.ui.newAccountSelected.connect(slot)
67 self.ui._set_next_new()
68 self.assertIn(1, self.signals_results)
69 # pylint: enable=W0212
700
=== renamed file 'ubuntu_sso/qt/tests/test_qt_views.py' => 'ubuntu_sso/qt/tests/test_sso_wizard_page.py'
--- ubuntu_sso/qt/tests/test_qt_views.py 2012-02-24 13:57:19 +0000
+++ ubuntu_sso/qt/tests/test_sso_wizard_page.py 2012-02-24 17:28:19 +0000
@@ -13,107 +13,23 @@
13#13#
14# You should have received a copy of the GNU General Public License along14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.15# with this program. If not, see <http://www.gnu.org/licenses/>.
16"""Test the interaction of the view with the auto generated code."""16
1717"""Test the SSOWizardPage and related."""
18from unittest import TestCase18
19from mocker import MATCH, Mocker19from twisted.internet import defer
20
21from PyQt4 import QtGui
22
23from ubuntu_sso.qt.error_page import ErrorPage
24from ubuntu_sso.qt.sign_in_page import SignInPage
25from ubuntu_sso.qt.success_page import SuccessPage
2620
27from ubuntu_sso.qt import PREFERED_UI_SIZE21from ubuntu_sso.qt import PREFERED_UI_SIZE
28from ubuntu_sso.qt.gui import Header22from ubuntu_sso.qt.sso_wizard_page import Header
29from ubuntu_sso.qt.ui.choose_sign_in_ui import Ui_ChooseSignInPage23from ubuntu_sso.qt.tests import BaseTestCase
30from ubuntu_sso.qt.ui.error_message_ui import Ui_ErrorPage24
31from ubuntu_sso.qt.ui.success_message_ui import Ui_SuccessPage25
3226class HeaderTest(BaseTestCase):
3327
34class FakeController(object):
35 """A fake controller for the tests."""
36
37 # pylint: disable=C0103
38 def setupUi(self, view):
39 """Fake the setup."""
40 # pylint: enable=C0103
41
42
43class ChooseSignInPageTestCase(TestCase):
44 """Test the ChooseSignInPage."""
45
46 def setUp(self):
47 """Set up the tests."""
48 super(ChooseSignInPageTestCase, self).setUp()
49 self.ui = Ui_ChooseSignInPage()
50 self.controller = FakeController()
51 self.widget = SignInPage(self.ui, QtGui.QPixmap())
52
53 def tearDown(self):
54 self.widget.close()
55
56 def test_constructor(self):
57 """Test the constructor of the class."""
58 # used a mocked ui for this
59 mocker = Mocker()
60 ui = mocker.mock()
61 ui.setupUi(MATCH(lambda x: isinstance(x, SignInPage)))
62 mocker.replay()
63 self.widget = SignInPage(self.ui, QtGui.QPixmap())
64
65 def test_next_id(self):
66 """Test the nextId method."""
67 next_id = 1
68 self.widget.next = next_id
69 self.assertEqual(next_id, self.widget.nextId())
70
71
72class SuccessPageTestCase(TestCase):
73 """Test that the correct widgets are used."""
74
75 def setUp(self):
76 """Setup tests."""
77 super(SuccessPageTestCase, self).setUp()
78 self.ui = Ui_SuccessPage()
79 self.widget = SuccessPage(self.ui, QtGui.QPixmap())
80
81 def test_constructor(self):
82 """Test that the constructor works as expected."""
83 mocker = Mocker()
84 ui = mocker.mock()
85 ui.setupUi(MATCH(lambda x: isinstance(x, SuccessPage)))
86 mocker.replay()
87 self.widget = SuccessPage(self.ui, QtGui.QPixmap())
88
89
90class ErrorPageTestCase(TestCase):
91 """Test that the correct widgets are used."""
92
93 def setUp(self):
94 """Setup tests."""
95 super(ErrorPageTestCase, self).setUp()
96 self.ui = Ui_ErrorPage()
97 self.controller = FakeController()
98 self.widget = ErrorPage(self.ui, self.controller)
99
100 def test_constructor(self):
101 """Test that the constructor works as expected."""
102 mocker = Mocker()
103 ui = mocker.mock()
104 controller = mocker.mock()
105 ui.setupUi(MATCH(lambda x: isinstance(x, ErrorPage)))
106 controller.setupUi(MATCH(lambda x: isinstance(x, ErrorPage)))
107 mocker.replay()
108 self.widget = ErrorPage(self.ui, self.controller)
109
110
111class HeaderTest(TestCase):
112 """Tests for injected Header in each Wizard Page."""28 """Tests for injected Header in each Wizard Page."""
11329
30 @defer.inlineCallbacks
114 def setUp(self):31 def setUp(self):
115 """Setup test."""32 yield super(HeaderTest, self).setUp()
116 super(HeaderTest, self).setUp()
117 self.header = Header()33 self.header = Header()
11834
119 def test_label_state(self):35 def test_label_state(self):
12036
=== added file 'ubuntu_sso/qt/tests/test_success_page.py'
--- ubuntu_sso/qt/tests/test_success_page.py 1970-01-01 00:00:00 +0000
+++ ubuntu_sso/qt/tests/test_success_page.py 2012-02-24 17:28:19 +0000
@@ -0,0 +1,26 @@
1# -*- coding: utf-8 -*-
2#
3# Copyright 2012 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""Test the success page."""
18
19from ubuntu_sso.qt.success_page import SuccessPage
20from ubuntu_sso.qt.tests import BaseTestCase
21
22
23class SuccessPageTestCase(BaseTestCase):
24 """Test that the correct widgets are used."""
25
26 ui_class = SuccessPage
027
=== modified file 'ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py'
--- ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-02-24 14:58:30 +0000
+++ ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-02-24 17:28:19 +0000
@@ -20,21 +20,24 @@
20from twisted.internet import defer20from twisted.internet import defer
2121
22from ubuntu_sso.qt import PREFERED_UI_SIZE, ubuntu_sso_wizard22from ubuntu_sso.qt import PREFERED_UI_SIZE, ubuntu_sso_wizard
23from ubuntu_sso.qt.tests import (23from ubuntu_sso.qt.tests import BaseTestCase
24 BaseTestCase,24
25 FakedObject,25
26)26# is ok to access private method/attrs in tests
2727# pylint: disable=W0212
2828
29class ReturnCodeTestCase(BaseTestCase):29
30 """Test the return codes."""30class UbuntuSSOClientGUITestCase(BaseTestCase):
31
32 """Test the UbuntuSSOClientGUI class."""
33
34 ui_class = ubuntu_sso_wizard.UbuntuSSOClientGUI
35 ui_wizard_class = None
3136
32 @defer.inlineCallbacks37 @defer.inlineCallbacks
33 def setUp(self):38 def setUp(self):
34 yield super(ReturnCodeTestCase, self).setUp()39 yield super(UbuntuSSOClientGUITestCase, self).setUp()
35 self.patch(ubuntu_sso_wizard.sys, 'exit', self._set_called)40 self.patch(ubuntu_sso_wizard.sys, 'exit', self._set_called)
36 self.app_name = 'app_name'
37 self.ui = ubuntu_sso_wizard.UbuntuSSOClientGUI(self.app_name)
3841
39 def test_closing_main_window(self):42 def test_closing_main_window(self):
40 """When closing the main window, USER_CANCELLATION is returned."""43 """When closing the main window, USER_CANCELLATION is returned."""
@@ -42,44 +45,36 @@
42 self.assertEqual(self._called,45 self.assertEqual(self._called,
43 ((ubuntu_sso_wizard.USER_CANCELLATION,), {}))46 ((ubuntu_sso_wizard.USER_CANCELLATION,), {}))
4447
45 # pylint: disable=W0212
46 def test_close_main_window_reaching_success_page(self):48 def test_close_main_window_reaching_success_page(self):
47 """Closing the window in success page, USER_SUCCESS is returned."""49 """Closing the window in success page, USER_SUCCESS is returned."""
48 email = 'email@example.com'50 self.ui.wizard._move_to_success_page()
49 self.ui.wizard._move_to_success_page(self.app_name, email)
50 self.ui.close()51 self.ui.close()
51 self.assertEqual(self._called,52 self.assertEqual(self._called,
52 ((ubuntu_sso_wizard.USER_SUCCESS,), {}))53 ((ubuntu_sso_wizard.USER_SUCCESS,), {}))
53 # pylint: enable=W0212
5454
55 def test_closing_wizard(self):55 def test_closing_wizard_no_parent(self):
56 """When closing the wizard, USER_CANCELLATION is returned."""56 """When closing the wizard, USER_CANCELLATION is returned."""
57 self.ui.wizard.setParent(None)57 self.ui.wizard.setParent(None)
58 self.ui.wizard.close()58 self.ui.wizard.close()
59 self.assertEqual(self._called,59 self.assertEqual(self._called,
60 ((ubuntu_sso_wizard.USER_CANCELLATION,), {}))60 ((ubuntu_sso_wizard.USER_CANCELLATION,), {}))
6161
62 # pylint: disable=W021262 def test_close_wizard_no_parent_reaching_success_page(self):
63 def test_close_wizard_reaching_success_page(self):
64 """Closing the wizard in success page, USER_SUCCESS is returned."""63 """Closing the wizard in success page, USER_SUCCESS is returned."""
65 self.ui.wizard.setParent(None)64 self.ui.wizard.setParent(None)
66 email = 'email@example.com'65 self.ui.wizard._move_to_success_page()
67 self.ui.wizard._move_to_success_page(self.app_name, email)
68 self.ui.wizard.close()66 self.ui.wizard.close()
69 self.assertEqual(self._called,67 self.assertEqual(self._called,
70 ((ubuntu_sso_wizard.USER_SUCCESS,), {}))68 ((ubuntu_sso_wizard.USER_SUCCESS,), {}))
71 # pylint: enable=W0212
7269
7370
74class UbuntuSSOWizardTestCase(BaseTestCase):71class UbuntuSSOWizardTestCase(BaseTestCase):
7572
76 """Test Case for UbuntuSSOWizard"""73 """Test case for UbuntuSSOWizard class."""
7774
78 @defer.inlineCallbacks75 ui_class = ubuntu_sso_wizard.UbuntuSSOWizard
79 def setUp(self):76 ui_signals = ('recoverableError', 'loginSuccess', 'registrationSuccess')
80 yield super(UbuntuSSOWizardTestCase, self).setUp()77 ui_wizard_class = None
81 self.app_name = 'app_name'
82 self.ui = ubuntu_sso_wizard.UbuntuSSOWizard(self.app_name)
8378
84 def test_window_size(self):79 def test_window_size(self):
85 """check the window size."""80 """check the window size."""
@@ -89,32 +84,13 @@
89 self.assertEqual(size.height(), PREFERED_UI_SIZE['height'])84 self.assertEqual(size.height(), PREFERED_UI_SIZE['height'])
90 self.assertEqual(size.width(), PREFERED_UI_SIZE['width'])85 self.assertEqual(size.width(), PREFERED_UI_SIZE['width'])
9186
92 # pylint: disable=W0212
93 def test_move_to_success_page_state(self):87 def test_move_to_success_page_state(self):
94 """Test _move_to_success_page method."""88 """Test _move_to_success_page method."""
95 self.patch(self.ui, 'setButtonLayout', self._set_called)89 self.patch(self.ui, 'setButtonLayout', self._set_called)
96 self.ui._move_to_success_page(self.app_name)90 self.ui._move_to_success_page()
97 self.assertEqual(self.ui._next_id, -1)91 self.assertEqual(self.ui._next_id, -1)
98 self.assertEqual(self.ui._next_id, -1)92 self.assertEqual(self.ui._next_id, -1)
99 self.assertEqual(self._called,93 self.assertEqual(self._called,
100 (([QtGui.QWizard.Stretch, QtGui.QWizard.FinishButton],), {}))94 (([QtGui.QWizard.Stretch, QtGui.QWizard.FinishButton],), {}))
101 self.assertTrue(self.ui.button(QtGui.QWizard.FinishButton).isEnabled())95 self.assertTrue(self.ui.button(QtGui.QWizard.FinishButton).isEnabled())
102 self.assertEqual(self.ui._done, ubuntu_sso_wizard.USER_SUCCESS)96 self.assertEqual(self.ui.exit_code, ubuntu_sso_wizard.USER_SUCCESS)
103 # pylint: enable=W0212
104
105 # pylint: disable=W0212, E1101
106 def test_sing_in_canceled_connection(self):
107 """Test if sign in canceled signal calls close and not reject."""
108 exposed_methods = [
109 'close',
110 'reject']
111 self.patch(FakedObject, "exposed_methods", exposed_methods)
112 faked_object = FakedObject()
113 self.patch(self.ui, "closeEvent", faked_object.close)
114 self.patch(self.ui, "reject", faked_object.reject)
115 self.ui.show()
116 self.addCleanup(self.ui.hide)
117 self.ui.sign_in_page.ui.cancel_button.clicked.emit(True)
118 self.assertIn('close', faked_object._called)
119 self.assertNotIn('reject', faked_object._called)
120 # pylint: enable=W0212, E1101
12197
=== modified file 'ubuntu_sso/qt/ubuntu_sso_wizard.py'
--- ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-02-24 14:58:30 +0000
+++ ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-02-24 17:28:19 +0000
@@ -1,5 +1,5 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
22#
3# Copyright 2012 Canonical Ltd.3# Copyright 2012 Canonical Ltd.
4#4#
5# This program is free software: you can redistribute it and/or modify it5# This program is free software: you can redistribute it and/or modify it
@@ -21,14 +21,11 @@
21from PyQt4.QtCore import pyqtSignal21from PyQt4.QtCore import pyqtSignal
22from PyQt4.QtGui import (22from PyQt4.QtGui import (
23 QFrame,23 QFrame,
24 QPixmap,
25 QVBoxLayout,24 QVBoxLayout,
26 QWizard,25 QWizard,
27)26)
28from twisted.internet import defer
2927
30from ubuntu_sso import (28from ubuntu_sso import (
31 NO_OP,
32 USER_CANCELLATION,29 USER_CANCELLATION,
33 USER_SUCCESS,30 USER_SUCCESS,
34)31)
@@ -40,17 +37,7 @@
40from ubuntu_sso.qt.forgotten_password_page import ForgottenPasswordPage37from ubuntu_sso.qt.forgotten_password_page import ForgottenPasswordPage
41from ubuntu_sso.qt.reset_password_page import ResetPasswordPage38from ubuntu_sso.qt.reset_password_page import ResetPasswordPage
42from ubuntu_sso.qt.setup_account_page import SetupAccountPage39from ubuntu_sso.qt.setup_account_page import SetupAccountPage
43from ubuntu_sso.qt.sign_in_page import SignInPage
44from ubuntu_sso.qt.success_page import SuccessPage40from ubuntu_sso.qt.success_page import SuccessPage
45from ubuntu_sso.qt.ui.choose_sign_in_ui import Ui_ChooseSignInPage
46from ubuntu_sso.qt.ui.current_user_sign_in_ui import Ui_CurrentUserSignInPage
47from ubuntu_sso.qt.ui.email_verification_ui import Ui_EmailVerificationPage
48from ubuntu_sso.qt.ui.error_message_ui import Ui_ErrorPage
49from ubuntu_sso.qt.ui.setup_account_ui import Ui_SetUpAccountPage
50from ubuntu_sso.qt.ui.success_message_ui import Ui_SuccessPage
51from ubuntu_sso.qt.ui.forgotten_password_ui import Ui_ForgottenPasswordPage
52from ubuntu_sso.qt.ui.reset_password_ui import Ui_ResetPasswordPage
53
5441
55logger = setup_logging('ubuntu_sso.gui')42logger = setup_logging('ubuntu_sso.gui')
5643
@@ -65,83 +52,61 @@
6552
66 def __init__(self, app_name, **kwargs):53 def __init__(self, app_name, **kwargs):
67 """Create a new wizard."""54 """Create a new wizard."""
68 parent = kwargs.get('parent')55 logger.debug('UbuntuSSOWizard: app_name %r, kwargs %r.',
69 super(UbuntuSSOWizard, self).__init__(parent)56 app_name, kwargs)
57 parent = kwargs.pop('parent', None)
58 super(UbuntuSSOWizard, self).__init__(parent=parent)
70 self._next_id = -159 self._next_id = -1
71 self.setOption(QWizard.HaveFinishButtonOnEarlyPages, True)60 self.setOption(QWizard.HaveFinishButtonOnEarlyPages, True)
72 self._done = USER_CANCELLATION61 self.setOption(QWizard.NoBackButtonOnStartPage, True)
62 self.exit_code = USER_CANCELLATION
7363
74 # store common useful data provided by the app
75 self.app_name = app_name64 self.app_name = app_name
76 self.ping_url = kwargs.get('ping_url', '')65 self.login_only = kwargs.pop('login_only', False)
77 self.tc_url = kwargs.get('tc_url', '')66 self.close_callback = kwargs.pop('close_callback', lambda: None)
78 self.policy_url = kwargs.get('policy_url', '')67
79 self.help_text = kwargs.get('help_text', '')68 # store the ids of the pages so that it is easier to access them later
80 self.login_only = kwargs.get('login_only', False)69 self._pages = {}
81 self.close_callback = kwargs.get('close_callback', lambda: None)70
82 self.login_success_callback = NO_OP71 # prepare kwargs to be suitable for the pages
83 self.registration_success_callback = NO_OP72 kwargs['app_name'] = self.app_name
84 self.user_cancellation_callback = NO_OP73 kwargs['parent'] = self
8574
86 # set the diff pages of the QWizard75 # set the diff pages of the QWizard
87 self.sign_in_page = SignInPage(Ui_ChooseSignInPage(),76 if not self.login_only:
88 QPixmap(),77 self.setup_account = SetupAccountPage(**kwargs)
89 app_name=self.app_name,78 self.setup_account.userRegistered.connect(
90 parent=self)79 self._move_to_email_verification_page)
91 self.sign_in_page.singInCanceled.connect(self.close)80 self.addPage(self.setup_account)
92 self.sign_in_page.existingAccountSelected.connect(81
93 self._move_to_login_page)82 self.current_user = CurrentUserSignInPage(**kwargs)
94 self.sign_in_page.newAccountSelected.connect(
95 self._move_to_setup_account_page)
96
97 self.setup_account = SetupAccountPage(Ui_SetUpAccountPage(),
98 self.help_text,
99 self.tc_url,
100 self.policy_url,
101 app_name=self.app_name,
102 parent=self)
103 self.setup_account.userRegistered.connect(
104 self._move_to_email_verification_page)
105
106 self.current_user = CurrentUserSignInPage(Ui_CurrentUserSignInPage(),
107 self.ping_url,
108 app_name=self.app_name,
109 parent=self)
110 self.current_user.userNotValidated.connect(83 self.current_user.userNotValidated.connect(
111 self._move_to_email_verification_page)84 self._move_to_email_verification_page)
112 self.current_user.userLoggedIn.connect(self._move_to_success_page)85 self.current_user.userLoggedIn.connect(self._move_to_success_page)
113 self.current_user.passwordForgotten.connect(86 self.current_user.passwordForgotten.connect(
114 self._move_to_forgotten_page)87 self._move_to_forgotten_page)
88 self.addPage(self.current_user)
11589
116 self.email_verification = EmailVerificationPage(90 self.email_verification = EmailVerificationPage(**kwargs)
117 Ui_EmailVerificationPage(),
118 self.ping_url,
119 app_name=self.app_name)
120 self.email_verification.registrationSuccess.connect(91 self.email_verification.registrationSuccess.connect(
121 self._move_to_success_page)92 self._move_to_success_page)
12293 self.addPage(self.email_verification)
123 self.success = SuccessPage(Ui_SuccessPage(), QPixmap(),94
124 app_name=self.app_name, parent=self)95 self.success = SuccessPage(**kwargs)
125 self.error = ErrorPage(Ui_ErrorPage(),96 self.addPage(self.success)
126 app_name=self.app_name)97
127 self.forgotten = ForgottenPasswordPage(Ui_ForgottenPasswordPage(),98 self.error = ErrorPage(**kwargs)
128 app_name=self.app_name,99 self.addPage(self.error)
129 parent=self)100
101 self.forgotten = ForgottenPasswordPage(**kwargs)
130 self.forgotten.passwordResetTokenSent.connect(102 self.forgotten.passwordResetTokenSent.connect(
131 self._move_to_reset_password_page)103 self._move_to_reset_password_page)
104 self.addPage(self.forgotten)
132105
133 self.reset_password = ResetPasswordPage(Ui_ResetPasswordPage(),106 self.reset_password = ResetPasswordPage(**kwargs)
134 app_name=self.app_name,107 back = lambda *a: self._go_back_to_current_page(self.current_user)
135 parent=self)108 self.reset_password.passwordChanged.connect(back)
136 self.reset_password.passwordChanged.connect(109 self.addPage(self.reset_password)
137 self._go_back_to_current_page)
138 # store the ids of the pages so that it is easier to access them later
139 pages = [self.sign_in_page, self.setup_account,
140 self.email_verification, self.current_user, self.success,
141 self.error, self.forgotten, self.reset_password]
142 self._pages = {}
143 for page in pages:
144 self._pages[page] = self.addPage(page)
145110
146 # set the buttons layout to only have cancel and back since the next111 # set the buttons layout to only have cancel and back since the next
147 # buttons are the ones used in the diff pages.112 # buttons are the ones used in the diff pages.
@@ -152,24 +117,29 @@
152 self.setButtonLayout(buttons_layout)117 self.setButtonLayout(buttons_layout)
153 self.setWindowTitle(self.app_name)118 self.setWindowTitle(self.app_name)
154 self.setWizardStyle(QWizard.ModernStyle)119 self.setWizardStyle(QWizard.ModernStyle)
155 self.button(QWizard.CancelButton).clicked.connect(120 self.button(QWizard.CancelButton).clicked.connect(self.close)
156 self.on_user_cancelation)
157 self.setMinimumSize(PREFERED_UI_SIZE['width'],121 self.setMinimumSize(PREFERED_UI_SIZE['width'],
158 PREFERED_UI_SIZE['height'])122 PREFERED_UI_SIZE['height'])
159123
160 # pylint: disable=C0103124 # pylint: disable=C0103
125
161 def nextId(self):126 def nextId(self):
162 """Return the id of the next page."""127 """Return the id of the next page."""
163 return self._next_id128 return self._next_id
129
130 def addPage(self, page):
131 """Add 'page' to this wizard."""
132 page_id = super(UbuntuSSOWizard, self).addPage(page)
133 self._pages[page] = page_id
134
164 # pylint: enable=C0103135 # pylint: enable=C0103
165136
166 def _go_back_to_current_page(self, email):137 def _go_back_to_page(self, page):
167 """Move back until it reaches the current user sign in page. """138 """Move back until it reaches the 'page'."""
168 self.current_user.ui.email_edit.setText(email)139 page_id = self._pages[page]
169 current_user_id = self.current_user_page_id
170 visited_pages = self.visitedPages()140 visited_pages = self.visitedPages()
171 for index in reversed(visited_pages):141 for index in reversed(visited_pages):
172 if index == current_user_id:142 if index == page_id:
173 break143 break
174 self.back()144 self.back()
175145
@@ -179,12 +149,9 @@
179 self.next()149 self.next()
180 self._next_id = -1150 self._next_id = -1
181151
182 def _move_to_email_verification_page(self, email, password):152 def _move_to_email_verification_page(self):
183 """Move to the email verification page wizard."""153 """Move to the email verification page wizard."""
184 self._next_id = self.email_verification_page_id154 self._next_id = self.email_verification_page_id
185 self.email_verification.email = unicode(email)
186 self.email_verification.password = unicode(password)
187 self.email_verification.set_titles(email)
188 self.next()155 self.next()
189 self._next_id = -1156 self._next_id = -1
190157
@@ -200,7 +167,7 @@
200 self.next()167 self.next()
201 self._next_id = -1168 self._next_id = -1
202169
203 def _move_to_success_page(self, app_name='', email=''):170 def _move_to_success_page(self):
204 """Move to the success page wizard."""171 """Move to the success page wizard."""
205 self._next_id = self.success_page_id172 self._next_id = self.success_page_id
206 self.next()173 self.next()
@@ -209,7 +176,7 @@
209 QWizard.FinishButton])176 QWizard.FinishButton])
210 self.button(QWizard.FinishButton).setEnabled(True)177 self.button(QWizard.FinishButton).setEnabled(True)
211 self.button(QWizard.FinishButton).setFocus()178 self.button(QWizard.FinishButton).setFocus()
212 self._done = USER_SUCCESS179 self.exit_code = USER_SUCCESS
213 self._next_id = -1180 self._next_id = -1
214181
215 def _move_to_forgotten_page(self):182 def _move_to_forgotten_page(self):
@@ -219,11 +186,6 @@
219 self._next_id = -1186 self._next_id = -1
220187
221 @property188 @property
222 def sign_in_page_id(self):
223 """Return the id of the page used for choosing sign in type."""
224 return self._pages[self.sign_in_page]
225
226 @property
227 def setup_account_page_id(self):189 def setup_account_page_id(self):
228 """Return the id of the page used for sign in."""190 """Return the id of the page used for sign in."""
229 return self._pages[self.setup_account]191 return self._pages[self.setup_account]
@@ -258,76 +220,18 @@
258 """Return the id of the error page."""220 """Return the id of the error page."""
259 return self._pages[self.error]221 return self._pages[self.error]
260222
261 def on_user_cancelation(self):223 # pylint: disable=C0103
262 """Process the cancel action."""224
263 logger.debug('UbuntuSSOWizard.on_user_cancelation')
264 self.user_cancellation_callback(self.app_name)
265 self.close()
266
267 @defer.inlineCallbacks
268 def on_login_success(self, app_name, email):
269 """Process the success of a login."""
270 logger.debug('UbuntuSSOWizard.on_login_success')
271 result = yield self.login_success_callback(
272 unicode(app_name), unicode(email))
273 logger.debug('Result from callback is %s', result)
274 if result == 0:
275 logger.info('Success in calling the given success_callback')
276 self.show_success_message()
277 else:
278 logger.info('Error in calling the given success_callback')
279 self.show_error_message()
280
281 @defer.inlineCallbacks
282 def on_registration_success(self, app_name, email):
283 """Process the success of a registration."""
284 logger.debug('UbuntuSSOWizard.on_registration_success')
285 result = yield self.registration_success_callback(unicode(app_name),
286 unicode(email))
287 logger.debug('Result from callback is %s', result)
288 if result == 0:
289 logger.info('Success in calling the given registration_callback')
290 self.show_success_message()
291 else:
292 logger.info('Success in calling the given registration_callback')
293 self.show_error_message()
294
295 def show_success_message(self):
296 """Show the success message in the view."""
297 logger.info('Showing success message.')
298 # get the id of the success page, set it as the next id of the
299 # current page and let the wizard move to the next step
300 self.currentPage().next = self.success_page_id
301 self.next()
302 # show the finish button but with a close message
303 buttons_layout = []
304 buttons_layout.append(QWizard.Stretch)
305 buttons_layout.append(QWizard.FinishButton)
306 self.setButtonLayout(buttons_layout)
307
308 def show_error_message(self):
309 """Show the error page in the view."""
310 logger.info('Showing error message.')
311 # similar to the success page but using the error id
312 self.currentPage().next = self.error_page_id
313 self.next()
314 # show the finish button but with a close message
315 buttons_layout = []
316 buttons_layout.append(QWizard.Stretch)
317 buttons_layout.append(QWizard.FinishButton)
318 self.setButtonLayout(buttons_layout)
319
320 # pylint: disable=C0103, W0212
321 def closeEvent(self, event):225 def closeEvent(self, event):
322 """Catch close event and send the proper return code."""226 """Catch close event and send the proper return code."""
323 if self.parent() is not None:227 if self.parent() is not None:
324 self.parent().close()228 self.parent().close()
325 else:229 else:
326 sys.exit(self._done)230 sys.exit(self.exit_code)
327 # pylint: enable=C0103, W0212231
328232 # pylint: enable=C0103
329233
330# pylint: disable=W0201234
331class UbuntuSSOClientGUI(QFrame):235class UbuntuSSOClientGUI(QFrame):
332 """Ubuntu single sign-on GUI."""236 """Ubuntu single sign-on GUI."""
333237
@@ -345,41 +249,10 @@
345 self.wizard = UbuntuSSOWizard(app_name=app_name, **kwargs)249 self.wizard = UbuntuSSOWizard(app_name=app_name, **kwargs)
346 vbox.addWidget(self.wizard)250 vbox.addWidget(self.wizard)
347251
348 def get_login_success_callback(self):252 # pylint: disable=C0103
349 """Return the log in success cb."""253
350 return self.view.login_success_callback
351
352 def set_login_success_callback(self, cb):
353 """Set log in success cb."""
354 self.view.login_success_callback = cb
355
356 login_success_callback = property(get_login_success_callback,
357 set_login_success_callback)
358
359 def get_registration_success_callback(self):
360 """Return the registration success cb."""
361 return self.view.registration_success_callback
362
363 def set_registration_success_callback(self, cb):
364 """Set registration success cb."""
365 self.view.registration_success_callback = cb
366
367 registration_success_callback = property(get_registration_success_callback,
368 set_registration_success_callback)
369
370 def get_user_cancellation_callback(self):
371 """Return the user cancellation callback."""
372 return self.view.user_cancellation_callback
373
374 def set_user_cancellation_callback(self, cb):
375 """Set the user cancellation callback."""
376 self.view.user_cancellation_callback = cb
377
378 user_cancellation_callback = property(get_user_cancellation_callback,
379 set_user_cancellation_callback)
380
381 # pylint: disable=C0103, W0212
382 def closeEvent(self, event):254 def closeEvent(self, event):
383 """Catch close event and send the proper return code."""255 """Catch close event and send the proper return code."""
384 sys.exit(self.wizard._done)256 sys.exit(self.wizard.exit_code)
385 # pylint: enable=C0103, W0212257
258 # pylint: enable=C0103

Subscribers

People subscribed via source and target branches