Merge lp:~dobey/ubuntu/oneiric/ubuntu-sso-client/release-133 into lp:ubuntu/oneiric/ubuntu-sso-client
- Oneiric (11.10)
- release-133
- Merge into oneiric
Proposed by
dobey
Status: | Merged |
---|---|
Merged at revision: | 36 |
Proposed branch: | lp:~dobey/ubuntu/oneiric/ubuntu-sso-client/release-133 |
Merge into: | lp:ubuntu/oneiric/ubuntu-sso-client |
Diff against target: |
4383 lines (+2124/-395) 39 files modified
PKG-INFO (+19/-1) bin/windows-ubuntu-sso-login (+36/-5) data/qt/current_user_sign_in.ui (+6/-3) data/qt/email_verification.ui (+1/-1) data/qt/forgotten_password.ui (+4/-1) data/qt/reset_password.ui (+4/-1) data/qt/setup_account.ui (+2/-15) debian/changelog (+7/-0) run-tests (+18/-2) run-tests.bat (+5/-7) setup.py (+33/-12) ubuntu_sso/credentials.py (+46/-26) ubuntu_sso/logger.py (+2/-3) ubuntu_sso/main/__init__.py (+29/-7) ubuntu_sso/main/linux.py (+20/-6) ubuntu_sso/main/tests/test_common.py (+15/-8) ubuntu_sso/main/tests/test_linux.py (+16/-5) ubuntu_sso/main/tests/test_windows.py (+100/-15) ubuntu_sso/main/windows.py (+87/-31) ubuntu_sso/networkstate/windows.py (+4/-2) ubuntu_sso/qt/controllers.py (+212/-78) ubuntu_sso/qt/gui.py (+79/-16) ubuntu_sso/qt/tests/login_u_p.py (+54/-0) ubuntu_sso/qt/tests/show_gui.py (+16/-5) ubuntu_sso/qt/tests/test_enchanced_line_edit.py (+94/-0) ubuntu_sso/qt/tests/test_qt_views.py (+44/-1) ubuntu_sso/qt/tests/test_windows.py (+502/-46) ubuntu_sso/tests/__init__.py (+10/-10) ubuntu_sso/tests/test_account.py (+5/-2) ubuntu_sso/tests/test_credentials.py (+168/-82) ubuntu_sso/utils/__init__.py (+35/-0) ubuntu_sso/utils/tests/test_oauth_headers.py (+109/-0) ubuntu_sso/utils/txsecrets.py (+8/-2) ubuntu_sso/utils/ui.py (+3/-2) ubuntu_sso/xdg_base_directory/__init__.py (+35/-0) ubuntu_sso/xdg_base_directory/tests/__init__.py (+16/-0) ubuntu_sso/xdg_base_directory/tests/test_common.py (+49/-0) ubuntu_sso/xdg_base_directory/tests/test_windows.py (+112/-0) ubuntu_sso/xdg_base_directory/windows.py (+119/-0) |
To merge this branch: | bzr merge lp:~dobey/ubuntu/oneiric/ubuntu-sso-client/release-133 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu branches | Pending | ||
Review via email: mp+72943@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'PKG-INFO' | |||
2 | --- PKG-INFO 2011-07-22 20:12:20 +0000 | |||
3 | +++ PKG-INFO 2011-08-25 19:16:19 +0000 | |||
4 | @@ -1,6 +1,6 @@ | |||
5 | 1 | Metadata-Version: 1.1 | 1 | Metadata-Version: 1.1 |
6 | 2 | Name: ubuntu-sso-client | 2 | Name: ubuntu-sso-client |
8 | 3 | Version: 1.3.2 | 3 | Version: 1.3.3 |
9 | 4 | Summary: Ubuntu Single Sign-On client | 4 | Summary: Ubuntu Single Sign-On client |
10 | 5 | Home-page: https://launchpad.net/ubuntu-sso-client | 5 | Home-page: https://launchpad.net/ubuntu-sso-client |
11 | 6 | Author: Natalia Bidart | 6 | Author: Natalia Bidart |
12 | @@ -8,4 +8,22 @@ | |||
13 | 8 | License: GPL v3 | 8 | License: GPL v3 |
14 | 9 | Description: Desktop service to allow applications to sign into Ubuntu services via SSO | 9 | Description: Desktop service to allow applications to sign into Ubuntu services via SSO |
15 | 10 | Platform: UNKNOWN | 10 | Platform: UNKNOWN |
16 | 11 | Requires: Image | ||
17 | 12 | Requires: PIL | ||
18 | 13 | Requires: PyQt4 | ||
19 | 14 | Requires: dbus | ||
20 | 15 | Requires: gi.repository | ||
21 | 16 | Requires: gobject | ||
22 | 17 | Requires: gtk | ||
23 | 18 | Requires: keyring | ||
24 | 19 | Requires: mocker | ||
25 | 20 | Requires: oauth | ||
26 | 21 | Requires: twisted.internet | ||
27 | 22 | Requires: twisted.python | ||
28 | 23 | Requires: twisted.spread.pb | ||
29 | 24 | Requires: twisted.trial | ||
30 | 25 | Requires: ubuntuone.devtools.handlers | ||
31 | 26 | Requires: ubuntuone.devtools.testcase | ||
32 | 27 | Requires: webkit | ||
33 | 28 | Requires: xdg.BaseDirectory | ||
34 | 11 | Provides: ubuntu_sso | 29 | Provides: ubuntu_sso |
35 | 12 | 30 | ||
36 | === modified file 'bin/windows-ubuntu-sso-login' | |||
37 | --- bin/windows-ubuntu-sso-login 2011-07-22 20:12:20 +0000 | |||
38 | +++ bin/windows-ubuntu-sso-login 2011-08-25 19:16:19 +0000 | |||
39 | @@ -28,16 +28,25 @@ | |||
40 | 28 | import qtreactor.qt4reactor | 28 | import qtreactor.qt4reactor |
41 | 29 | qtreactor.qt4reactor.install() | 29 | qtreactor.qt4reactor.install() |
42 | 30 | 30 | ||
44 | 31 | from twisted.internet import reactor | 31 | from twisted.internet import reactor, defer |
45 | 32 | from twisted.spread.pb import PBServerFactory | 32 | from twisted.spread.pb import PBServerFactory |
46 | 33 | from twisted.internet.task import LoopingCall | 33 | from twisted.internet.task import LoopingCall |
47 | 34 | from twisted.python import log | ||
48 | 34 | 35 | ||
49 | 36 | from ubuntu_sso.logger import setup_logging | ||
50 | 35 | from ubuntu_sso.main.windows import ( | 37 | from ubuntu_sso.main.windows import ( |
51 | 36 | CredentialsManagement, | 38 | CredentialsManagement, |
52 | 39 | LOCALHOST, | ||
53 | 37 | SSOCredentials, | 40 | SSOCredentials, |
54 | 38 | SSOLogin, | 41 | SSOLogin, |
55 | 39 | UbuntuSSORoot, | 42 | UbuntuSSORoot, |
57 | 40 | get_sso_pb_hostport) | 43 | get_activation_config, |
58 | 44 | ) | ||
59 | 45 | from ubuntu_sso.utils import tcpactivation | ||
60 | 46 | |||
61 | 47 | |||
62 | 48 | logger = setup_logging("windows-ubuntu-sso-login") | ||
63 | 49 | |||
64 | 41 | 50 | ||
65 | 42 | def add_timeout(interval, callback, *args, **kwargs): | 51 | def add_timeout(interval, callback, *args, **kwargs): |
66 | 43 | """Add a timeout callback as a task.""" | 52 | """Add a timeout callback as a task.""" |
67 | @@ -45,13 +54,35 @@ | |||
68 | 45 | time_out_task.start(interval/1000, now=False) | 54 | time_out_task.start(interval/1000, now=False) |
69 | 46 | 55 | ||
70 | 47 | 56 | ||
73 | 48 | if __name__ == '__main__': | 57 | @defer.inlineCallbacks |
74 | 49 | host, port = get_sso_pb_hostport() | 58 | def main(): |
75 | 59 | """Initialize and start this process.""" | ||
76 | 60 | ai = tcpactivation.ActivationInstance(get_activation_config()) | ||
77 | 61 | port = yield ai.get_port() | ||
78 | 50 | 62 | ||
79 | 51 | login = SSOLogin('ignored') | 63 | login = SSOLogin('ignored') |
80 | 52 | creds = SSOCredentials() | 64 | creds = SSOCredentials() |
81 | 53 | creds_management = CredentialsManagement(add_timeout, reactor.stop) | 65 | creds_management = CredentialsManagement(add_timeout, reactor.stop) |
82 | 54 | root = UbuntuSSORoot(login, creds, creds_management) | 66 | root = UbuntuSSORoot(login, creds, creds_management) |
83 | 55 | 67 | ||
85 | 56 | listener = reactor.listenTCP(port, PBServerFactory(root), interface=host) | 68 | reactor.listenTCP(port, PBServerFactory(root), interface=LOCALHOST) |
86 | 69 | |||
87 | 70 | |||
88 | 71 | def handle_already_started(failure): | ||
89 | 72 | """Handle the already started error by shutting down this process.""" | ||
90 | 73 | failure.trap(tcpactivation.AlreadyStartedError) | ||
91 | 74 | print "Ubuntu SSO login manager already running." | ||
92 | 75 | reactor.stop() | ||
93 | 76 | |||
94 | 77 | |||
95 | 78 | def utter_failure(failure): | ||
96 | 79 | """Handle an utter failure by logging it and quiting.""" | ||
97 | 80 | log.err(failure) | ||
98 | 81 | reactor.stop() | ||
99 | 82 | |||
100 | 83 | |||
101 | 84 | if __name__ == '__main__': | ||
102 | 85 | d = main() | ||
103 | 86 | d.addErrback(handle_already_started) | ||
104 | 87 | d.addErrback(utter_failure) | ||
105 | 57 | reactor.run() | 88 | reactor.run() |
106 | 58 | 89 | ||
107 | === modified file 'data/qt/current_user_sign_in.ui' | |||
108 | --- data/qt/current_user_sign_in.ui 2011-07-22 20:12:20 +0000 | |||
109 | +++ data/qt/current_user_sign_in.ui 2011-08-25 19:16:19 +0000 | |||
110 | @@ -6,14 +6,14 @@ | |||
111 | 6 | <rect> | 6 | <rect> |
112 | 7 | <x>0</x> | 7 | <x>0</x> |
113 | 8 | <y>0</y> | 8 | <y>0</y> |
116 | 9 | <width>400</width> | 9 | <width>399</width> |
117 | 10 | <height>300</height> | 10 | <height>309</height> |
118 | 11 | </rect> | 11 | </rect> |
119 | 12 | </property> | 12 | </property> |
120 | 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
121 | 14 | <string>WizardPage</string> | 14 | <string>WizardPage</string> |
122 | 15 | </property> | 15 | </property> |
124 | 16 | <layout class="QHBoxLayout" name="horizontalLayout"> | 16 | <layout class="QVBoxLayout" name="verticalLayout_4"> |
125 | 17 | <item> | 17 | <item> |
126 | 18 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | 18 | <layout class="QHBoxLayout" name="horizontalLayout_3"> |
127 | 19 | <item> | 19 | <item> |
128 | @@ -122,6 +122,9 @@ | |||
129 | 122 | </item> | 122 | </item> |
130 | 123 | <item> | 123 | <item> |
131 | 124 | <widget class="QPushButton" name="sign_in_button"> | 124 | <widget class="QPushButton" name="sign_in_button"> |
132 | 125 | <property name="enabled"> | ||
133 | 126 | <bool>false</bool> | ||
134 | 127 | </property> | ||
135 | 125 | <property name="text"> | 128 | <property name="text"> |
136 | 126 | <string>Sign In</string> | 129 | <string>Sign In</string> |
137 | 127 | </property> | 130 | </property> |
138 | 128 | 131 | ||
139 | === modified file 'data/qt/email_verification.ui' | |||
140 | --- data/qt/email_verification.ui 2011-06-24 19:14:17 +0000 | |||
141 | +++ data/qt/email_verification.ui 2011-08-25 19:16:19 +0000 | |||
142 | @@ -13,7 +13,7 @@ | |||
143 | 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
144 | 14 | <string>WizardPage</string> | 14 | <string>WizardPage</string> |
145 | 15 | </property> | 15 | </property> |
147 | 16 | <layout class="QHBoxLayout" name="horizontalLayout"> | 16 | <layout class="QVBoxLayout" name="verticalLayout_2"> |
148 | 17 | <item> | 17 | <item> |
149 | 18 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | 18 | <layout class="QHBoxLayout" name="horizontalLayout_3"> |
150 | 19 | <item> | 19 | <item> |
151 | 20 | 20 | ||
152 | === modified file 'data/qt/forgotten_password.ui' | |||
153 | --- data/qt/forgotten_password.ui 2011-06-24 19:14:17 +0000 | |||
154 | +++ data/qt/forgotten_password.ui 2011-08-25 19:16:19 +0000 | |||
155 | @@ -7,7 +7,7 @@ | |||
156 | 7 | <x>0</x> | 7 | <x>0</x> |
157 | 8 | <y>0</y> | 8 | <y>0</y> |
158 | 9 | <width>446</width> | 9 | <width>446</width> |
160 | 10 | <height>209</height> | 10 | <height>317</height> |
161 | 11 | </rect> | 11 | </rect> |
162 | 12 | </property> | 12 | </property> |
163 | 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
164 | @@ -109,6 +109,9 @@ | |||
165 | 109 | </item> | 109 | </item> |
166 | 110 | <item> | 110 | <item> |
167 | 111 | <widget class="QPushButton" name="send_button"> | 111 | <widget class="QPushButton" name="send_button"> |
168 | 112 | <property name="enabled"> | ||
169 | 113 | <bool>false</bool> | ||
170 | 114 | </property> | ||
171 | 112 | <property name="text"> | 115 | <property name="text"> |
172 | 113 | <string/> | 116 | <string/> |
173 | 114 | </property> | 117 | </property> |
174 | 115 | 118 | ||
175 | === modified file 'data/qt/reset_password.ui' | |||
176 | --- data/qt/reset_password.ui 2011-06-24 19:14:17 +0000 | |||
177 | +++ data/qt/reset_password.ui 2011-08-25 19:16:19 +0000 | |||
178 | @@ -7,7 +7,7 @@ | |||
179 | 7 | <x>0</x> | 7 | <x>0</x> |
180 | 8 | <y>0</y> | 8 | <y>0</y> |
181 | 9 | <width>476</width> | 9 | <width>476</width> |
183 | 10 | <height>282</height> | 10 | <height>262</height> |
184 | 11 | </rect> | 11 | </rect> |
185 | 12 | </property> | 12 | </property> |
186 | 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
187 | @@ -65,6 +65,9 @@ | |||
188 | 65 | </item> | 65 | </item> |
189 | 66 | <item> | 66 | <item> |
190 | 67 | <widget class="QPushButton" name="reset_password_button"> | 67 | <widget class="QPushButton" name="reset_password_button"> |
191 | 68 | <property name="enabled"> | ||
192 | 69 | <bool>false</bool> | ||
193 | 70 | </property> | ||
194 | 68 | <property name="text"> | 71 | <property name="text"> |
195 | 69 | <string/> | 72 | <string/> |
196 | 70 | </property> | 73 | </property> |
197 | 71 | 74 | ||
198 | === modified file 'data/qt/setup_account.ui' | |||
199 | --- data/qt/setup_account.ui 2011-06-24 19:14:17 +0000 | |||
200 | +++ data/qt/setup_account.ui 2011-08-25 19:16:19 +0000 | |||
201 | @@ -7,29 +7,16 @@ | |||
202 | 7 | <x>0</x> | 7 | <x>0</x> |
203 | 8 | <y>0</y> | 8 | <y>0</y> |
204 | 9 | <width>407</width> | 9 | <width>407</width> |
206 | 10 | <height>453</height> | 10 | <height>572</height> |
207 | 11 | </rect> | 11 | </rect> |
208 | 12 | </property> | 12 | </property> |
209 | 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
210 | 14 | <string>WizardPage</string> | 14 | <string>WizardPage</string> |
211 | 15 | </property> | 15 | </property> |
213 | 16 | <layout class="QHBoxLayout" name="horizontalLayout"> | 16 | <layout class="QVBoxLayout" name="verticalLayout_5"> |
214 | 17 | <item> | 17 | <item> |
215 | 18 | <layout class="QVBoxLayout" name="verticalLayout"> | 18 | <layout class="QVBoxLayout" name="verticalLayout"> |
216 | 19 | <item> | 19 | <item> |
217 | 20 | <spacer name="verticalSpacer_3"> | ||
218 | 21 | <property name="orientation"> | ||
219 | 22 | <enum>Qt::Vertical</enum> | ||
220 | 23 | </property> | ||
221 | 24 | <property name="sizeHint" stdset="0"> | ||
222 | 25 | <size> | ||
223 | 26 | <width>20</width> | ||
224 | 27 | <height>40</height> | ||
225 | 28 | </size> | ||
226 | 29 | </property> | ||
227 | 30 | </spacer> | ||
228 | 31 | </item> | ||
229 | 32 | <item> | ||
230 | 33 | <widget class="QFrame" name="_signInFrame"> | 20 | <widget class="QFrame" name="_signInFrame"> |
231 | 34 | <property name="frameShape"> | 21 | <property name="frameShape"> |
232 | 35 | <enum>QFrame::NoFrame</enum> | 22 | <enum>QFrame::NoFrame</enum> |
233 | 36 | 23 | ||
234 | === modified file 'debian/changelog' | |||
235 | --- debian/changelog 2011-07-26 13:58:21 +0000 | |||
236 | +++ debian/changelog 2011-08-25 19:16:19 +0000 | |||
237 | @@ -1,3 +1,10 @@ | |||
238 | 1 | ubuntu-sso-client (1.3.3-0ubuntu1) oneiric; urgency=low | ||
239 | 2 | |||
240 | 3 | * New upstream release. | ||
241 | 4 | - Work correctly with static and GI bindings of gobject (LP: #829186) | ||
242 | 5 | |||
243 | 6 | -- Rodney Dawes <rodney.dawes@ubuntu.com> Thu, 25 Aug 2011 15:08:27 -0400 | ||
244 | 7 | |||
245 | 1 | ubuntu-sso-client (1.3.2-0ubuntu2) oneiric; urgency=low | 8 | ubuntu-sso-client (1.3.2-0ubuntu2) oneiric; urgency=low |
246 | 2 | 9 | ||
247 | 3 | * Require python-qt4 to build, as distutils doesn't have optional deps | 10 | * Require python-qt4 to build, as distutils doesn't have optional deps |
248 | 4 | 11 | ||
249 | === modified file 'run-tests' | |||
250 | --- run-tests 2011-07-22 20:12:20 +0000 | |||
251 | +++ run-tests 2011-08-25 19:16:19 +0000 | |||
252 | @@ -16,8 +16,18 @@ | |||
253 | 16 | # You should have received a copy of the GNU General Public License along | 16 | # You should have received a copy of the GNU General Public License along |
254 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
255 | 18 | 18 | ||
256 | 19 | QT_TESTS_PATH=ubuntu_sso/qt/tests | ||
257 | 20 | GTK_TESTS_PATH=ubuntu_sso/gtk/tests | ||
258 | 21 | |||
259 | 19 | set -e | 22 | set -e |
260 | 20 | 23 | ||
261 | 24 | if [ "$1" == "-qt" ]; then | ||
262 | 25 | USE_QT=1 | ||
263 | 26 | shift | ||
264 | 27 | else | ||
265 | 28 | USE_QT=0 | ||
266 | 29 | fi | ||
267 | 30 | |||
268 | 21 | if [ $# -ne 0 ]; then | 31 | if [ $# -ne 0 ]; then |
269 | 22 | # run specific module given by the caller | 32 | # run specific module given by the caller |
270 | 23 | MODULE="$@" | 33 | MODULE="$@" |
271 | @@ -30,7 +40,7 @@ | |||
272 | 30 | ./setup.py clean | 40 | ./setup.py clean |
273 | 31 | u1lint | 41 | u1lint |
274 | 32 | if [ -x `which pep8` ]; then | 42 | if [ -x `which pep8` ]; then |
276 | 33 | pep8 --repeat bin/ $MODULE | 43 | pep8 --repeat . |
277 | 34 | else | 44 | else |
278 | 35 | echo "Please install the 'pep8' package." | 45 | echo "Please install the 'pep8' package." |
279 | 36 | fi | 46 | fi |
280 | @@ -39,6 +49,12 @@ | |||
281 | 39 | unset GTK_MODULES | 49 | unset GTK_MODULES |
282 | 40 | 50 | ||
283 | 41 | echo "Running test suite for ""$MODULE" | 51 | echo "Running test suite for ""$MODULE" |
285 | 42 | `which xvfb-run` u1trial "$MODULE" -i "test_windows.py, test_qt_views.py" | 52 | if [ "$USE_QT" -eq 0 ]; then |
286 | 53 | `which xvfb-run` u1trial -p "$QT_TESTS_PATH" -i "test_windows.py" "$MODULE" | ||
287 | 54 | else | ||
288 | 55 | ./setup.py build | ||
289 | 56 | `which xvfb-run` u1trial -p "$GTK_TESTS_PATH" -i "test_windows.py" --reactor=qt4 --gui "$MODULE" | ||
290 | 57 | fi | ||
291 | 43 | style_check | 58 | style_check |
292 | 44 | rm -rf _trial_temp | 59 | rm -rf _trial_temp |
293 | 60 | rm -rf build | ||
294 | 45 | 61 | ||
295 | === modified file 'run-tests.bat' | |||
296 | --- run-tests.bat 2011-07-22 20:12:20 +0000 | |||
297 | +++ run-tests.bat 2011-08-25 19:16:19 +0000 | |||
298 | @@ -60,13 +60,11 @@ | |||
299 | 60 | ECHO Cleaning the generated code before running the style checks... | 60 | ECHO Cleaning the generated code before running the style checks... |
300 | 61 | "%PYTHONEXEPATH%\python.exe" setup.py clean | 61 | "%PYTHONEXEPATH%\python.exe" setup.py clean |
301 | 62 | ECHO Performing style checks... | 62 | ECHO Performing style checks... |
303 | 63 | "%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1lint" ubuntu_sso | 63 | SET IGNORE_LINT="ubuntu_sso\gtk,ubuntu_sso\networkstate\linux.py,ubuntu_sso\main\linux.py,ubuntu_sso\main\tests\test_linux.py,ubuntu_sso\utils\txsecrets.py,ubuntu_sso\utils\tests\test_txsecrets.py,ubuntu_sso\tests\bin,bin\ubuntu-sso-login" |
304 | 64 | "%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1lint" -i "%IGNORE_LINT%" ubuntu_sso | ||
305 | 64 | :: test for style if we can, if pep8 is not present, move to the end | 65 | :: test for style if we can, if pep8 is not present, move to the end |
310 | 65 | IF EXIST "%PYTHONEXEPATH%\Scripts\pep8.exe" | 66 | "%PYTHONEXEPATH%\Scripts\pep8.exe" --repeat . |
307 | 66 | "%PYTHONEXEPATH%\Scripts\pep8.exe" --repeat ubuntu_sso | ||
308 | 67 | ELSE | ||
309 | 68 | ECHO Style checks were not done | ||
311 | 69 | :: Delete the temp folders | 67 | :: Delete the temp folders |
314 | 70 | RMDIR /s /q _trial_temp | 68 | RMDIR /q /s _trial_temp |
315 | 71 | RMDIR /s /q .coverage | 69 | RMDIR /q /s .coverage |
316 | 72 | :END | 70 | :END |
317 | 73 | 71 | ||
318 | === modified file 'setup.py' | |||
319 | --- setup.py 2011-07-22 20:12:20 +0000 | |||
320 | +++ setup.py 2011-08-25 19:16:19 +0000 | |||
321 | @@ -22,6 +22,7 @@ | |||
322 | 22 | 22 | ||
323 | 23 | # pylint: disable=W0404, W0511 | 23 | # pylint: disable=W0404, W0511 |
324 | 24 | 24 | ||
325 | 25 | import distutils | ||
326 | 25 | import os | 26 | import os |
327 | 26 | import sys | 27 | import sys |
328 | 27 | 28 | ||
329 | @@ -43,6 +44,7 @@ | |||
330 | 43 | CLEANFILES = [SERVICE_FILE, POT_FILE, 'MANIFEST'] | 44 | CLEANFILES = [SERVICE_FILE, POT_FILE, 'MANIFEST'] |
331 | 44 | QT_UI_DIR = os.path.join('ubuntu_sso', 'qt') | 45 | QT_UI_DIR = os.path.join('ubuntu_sso', 'qt') |
332 | 45 | 46 | ||
333 | 47 | |||
334 | 46 | def replace_prefix(prefix): | 48 | def replace_prefix(prefix): |
335 | 47 | """Replace every '@prefix@' with prefix within 'filename' content.""" | 49 | """Replace every '@prefix@' with prefix within 'filename' content.""" |
336 | 48 | # replace .service file | 50 | # replace .service file |
337 | @@ -242,7 +244,7 @@ | |||
338 | 242 | # this some day. If this doesn't work, try import modulefinder | 244 | # this some day. If this doesn't work, try import modulefinder |
339 | 243 | for package_path in win32com.__path__[1:]: | 245 | for package_path in win32com.__path__[1:]: |
340 | 244 | modulefinder.AddPackagePath("win32com", package_path) | 246 | modulefinder.AddPackagePath("win32com", package_path) |
342 | 245 | for extra_mod in ["win32com.server" ,"win32com.client"]: | 247 | for extra_mod in ["win32com.server", "win32com.client"]: |
343 | 246 | __import__(extra_mod) | 248 | __import__(extra_mod) |
344 | 247 | module = sys.modules[extra_mod] | 249 | module = sys.modules[extra_mod] |
345 | 248 | for module_path in module.__path__[1:]: | 250 | for module_path in module.__path__[1:]: |
346 | @@ -251,7 +253,7 @@ | |||
347 | 251 | # lazr uses namespaces packages, which does add some problems to py2exe | 253 | # lazr uses namespaces packages, which does add some problems to py2exe |
348 | 252 | # the following is a way to work arround the issue | 254 | # the following is a way to work arround the issue |
349 | 253 | for path in lazr.__path__: | 255 | for path in lazr.__path__: |
351 | 254 | modulefinder.AddPackagePath(__name__, path) | 256 | modulefinder.AddPackagePath(__name__, path) |
352 | 255 | 257 | ||
353 | 256 | 258 | ||
354 | 257 | def get_py2exe_extension(): | 259 | def get_py2exe_extension(): |
355 | @@ -261,14 +263,10 @@ | |||
356 | 261 | from py2exe.build_exe import py2exe as build_exe | 263 | from py2exe.build_exe import py2exe as build_exe |
357 | 262 | # pylint: enable=F0401 | 264 | # pylint: enable=F0401 |
358 | 263 | 265 | ||
360 | 264 | # pylint: disable=E1101 | 266 | # pylint: disable=E1101,W0232 |
361 | 265 | class MediaCollector(build_exe): | 267 | class MediaCollector(build_exe): |
362 | 266 | """Extension that copies lazr missing data.""" | 268 | """Extension that copies lazr missing data.""" |
363 | 267 | 269 | ||
364 | 268 | def __init__(self, *args, **kwargs): | ||
365 | 269 | """Create a new instance.""" | ||
366 | 270 | build_exe.__init__(self, *args, **kwargs) | ||
367 | 271 | |||
368 | 272 | def _add_module_data(self, module_name): | 270 | def _add_module_data(self, module_name): |
369 | 273 | """Add the data from a given path.""" | 271 | """Add the data from a given path.""" |
370 | 274 | # Create the media subdir where the | 272 | # Create the media subdir where the |
371 | @@ -310,6 +308,24 @@ | |||
372 | 310 | 'clean': SSOClean, | 308 | 'clean': SSOClean, |
373 | 311 | } | 309 | } |
374 | 312 | 310 | ||
375 | 311 | |||
376 | 312 | class dummy_build_i18n(distutils.cmd.Command): | ||
377 | 313 | |||
378 | 314 | """Dummy for windows.""" | ||
379 | 315 | |||
380 | 316 | def initialize_options(self, *args): | ||
381 | 317 | """Dummy.""" | ||
382 | 318 | |||
383 | 319 | def finalize_options(self, *args): | ||
384 | 320 | """Dummy.""" | ||
385 | 321 | |||
386 | 322 | def run(self, *args): | ||
387 | 323 | """Dummy.""" | ||
388 | 324 | |||
389 | 325 | if sys.platform == 'win32': | ||
390 | 326 | cmdclass['build_i18n'] = dummy_build_i18n | ||
391 | 327 | |||
392 | 328 | |||
393 | 313 | def setup_windows(): | 329 | def setup_windows(): |
394 | 314 | """Provide the required info to setup the project on windows.""" | 330 | """Provide the required info to setup the project on windows.""" |
395 | 315 | set_py2exe_paths() | 331 | set_py2exe_paths() |
396 | @@ -329,7 +345,7 @@ | |||
397 | 329 | }, | 345 | }, |
398 | 330 | }, | 346 | }, |
399 | 331 | # add the console script so that py2exe compiles it | 347 | # add the console script so that py2exe compiles it |
401 | 332 | 'console': ['bin/windows-ubuntu-sso-login',], | 348 | 'console': ['bin/windows-ubuntu-sso-login'], |
402 | 333 | 'zipfile': None, | 349 | 'zipfile': None, |
403 | 334 | } | 350 | } |
404 | 335 | return _data_files, _extra | 351 | return _data_files, _extra |
405 | @@ -344,7 +360,7 @@ | |||
406 | 344 | 360 | ||
407 | 345 | DistUtilsExtra.auto.setup( | 361 | DistUtilsExtra.auto.setup( |
408 | 346 | name='ubuntu-sso-client', | 362 | name='ubuntu-sso-client', |
410 | 347 | version='1.3.2', | 363 | version='1.3.3', |
411 | 348 | license='GPL v3', | 364 | license='GPL v3', |
412 | 349 | author='Natalia Bidart', | 365 | author='Natalia Bidart', |
413 | 350 | author_email='natalia.bidart@canonical.com', | 366 | author_email='natalia.bidart@canonical.com', |
414 | @@ -355,9 +371,14 @@ | |||
415 | 355 | extra_path='ubuntu-sso-client', | 371 | extra_path='ubuntu-sso-client', |
416 | 356 | data_files=data_files, | 372 | data_files=data_files, |
417 | 357 | packages=[ | 373 | packages=[ |
421 | 358 | 'ubuntu_sso', 'ubuntu_sso.utils', 'ubuntu_sso.keyring', | 374 | 'ubuntu_sso', |
422 | 359 | 'ubuntu_sso.networkstate', 'ubuntu_sso.main', | 375 | 'ubuntu_sso.utils', |
423 | 360 | 'ubuntu_sso.gtk', 'ubuntu_sso.qt', | 376 | 'ubuntu_sso.keyring', |
424 | 377 | 'ubuntu_sso.networkstate', | ||
425 | 378 | 'ubuntu_sso.main', | ||
426 | 379 | 'ubuntu_sso.gtk', | ||
427 | 380 | 'ubuntu_sso.qt', | ||
428 | 381 | 'ubuntu_sso.xdg_base_directory', | ||
429 | 361 | ], | 382 | ], |
430 | 362 | cmdclass=cmdclass, | 383 | cmdclass=cmdclass, |
431 | 363 | **extra) | 384 | **extra) |
432 | 364 | 385 | ||
433 | === modified file 'ubuntu_sso/credentials.py' | |||
434 | --- ubuntu_sso/credentials.py 2011-01-12 18:56:56 +0000 | |||
435 | +++ ubuntu_sso/credentials.py 2011-08-25 19:16:19 +0000 | |||
436 | @@ -43,14 +43,12 @@ | |||
437 | 43 | 43 | ||
438 | 44 | from functools import wraps | 44 | from functools import wraps |
439 | 45 | 45 | ||
440 | 46 | from oauth import oauth | ||
441 | 47 | from twisted.internet.defer import inlineCallbacks, returnValue | 46 | from twisted.internet.defer import inlineCallbacks, returnValue |
442 | 48 | 47 | ||
444 | 49 | from ubuntu_sso import NO_OP | 48 | from ubuntu_sso import NO_OP, utils |
445 | 50 | from ubuntu_sso.keyring import Keyring | 49 | from ubuntu_sso.keyring import Keyring |
446 | 51 | from ubuntu_sso.logger import setup_logging | 50 | from ubuntu_sso.logger import setup_logging |
447 | 52 | 51 | ||
448 | 53 | |||
449 | 54 | logger = setup_logging('ubuntu_sso.credentials') | 52 | logger = setup_logging('ubuntu_sso.credentials') |
450 | 55 | 53 | ||
451 | 56 | 54 | ||
452 | @@ -183,7 +181,7 @@ | |||
453 | 183 | self._success_cb = success_cb | 181 | self._success_cb = success_cb |
454 | 184 | self._error_cb = error_cb | 182 | self._error_cb = error_cb |
455 | 185 | self.denial_cb = denial_cb | 183 | self.denial_cb = denial_cb |
457 | 186 | self.gui = None # will hold the GUI instance | 184 | self.inner = None # will hold the GUI or SSOLoginRoot instance |
458 | 187 | 185 | ||
459 | 188 | @handle_failures(msg='Problem while retrieving credentials') | 186 | @handle_failures(msg='Problem while retrieving credentials') |
460 | 189 | @inlineCallbacks | 187 | @inlineCallbacks |
461 | @@ -226,27 +224,28 @@ | |||
462 | 226 | defined if this method is being called. | 224 | defined if this method is being called. |
463 | 227 | 225 | ||
464 | 228 | """ | 226 | """ |
479 | 229 | logger.info('Pinging server for app_name "%s", ping_url: "%s", ' | 227 | logger.info('Pinging server for app_name %r, ping_url: %r, ' |
480 | 230 | 'email "%s".', app_name, self.ping_url, email) | 228 | 'email %r.', app_name, self.ping_url, email) |
481 | 231 | url = self.ping_url + email | 229 | try: |
482 | 232 | consumer = oauth.OAuthConsumer(credentials['consumer_key'], | 230 | url = self.ping_url.format(email=email) |
483 | 233 | credentials['consumer_secret']) | 231 | except IndexError: # tuple index out of range |
484 | 234 | token = oauth.OAuthToken(credentials['token'], | 232 | url = self.ping_url.format(email) # format the first substitution |
485 | 235 | credentials['token_secret']) | 233 | |
486 | 236 | get_request = oauth.OAuthRequest.from_consumer_and_token | 234 | if url == self.ping_url: |
487 | 237 | oauth_req = get_request(oauth_consumer=consumer, token=token, | 235 | logger.debug('Original url (%r) could not be formatted, ' |
488 | 238 | http_method='GET', http_url=url) | 236 | 'appending email (%r).', self.ping_url, email) |
489 | 239 | oauth_req.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(), | 237 | url = self.ping_url + email |
490 | 240 | consumer, token) | 238 | |
491 | 241 | request = urllib2.Request(url, headers=oauth_req.to_header()) | 239 | headers = utils.oauth_headers(url, credentials) |
492 | 242 | logger.debug('Opening the url "%s" with urllib2.urlopen.', | 240 | request = urllib2.Request(url, headers=headers) |
493 | 241 | logger.debug('Opening the url %r with urllib2.urlopen.', | ||
494 | 243 | request.get_full_url()) | 242 | request.get_full_url()) |
495 | 244 | # This code is blocking, we should change this. | 243 | # This code is blocking, we should change this. |
496 | 245 | # I've tried with deferToThread an twisted.web.client.getPage | 244 | # I've tried with deferToThread an twisted.web.client.getPage |
497 | 246 | # but the returned deferred will never be fired (nataliabidart). | 245 | # but the returned deferred will never be fired (nataliabidart). |
498 | 247 | response = urllib2.urlopen(request) | 246 | response = urllib2.urlopen(request) |
499 | 248 | logger.debug('Url opened. Response: %s.', response.code) | 247 | logger.debug('Url opened. Response: %s.', response.code) |
501 | 249 | returnValue(response.code) | 248 | returnValue(response) |
502 | 250 | 249 | ||
503 | 251 | @handle_exceptions(msg='Problem opening the Ubuntu SSO user interface') | 250 | @handle_exceptions(msg='Problem opening the Ubuntu SSO user interface') |
504 | 252 | def _show_ui(self, login_only): | 251 | def _show_ui(self, login_only): |
505 | @@ -255,23 +254,39 @@ | |||
506 | 255 | __import__(self.ui_module) | 254 | __import__(self.ui_module) |
507 | 256 | gui = sys.modules[self.ui_module] | 255 | gui = sys.modules[self.ui_module] |
508 | 257 | 256 | ||
510 | 258 | self.gui = getattr(gui, self.ui_class)(app_name=self.app_name, | 257 | self.inner = getattr(gui, self.ui_class)(app_name=self.app_name, |
511 | 259 | tc_url=self.tc_url, help_text=self.help_text, | 258 | tc_url=self.tc_url, help_text=self.help_text, |
512 | 260 | window_id=self.window_id, login_only=login_only) | 259 | window_id=self.window_id, login_only=login_only) |
513 | 261 | 260 | ||
517 | 262 | self.gui.login_success_callback = self._login_success_cb | 261 | self.inner.login_success_callback = self._login_success_cb |
518 | 263 | self.gui.registration_success_callback = self._login_success_cb | 262 | self.inner.registration_success_callback = self._login_success_cb |
519 | 264 | self.gui.user_cancellation_callback = self._auth_denial_cb | 263 | self.inner.user_cancellation_callback = self._auth_denial_cb |
520 | 264 | |||
521 | 265 | @handle_exceptions(msg='Problem logging with email and password.') | ||
522 | 266 | def _do_login(self, email, password): | ||
523 | 267 | """Login using email/password, connect outcome signals.""" | ||
524 | 268 | from ubuntu_sso.main import SSOLoginRoot | ||
525 | 269 | self.inner = SSOLoginRoot() | ||
526 | 270 | self.inner.login(app_name=self.app_name, email=email, | ||
527 | 271 | password=password, | ||
528 | 272 | result_cb=self._login_success_cb, | ||
529 | 273 | error_cb=self._error_cb, | ||
530 | 274 | not_validated_cb=self._error_cb) | ||
531 | 265 | 275 | ||
532 | 266 | @handle_failures(msg='Problem while retrieving credentials') | 276 | @handle_failures(msg='Problem while retrieving credentials') |
533 | 267 | @inlineCallbacks | 277 | @inlineCallbacks |
535 | 268 | def _login_or_register(self, login_only): | 278 | def _login_or_register(self, login_only, email=None, password=None): |
536 | 269 | """Get credentials if found else prompt the GUI.""" | 279 | """Get credentials if found else prompt the GUI.""" |
537 | 280 | logger.info("_login_or_register: login_only=%r email=%r.", | ||
538 | 281 | login_only, email) | ||
539 | 270 | token = yield self.find_credentials() | 282 | token = yield self.find_credentials() |
540 | 271 | if token is not None and len(token) > 0: | 283 | if token is not None and len(token) > 0: |
541 | 272 | self.success_cb(token) | 284 | self.success_cb(token) |
542 | 273 | elif token == {}: | 285 | elif token == {}: |
544 | 274 | self._show_ui(login_only) | 286 | if email and password: |
545 | 287 | self._do_login(email, password) | ||
546 | 288 | else: | ||
547 | 289 | self._show_ui(login_only) | ||
548 | 275 | else: | 290 | else: |
549 | 276 | # something went wrong with find_credentials, already handled. | 291 | # something went wrong with find_credentials, already handled. |
550 | 277 | logger.info('_login_or_register: call to "find_credentials" went ' | 292 | logger.info('_login_or_register: call to "find_credentials" went ' |
551 | @@ -292,7 +307,7 @@ | |||
552 | 292 | def find_credentials(self): | 307 | def find_credentials(self): |
553 | 293 | """Get the credentials for 'self.app_name'. Return {} if not there.""" | 308 | """Get the credentials for 'self.app_name'. Return {} if not there.""" |
554 | 294 | creds = yield Keyring().get_credentials(self.app_name) | 309 | creds = yield Keyring().get_credentials(self.app_name) |
556 | 295 | logger.info('find_credentials: self.app_name "%s", ' | 310 | logger.info('find_credentials: self.app_name %r, ' |
557 | 296 | 'result is {}? %s', self.app_name, creds is None) | 311 | 'result is {}? %s', self.app_name, creds is None) |
558 | 297 | returnValue(creds if creds is not None else {}) | 312 | returnValue(creds if creds is not None else {}) |
559 | 298 | 313 | ||
560 | @@ -313,3 +328,8 @@ | |||
561 | 313 | def login(self): | 328 | def login(self): |
562 | 314 | """Get credentials if found else prompt the GUI to login.""" | 329 | """Get credentials if found else prompt the GUI to login.""" |
563 | 315 | return self._login_or_register(login_only=True) | 330 | return self._login_or_register(login_only=True) |
564 | 331 | |||
565 | 332 | def login_email_password(self, email, password): | ||
566 | 333 | """Get credentials if found else login using email and password.""" | ||
567 | 334 | return self._login_or_register(login_only=True, | ||
568 | 335 | email=email, password=password) | ||
569 | 316 | 336 | ||
570 | === modified file 'ubuntu_sso/logger.py' | |||
571 | --- ubuntu_sso/logger.py 2011-01-12 18:56:56 +0000 | |||
572 | +++ ubuntu_sso/logger.py 2011-08-25 19:16:19 +0000 | |||
573 | @@ -25,12 +25,11 @@ | |||
574 | 25 | import os | 25 | import os |
575 | 26 | import sys | 26 | import sys |
576 | 27 | 27 | ||
577 | 28 | import xdg.BaseDirectory | ||
578 | 29 | |||
579 | 30 | from logging.handlers import RotatingFileHandler | 28 | from logging.handlers import RotatingFileHandler |
580 | 31 | 29 | ||
581 | 30 | from ubuntu_sso import xdg_base_directory | ||
582 | 32 | 31 | ||
584 | 33 | LOGFOLDER = os.path.join(xdg.BaseDirectory.xdg_cache_home, 'sso') | 32 | LOGFOLDER = os.path.join(xdg_base_directory.xdg_cache_home, 'sso') |
585 | 34 | # create log folder if it doesn't exists | 33 | # create log folder if it doesn't exists |
586 | 35 | if not os.path.exists(LOGFOLDER): | 34 | if not os.path.exists(LOGFOLDER): |
587 | 36 | os.makedirs(LOGFOLDER) | 35 | os.makedirs(LOGFOLDER) |
588 | 37 | 36 | ||
589 | === modified file 'ubuntu_sso/main/__init__.py' | |||
590 | --- ubuntu_sso/main/__init__.py 2011-07-22 20:12:20 +0000 | |||
591 | +++ ubuntu_sso/main/__init__.py 2011-08-25 19:16:19 +0000 | |||
592 | @@ -75,7 +75,7 @@ | |||
593 | 75 | self.processor = self.sso_login_processor_class( | 75 | self.processor = self.sso_login_processor_class( |
594 | 76 | sso_service_class=sso_service_class) | 76 | sso_service_class=sso_service_class) |
595 | 77 | 77 | ||
597 | 78 | def generate_captcha(self, app_name, filename, thread_execute, result_cb, | 78 | def generate_captcha(self, app_name, filename, result_cb, |
598 | 79 | error_cb): | 79 | error_cb): |
599 | 80 | """Call the matching method in the processor.""" | 80 | """Call the matching method in the processor.""" |
600 | 81 | def f(): | 81 | def f(): |
601 | @@ -84,7 +84,7 @@ | |||
602 | 84 | thread_execute(f, app_name, result_cb, error_cb) | 84 | thread_execute(f, app_name, result_cb, error_cb) |
603 | 85 | 85 | ||
604 | 86 | def register_user(self, app_name, email, password, name, captcha_id, | 86 | def register_user(self, app_name, email, password, name, captcha_id, |
606 | 87 | captcha_solution, thread_execute, result_cb, error_cb): | 87 | captcha_solution, result_cb, error_cb): |
607 | 88 | """Call the matching method in the processor.""" | 88 | """Call the matching method in the processor.""" |
608 | 89 | def f(): | 89 | def f(): |
609 | 90 | """Inner function that will be run in a thread.""" | 90 | """Inner function that will be run in a thread.""" |
610 | @@ -92,7 +92,7 @@ | |||
611 | 92 | captcha_id, captcha_solution) | 92 | captcha_id, captcha_solution) |
612 | 93 | thread_execute(f, app_name, result_cb, error_cb) | 93 | thread_execute(f, app_name, result_cb, error_cb) |
613 | 94 | 94 | ||
615 | 95 | def login(self, app_name, email, password, thread_execute, result_cb, | 95 | def login(self, app_name, email, password, result_cb, |
616 | 96 | error_cb, not_validated_cb): | 96 | error_cb, not_validated_cb): |
617 | 97 | """Call the matching method in the processor.""" | 97 | """Call the matching method in the processor.""" |
618 | 98 | def f(): | 98 | def f(): |
619 | @@ -121,7 +121,7 @@ | |||
620 | 121 | thread_execute(f, app_name, success_cb, error_cb) | 121 | thread_execute(f, app_name, success_cb, error_cb) |
621 | 122 | 122 | ||
622 | 123 | def validate_email(self, app_name, email, password, email_token, | 123 | def validate_email(self, app_name, email, password, email_token, |
624 | 124 | thread_execute, result_cb, error_cb): | 124 | result_cb, error_cb): |
625 | 125 | """Call the matching method in the processor.""" | 125 | """Call the matching method in the processor.""" |
626 | 126 | 126 | ||
627 | 127 | def f(): | 127 | def f(): |
628 | @@ -141,7 +141,7 @@ | |||
629 | 141 | 141 | ||
630 | 142 | thread_execute(f, app_name, success_cb, error_cb) | 142 | thread_execute(f, app_name, success_cb, error_cb) |
631 | 143 | 143 | ||
633 | 144 | def request_password_reset_token(self, app_name, email, thread_execute, | 144 | def request_password_reset_token(self, app_name, email, |
634 | 145 | result_cb, error_cb): | 145 | result_cb, error_cb): |
635 | 146 | """Call the matching method in the processor.""" | 146 | """Call the matching method in the processor.""" |
636 | 147 | def f(): | 147 | def f(): |
637 | @@ -150,7 +150,7 @@ | |||
638 | 150 | thread_execute(f, app_name, result_cb, error_cb) | 150 | thread_execute(f, app_name, result_cb, error_cb) |
639 | 151 | 151 | ||
640 | 152 | def set_new_password(self, app_name, email, token, new_password, | 152 | def set_new_password(self, app_name, email, token, new_password, |
642 | 153 | thread_execute, result_cb, error_cb): | 153 | result_cb, error_cb): |
643 | 154 | """Call the matching method in the processor.""" | 154 | """Call the matching method in the processor.""" |
644 | 155 | def f(): | 155 | def f(): |
645 | 156 | """Inner function that will be run in a thread.""" | 156 | """Inner function that will be run in a thread.""" |
646 | @@ -160,10 +160,16 @@ | |||
647 | 160 | 160 | ||
648 | 161 | 161 | ||
649 | 162 | class SSOCredentialsRoot(object): | 162 | class SSOCredentialsRoot(object): |
651 | 163 | """Object that gets credentials, and login/registers if needed.""" | 163 | """Object that gets credentials, and login/registers if needed. |
652 | 164 | |||
653 | 165 | This class is DEPRECATED, use CredentialsManagementRoot instead. | ||
654 | 166 | |||
655 | 167 | """ | ||
656 | 164 | 168 | ||
657 | 165 | def __init__(self): | 169 | def __init__(self): |
658 | 166 | self.ping_url = os.environ.get('USSOC_PING_URL', U1_PING_URL) | 170 | self.ping_url = os.environ.get('USSOC_PING_URL', U1_PING_URL) |
659 | 171 | msg = 'Use ubuntu_sso.main.CredentialsManagementRoot instead.' | ||
660 | 172 | warnings.warn(msg, DeprecationWarning) | ||
661 | 167 | 173 | ||
662 | 168 | def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): | 174 | def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): |
663 | 169 | """Get the credentials from the keyring or {} if not there.""" | 175 | """Get the credentials from the keyring or {} if not there.""" |
664 | @@ -399,6 +405,20 @@ | |||
665 | 399 | obj = Credentials(app_name, **self._parse_args(args)) | 405 | obj = Credentials(app_name, **self._parse_args(args)) |
666 | 400 | obj.login() | 406 | obj.login() |
667 | 401 | 407 | ||
668 | 408 | def login_email_password(self, app_name, args): | ||
669 | 409 | """Get credentials if found else try to login. | ||
670 | 410 | |||
671 | 411 | Login will be done by inspecting 'args' and expecting to find two keys: | ||
672 | 412 | 'email' and 'password'. | ||
673 | 413 | |||
674 | 414 | """ | ||
675 | 415 | self.ref_count += 1 | ||
676 | 416 | email = args.pop('email') | ||
677 | 417 | password = args.pop('password') | ||
678 | 418 | obj = Credentials(app_name, **self._parse_args(args)) | ||
679 | 419 | obj.login_email_password(email=email, password=password) | ||
680 | 420 | |||
681 | 421 | |||
682 | 402 | # pylint: disable=C0103 | 422 | # pylint: disable=C0103 |
683 | 403 | SSOLogin = None | 423 | SSOLogin = None |
684 | 404 | SSOCredentials = None | 424 | SSOCredentials = None |
685 | @@ -410,8 +430,10 @@ | |||
686 | 410 | SSOCredentials = windows.SSOCredentials | 430 | SSOCredentials = windows.SSOCredentials |
687 | 411 | CredentialsManagement = windows.CredentialsManagement | 431 | CredentialsManagement = windows.CredentialsManagement |
688 | 412 | TIMEOUT_INTERVAL = 10000000000 # forever | 432 | TIMEOUT_INTERVAL = 10000000000 # forever |
689 | 433 | thread_execute = windows.blocking | ||
690 | 413 | else: | 434 | else: |
691 | 414 | from ubuntu_sso.main import linux | 435 | from ubuntu_sso.main import linux |
692 | 415 | SSOLogin = linux.SSOLogin | 436 | SSOLogin = linux.SSOLogin |
693 | 416 | SSOCredentials = linux.SSOCredentials | 437 | SSOCredentials = linux.SSOCredentials |
694 | 417 | CredentialsManagement = linux.CredentialsManagement | 438 | CredentialsManagement = linux.CredentialsManagement |
695 | 439 | thread_execute = linux.blocking | ||
696 | 418 | 440 | ||
697 | === modified file 'ubuntu_sso/main/linux.py' | |||
698 | --- ubuntu_sso/main/linux.py 2011-06-24 19:14:17 +0000 | |||
699 | +++ ubuntu_sso/main/linux.py 2011-08-25 19:16:19 +0000 | |||
700 | @@ -74,6 +74,8 @@ | |||
701 | 74 | dbus.service.Object.__init__(self, object_path=object_path, | 74 | dbus.service.Object.__init__(self, object_path=object_path, |
702 | 75 | bus_name=bus_name) | 75 | bus_name=bus_name) |
703 | 76 | self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class) | 76 | self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class) |
704 | 77 | msg = 'Use ubuntu_sso.main.CredentialsManagement instead.' | ||
705 | 78 | warnings.warn(msg, DeprecationWarning) | ||
706 | 77 | 79 | ||
707 | 78 | # generate_capcha signals | 80 | # generate_capcha signals |
708 | 79 | @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss") | 81 | @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss") |
709 | @@ -92,7 +94,7 @@ | |||
710 | 92 | in_signature='ss') | 94 | in_signature='ss') |
711 | 93 | def generate_captcha(self, app_name, filename): | 95 | def generate_captcha(self, app_name, filename): |
712 | 94 | """Call the matching method in the processor.""" | 96 | """Call the matching method in the processor.""" |
714 | 95 | self.root.generate_captcha(app_name, filename, blocking, | 97 | self.root.generate_captcha(app_name, filename, |
715 | 96 | self.CaptchaGenerated, | 98 | self.CaptchaGenerated, |
716 | 97 | self.CaptchaGenerationError) | 99 | self.CaptchaGenerationError) |
717 | 98 | 100 | ||
718 | @@ -115,7 +117,7 @@ | |||
719 | 115 | captcha_id, captcha_solution): | 117 | captcha_id, captcha_solution): |
720 | 116 | """Call the matching method in the processor.""" | 118 | """Call the matching method in the processor.""" |
721 | 117 | self.root.register_user(app_name, email, password, name, captcha_id, | 119 | self.root.register_user(app_name, email, password, name, captcha_id, |
723 | 118 | captcha_solution, blocking, | 120 | captcha_solution, |
724 | 119 | self.UserRegistered, | 121 | self.UserRegistered, |
725 | 120 | self.UserRegistrationError) | 122 | self.UserRegistrationError) |
726 | 121 | 123 | ||
727 | @@ -142,7 +144,7 @@ | |||
728 | 142 | in_signature='sss') | 144 | in_signature='sss') |
729 | 143 | def login(self, app_name, email, password): | 145 | def login(self, app_name, email, password): |
730 | 144 | """Call the matching method in the processor.""" | 146 | """Call the matching method in the processor.""" |
732 | 145 | self.root.login(app_name, email, password, blocking, self.LoggedIn, | 147 | self.root.login(app_name, email, password, self.LoggedIn, |
733 | 146 | self.LoginError, self.UserNotValidated) | 148 | self.LoginError, self.UserNotValidated) |
734 | 147 | 149 | ||
735 | 148 | # validate_email signals | 150 | # validate_email signals |
736 | @@ -163,7 +165,7 @@ | |||
737 | 163 | def validate_email(self, app_name, email, password, email_token): | 165 | def validate_email(self, app_name, email, password, email_token): |
738 | 164 | """Call the matching method in the processor.""" | 166 | """Call the matching method in the processor.""" |
739 | 165 | self.root.validate_email(app_name, email, password, email_token, | 167 | self.root.validate_email(app_name, email, password, email_token, |
741 | 166 | blocking, self.EmailValidated, | 168 | self.EmailValidated, |
742 | 167 | self.EmailValidationError) | 169 | self.EmailValidationError) |
743 | 168 | 170 | ||
744 | 169 | # request_password_reset_token signals | 171 | # request_password_reset_token signals |
745 | @@ -183,7 +185,7 @@ | |||
746 | 183 | in_signature='ss') | 185 | in_signature='ss') |
747 | 184 | def request_password_reset_token(self, app_name, email): | 186 | def request_password_reset_token(self, app_name, email): |
748 | 185 | """Call the matching method in the processor.""" | 187 | """Call the matching method in the processor.""" |
750 | 186 | self.root.request_password_reset_token(app_name, email, blocking, | 188 | self.root.request_password_reset_token(app_name, email, |
751 | 187 | self.PasswordResetTokenSent, | 189 | self.PasswordResetTokenSent, |
752 | 188 | self.PasswordResetError) | 190 | self.PasswordResetError) |
753 | 189 | 191 | ||
754 | @@ -205,7 +207,7 @@ | |||
755 | 205 | def set_new_password(self, app_name, email, token, new_password): | 207 | def set_new_password(self, app_name, email, token, new_password): |
756 | 206 | """Call the matching method in the processor.""" | 208 | """Call the matching method in the processor.""" |
757 | 207 | self.root.set_new_password(app_name, email, token, new_password, | 209 | self.root.set_new_password(app_name, email, token, new_password, |
759 | 208 | blocking, self.PasswordChanged, | 210 | self.PasswordChanged, |
760 | 209 | self.PasswordChangeError) | 211 | self.PasswordChangeError) |
761 | 210 | 212 | ||
762 | 211 | 213 | ||
763 | @@ -462,3 +464,15 @@ | |||
764 | 462 | def login(self, app_name, args): | 464 | def login(self, app_name, args): |
765 | 463 | """Get credentials if found else prompt GUI to login.""" | 465 | """Get credentials if found else prompt GUI to login.""" |
766 | 464 | self.root.login(app_name, args) | 466 | self.root.login(app_name, args) |
767 | 467 | |||
768 | 468 | @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE, | ||
769 | 469 | in_signature='sa{ss}', out_signature='') | ||
770 | 470 | def login_email_password(self, app_name, args): | ||
771 | 471 | """Get credentials if found, else login using email and password. | ||
772 | 472 | |||
773 | 473 | - 'args' should contain at least the follwing keys: 'email' and | ||
774 | 474 | 'password'. Those will be used to issue a new SSO token, which will be | ||
775 | 475 | returned trough the CredentialsFound signal. | ||
776 | 476 | |||
777 | 477 | """ | ||
778 | 478 | self.root.login_email_password(app_name, args) | ||
779 | 465 | 479 | ||
780 | === modified file 'ubuntu_sso/main/tests/test_common.py' | |||
781 | --- ubuntu_sso/main/tests/test_common.py 2011-06-24 19:14:17 +0000 | |||
782 | +++ ubuntu_sso/main/tests/test_common.py 2011-08-25 19:16:19 +0000 | |||
783 | @@ -75,7 +75,7 @@ | |||
784 | 75 | """Test that the call is relayed.""" | 75 | """Test that the call is relayed.""" |
785 | 76 | app_name = 'app' | 76 | app_name = 'app' |
786 | 77 | filename = 'file' | 77 | filename = 'file' |
788 | 78 | self.root.generate_captcha(app_name, filename, MATCH(callable), | 78 | self.root.generate_captcha(app_name, filename, |
789 | 79 | MATCH(callable), MATCH(callable)) | 79 | MATCH(callable), MATCH(callable)) |
790 | 80 | self.mocker.replay() | 80 | self.mocker.replay() |
791 | 81 | self.login.generate_captcha(app_name, filename) | 81 | self.login.generate_captcha(app_name, filename) |
792 | @@ -89,7 +89,7 @@ | |||
793 | 89 | captcha_id = 'id' | 89 | captcha_id = 'id' |
794 | 90 | captcha_solution = 'hello' | 90 | captcha_solution = 'hello' |
795 | 91 | self.root.register_user(app_name, email, password, name, captcha_id, | 91 | self.root.register_user(app_name, email, password, name, captcha_id, |
797 | 92 | captcha_solution, MATCH(callable), | 92 | captcha_solution, |
798 | 93 | MATCH(callable), MATCH(callable)) | 93 | MATCH(callable), MATCH(callable)) |
799 | 94 | self.mocker.replay() | 94 | self.mocker.replay() |
800 | 95 | self.login.register_user(app_name, email, password, name, captcha_id, | 95 | self.login.register_user(app_name, email, password, name, captcha_id, |
801 | @@ -100,7 +100,7 @@ | |||
802 | 100 | app_name = 'app' | 100 | app_name = 'app' |
803 | 101 | email = 'email' | 101 | email = 'email' |
804 | 102 | password = 'password' | 102 | password = 'password' |
806 | 103 | self.root.login(app_name, email, password, MATCH(callable), | 103 | self.root.login(app_name, email, password, |
807 | 104 | MATCH(callable), MATCH(callable), | 104 | MATCH(callable), MATCH(callable), |
808 | 105 | MATCH(callable)) | 105 | MATCH(callable)) |
809 | 106 | self.mocker.mock() | 106 | self.mocker.mock() |
810 | @@ -114,18 +114,17 @@ | |||
811 | 114 | password = 'passwrd' | 114 | password = 'passwrd' |
812 | 115 | email_token = 'token' | 115 | email_token = 'token' |
813 | 116 | self.root.validate_email(app_name, email, password, email_token, | 116 | self.root.validate_email(app_name, email, password, email_token, |
815 | 117 | MATCH(callable), MATCH(callable), | 117 | MATCH(callable), |
816 | 118 | MATCH(callable)) | 118 | MATCH(callable)) |
817 | 119 | self.mocker.replay() | 119 | self.mocker.replay() |
818 | 120 | self.login.validate_email(app_name, email, password, email_token) | 120 | self.login.validate_email(app_name, email, password, email_token) |
819 | 121 | 121 | ||
821 | 122 | def test_request_password_reset_tolen(self): | 122 | def test_request_password_reset_token(self): |
822 | 123 | """Test that the call is relayed.""" | 123 | """Test that the call is relayed.""" |
823 | 124 | app_name = 'app' | 124 | app_name = 'app' |
824 | 125 | email = 'email' | 125 | email = 'email' |
825 | 126 | self.root.request_password_reset_token(app_name, email, | 126 | self.root.request_password_reset_token(app_name, email, |
826 | 127 | MATCH(callable), | 127 | MATCH(callable), |
827 | 128 | MATCH(callable), | ||
828 | 129 | MATCH(callable)) | 128 | MATCH(callable)) |
829 | 130 | self.mocker.replay() | 129 | self.mocker.replay() |
830 | 131 | self.login.request_password_reset_token(app_name, email) | 130 | self.login.request_password_reset_token(app_name, email) |
831 | @@ -137,7 +136,7 @@ | |||
832 | 137 | token = 'token' | 136 | token = 'token' |
833 | 138 | new_password = 'new' | 137 | new_password = 'new' |
834 | 139 | self.root.set_new_password(app_name, email, token, new_password, | 138 | self.root.set_new_password(app_name, email, token, new_password, |
836 | 140 | MATCH(callable), MATCH(callable), | 139 | MATCH(callable), |
837 | 141 | MATCH(callable)) | 140 | MATCH(callable)) |
838 | 142 | self.mocker.replay() | 141 | self.mocker.replay() |
839 | 143 | self.login.set_new_password(app_name, email, token, new_password) | 142 | self.login.set_new_password(app_name, email, token, new_password) |
840 | @@ -190,7 +189,7 @@ | |||
841 | 190 | self.cred.clear_token(app_name, result_cb, error_cb) | 189 | self.cred.clear_token(app_name, result_cb, error_cb) |
842 | 191 | 190 | ||
843 | 192 | 191 | ||
845 | 193 | class CredentialsManagementMockedTestCase(MockerTestCase): | 192 | class CredentialsManagementMockedTestCase(MockerTestCase, TestCase): |
846 | 194 | """Test that the call are relied correctly.""" | 193 | """Test that the call are relied correctly.""" |
847 | 195 | 194 | ||
848 | 196 | def setUp(self): | 195 | def setUp(self): |
849 | @@ -242,3 +241,11 @@ | |||
850 | 242 | self.root.login(app_name, args) | 241 | self.root.login(app_name, args) |
851 | 243 | self.mocker.replay() | 242 | self.mocker.replay() |
852 | 244 | self.cred.login(app_name, args) | 243 | self.cred.login(app_name, args) |
853 | 244 | |||
854 | 245 | def test_login_email_password(self): | ||
855 | 246 | """Test that the call is relayed.""" | ||
856 | 247 | app_name = 'app' | ||
857 | 248 | args = 'args' | ||
858 | 249 | self.root.login_email_password(app_name, args) | ||
859 | 250 | self.mocker.replay() | ||
860 | 251 | self.cred.login_email_password(app_name, args) | ||
861 | 245 | 252 | ||
862 | === modified file 'ubuntu_sso/main/tests/test_linux.py' | |||
863 | --- ubuntu_sso/main/tests/test_linux.py 2011-06-24 19:14:17 +0000 | |||
864 | +++ ubuntu_sso/main/tests/test_linux.py 2011-08-25 19:16:19 +0000 | |||
865 | @@ -144,7 +144,7 @@ | |||
866 | 144 | expected_result = "expected result" | 144 | expected_result = "expected result" |
867 | 145 | self.create_mock_processor().generate_captcha(filename) | 145 | self.create_mock_processor().generate_captcha(filename) |
868 | 146 | self.mocker.result(expected_result) | 146 | self.mocker.result(expected_result) |
870 | 147 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) | 147 | self.patch(ubuntu_sso.main, "thread_execute", fake_err_blocking) |
871 | 148 | self.mocker.replay() | 148 | self.mocker.replay() |
872 | 149 | 149 | ||
873 | 150 | def verify(app_name, errdict): | 150 | def verify(app_name, errdict): |
874 | @@ -191,7 +191,7 @@ | |||
875 | 191 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, | 191 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, |
876 | 192 | CAPTCHA_ID, CAPTCHA_SOLUTION) | 192 | CAPTCHA_ID, CAPTCHA_SOLUTION) |
877 | 193 | self.mocker.result(expected_result) | 193 | self.mocker.result(expected_result) |
879 | 194 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) | 194 | self.patch(ubuntu_sso.main, "thread_execute", fake_err_blocking) |
880 | 195 | self.mocker.replay() | 195 | self.mocker.replay() |
881 | 196 | 196 | ||
882 | 197 | def verify(app_name, errdict): | 197 | def verify(app_name, errdict): |
883 | @@ -377,7 +377,7 @@ | |||
884 | 377 | d = Deferred() | 377 | d = Deferred() |
885 | 378 | processor = self.create_mock_processor() | 378 | processor = self.create_mock_processor() |
886 | 379 | processor.request_password_reset_token(EMAIL) | 379 | processor.request_password_reset_token(EMAIL) |
888 | 380 | self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking) | 380 | self.patch(ubuntu_sso.main, "thread_execute", fake_ok_blocking) |
889 | 381 | self.mocker.result(EMAIL) | 381 | self.mocker.result(EMAIL) |
890 | 382 | self.mocker.replay() | 382 | self.mocker.replay() |
891 | 383 | 383 | ||
892 | @@ -400,7 +400,7 @@ | |||
893 | 400 | 400 | ||
894 | 401 | self.create_mock_processor().request_password_reset_token(EMAIL) | 401 | self.create_mock_processor().request_password_reset_token(EMAIL) |
895 | 402 | self.mocker.result(EMAIL) | 402 | self.mocker.result(EMAIL) |
897 | 403 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) | 403 | self.patch(ubuntu_sso.main, "thread_execute", fake_err_blocking) |
898 | 404 | self.mocker.replay() | 404 | self.mocker.replay() |
899 | 405 | 405 | ||
900 | 406 | def verify(app_name, errdict): | 406 | def verify(app_name, errdict): |
901 | @@ -446,7 +446,7 @@ | |||
902 | 446 | self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN, | 446 | self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN, |
903 | 447 | PASSWORD) | 447 | PASSWORD) |
904 | 448 | self.mocker.result(expected_result) | 448 | self.mocker.result(expected_result) |
906 | 449 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) | 449 | self.patch(ubuntu_sso.main, "thread_execute", fake_err_blocking) |
907 | 450 | self.mocker.replay() | 450 | self.mocker.replay() |
908 | 451 | 451 | ||
909 | 452 | def verify(app_name, errdict): | 452 | def verify(app_name, errdict): |
910 | @@ -1222,6 +1222,17 @@ | |||
911 | 1222 | self.client.login(APP_NAME, self.args) | 1222 | self.client.login(APP_NAME, self.args) |
912 | 1223 | self.assert_dbus_method_correct(self.client.login) | 1223 | self.assert_dbus_method_correct(self.client.login) |
913 | 1224 | 1224 | ||
914 | 1225 | def test_login_email_password(self): | ||
915 | 1226 | """The login_email_password is correct.""" | ||
916 | 1227 | self.create_mock_backend().login_email_password(email=EMAIL, | ||
917 | 1228 | password=PASSWORD) | ||
918 | 1229 | self.mocker.replay() | ||
919 | 1230 | |||
920 | 1231 | self.args['email'] = EMAIL | ||
921 | 1232 | self.args['password'] = PASSWORD | ||
922 | 1233 | self.client.login_email_password(APP_NAME, self.args) | ||
923 | 1234 | self.assert_dbus_method_correct(self.client.login_email_password) | ||
924 | 1235 | |||
925 | 1225 | 1236 | ||
926 | 1226 | class CredentialsManagementParamsTestCase(CredentialsManagementOpsTestCase): | 1237 | class CredentialsManagementParamsTestCase(CredentialsManagementOpsTestCase): |
927 | 1227 | """Tests for the CredentialsManagement extra parameters handling.""" | 1238 | """Tests for the CredentialsManagement extra parameters handling.""" |
928 | 1228 | 1239 | ||
929 | === modified file 'ubuntu_sso/main/tests/test_windows.py' | |||
930 | --- ubuntu_sso/main/tests/test_windows.py 2011-07-22 20:12:20 +0000 | |||
931 | +++ ubuntu_sso/main/tests/test_windows.py 2011-08-25 19:16:19 +0000 | |||
932 | @@ -30,10 +30,10 @@ | |||
933 | 30 | ) | 30 | ) |
934 | 31 | from ubuntu_sso.main import windows | 31 | from ubuntu_sso.main import windows |
935 | 32 | from ubuntu_sso.main.windows import ( | 32 | from ubuntu_sso.main.windows import ( |
936 | 33 | blocking, | ||
937 | 34 | signal, | 33 | signal, |
938 | 35 | CredentialsManagement, | 34 | CredentialsManagement, |
939 | 36 | CredentialsManagementClient, | 35 | CredentialsManagementClient, |
940 | 36 | LOCALHOST, | ||
941 | 37 | SignalBroadcaster, | 37 | SignalBroadcaster, |
942 | 38 | SSOCredentials, | 38 | SSOCredentials, |
943 | 39 | SSOCredentialsClient, | 39 | SSOCredentialsClient, |
944 | @@ -41,7 +41,8 @@ | |||
945 | 41 | SSOLoginClient, | 41 | SSOLoginClient, |
946 | 42 | UbuntuSSORoot, | 42 | UbuntuSSORoot, |
947 | 43 | UbuntuSSOClient, | 43 | UbuntuSSOClient, |
949 | 44 | get_sso_pb_hostport) | 44 | get_sso_pb_port, |
950 | 45 | ) | ||
951 | 45 | 46 | ||
952 | 46 | # because we are using twisted we have java like names C0103 and | 47 | # because we are using twisted we have java like names C0103 and |
953 | 47 | # the issues that mocker brings with it like W0104 | 48 | # the issues that mocker brings with it like W0104 |
954 | @@ -191,10 +192,10 @@ | |||
955 | 191 | self.sso_root = UbuntuSSORoot(self.login, None, None) | 192 | self.sso_root = UbuntuSSORoot(self.login, None, None) |
956 | 192 | self.server_factory = SaveProtocolServerFactory(self.sso_root) | 193 | self.server_factory = SaveProtocolServerFactory(self.sso_root) |
957 | 193 | # pylint: disable=E1101 | 194 | # pylint: disable=E1101 |
959 | 194 | host, port = get_sso_pb_hostport() | 195 | port = get_sso_pb_port() |
960 | 195 | self.listener = reactor.listenTCP(port, self.server_factory) | 196 | self.listener = reactor.listenTCP(port, self.server_factory) |
961 | 196 | self.client_factory = PBClientFactory() | 197 | self.client_factory = PBClientFactory() |
963 | 197 | self.connector = reactor.connectTCP(host, port, | 198 | self.connector = reactor.connectTCP(LOCALHOST, port, |
964 | 198 | self.client_factory) | 199 | self.client_factory) |
965 | 199 | # pylint: enable=E1101 | 200 | # pylint: enable=E1101 |
966 | 200 | 201 | ||
967 | @@ -292,7 +293,7 @@ | |||
968 | 292 | @defer.inlineCallbacks | 293 | @defer.inlineCallbacks |
969 | 293 | def test_execution(client): | 294 | def test_execution(client): |
970 | 294 | """Actual test.""" | 295 | """Actual test.""" |
972 | 295 | self.root.generate_captcha(app_name, filename, blocking, | 296 | self.root.generate_captcha(app_name, filename, |
973 | 296 | self.login.emit_captcha_generated, | 297 | self.login.emit_captcha_generated, |
974 | 297 | self.login.emit_captcha_generation_error) | 298 | self.login.emit_captcha_generation_error) |
975 | 298 | self.mocker.replay() | 299 | self.mocker.replay() |
976 | @@ -364,7 +365,7 @@ | |||
977 | 364 | def test_execution(client): | 365 | def test_execution(client): |
978 | 365 | """Actual test.""" | 366 | """Actual test.""" |
979 | 366 | self.root.register_user(app_name, email, password, displayname, | 367 | self.root.register_user(app_name, email, password, displayname, |
981 | 367 | captcha_id, captcha_solution, blocking, | 368 | captcha_id, captcha_solution, |
982 | 368 | self.login.emit_user_registered, | 369 | self.login.emit_user_registered, |
983 | 369 | self.login.emit_user_registration_error) | 370 | self.login.emit_user_registration_error) |
984 | 370 | self.mocker.replay() | 371 | self.mocker.replay() |
985 | @@ -453,7 +454,7 @@ | |||
986 | 453 | @defer.inlineCallbacks | 454 | @defer.inlineCallbacks |
987 | 454 | def test_execution(client): | 455 | def test_execution(client): |
988 | 455 | """Actual test.""" | 456 | """Actual test.""" |
990 | 456 | self.root.login(app_name, email, password, blocking, | 457 | self.root.login(app_name, email, password, |
991 | 457 | self.login.emit_logged_in, | 458 | self.login.emit_logged_in, |
992 | 458 | self.login.emit_login_error, | 459 | self.login.emit_login_error, |
993 | 459 | self.login.emit_user_not_validated) | 460 | self.login.emit_user_not_validated) |
994 | @@ -524,7 +525,7 @@ | |||
995 | 524 | def test_execution(client): | 525 | def test_execution(client): |
996 | 525 | """Actual test.""" | 526 | """Actual test.""" |
997 | 526 | self.root.validate_email(app_name, email, password, email_token, | 527 | self.root.validate_email(app_name, email, password, email_token, |
999 | 527 | blocking, self.login.emit_email_validated, | 528 | self.login.emit_email_validated, |
1000 | 528 | self.login.emit_email_validation_error) | 529 | self.login.emit_email_validation_error) |
1001 | 529 | self.mocker.replay() | 530 | self.mocker.replay() |
1002 | 530 | yield client.validate_email(app_name, email, password, email_token) | 531 | yield client.validate_email(app_name, email, password, email_token) |
1003 | @@ -590,7 +591,7 @@ | |||
1004 | 590 | @defer.inlineCallbacks | 591 | @defer.inlineCallbacks |
1005 | 591 | def test_execution(client): | 592 | def test_execution(client): |
1006 | 592 | """Actual test.""" | 593 | """Actual test.""" |
1008 | 593 | self.root.request_password_reset_token(app_name, email, blocking, | 594 | self.root.request_password_reset_token(app_name, email, |
1009 | 594 | self.login.emit_password_reset_token_sent, | 595 | self.login.emit_password_reset_token_sent, |
1010 | 595 | self.login.emit_password_reset_error) | 596 | self.login.emit_password_reset_error) |
1011 | 596 | self.mocker.replay() | 597 | self.mocker.replay() |
1012 | @@ -660,7 +661,7 @@ | |||
1013 | 660 | def test_execution(client): | 661 | def test_execution(client): |
1014 | 661 | """Actual test.""" | 662 | """Actual test.""" |
1015 | 662 | self.root.set_new_password(app_name, email, token, new_password, | 663 | self.root.set_new_password(app_name, email, token, new_password, |
1017 | 663 | blocking, self.login.emit_password_changed, | 664 | self.login.emit_password_changed, |
1018 | 664 | self.login.emit_password_change_error) | 665 | self.login.emit_password_change_error) |
1019 | 665 | self.mocker.replay() | 666 | self.mocker.replay() |
1020 | 666 | yield client.set_new_password(app_name, email, token, new_password) | 667 | yield client.set_new_password(app_name, email, token, new_password) |
1021 | @@ -690,10 +691,10 @@ | |||
1022 | 690 | self.sso_root = UbuntuSSORoot(None, self.creds, None) | 691 | self.sso_root = UbuntuSSORoot(None, self.creds, None) |
1023 | 691 | self.server_factory = SaveProtocolServerFactory(self.sso_root) | 692 | self.server_factory = SaveProtocolServerFactory(self.sso_root) |
1024 | 692 | # pylint: disable=E1101 | 693 | # pylint: disable=E1101 |
1026 | 693 | host, port = get_sso_pb_hostport() | 694 | port = get_sso_pb_port() |
1027 | 694 | self.listener = reactor.listenTCP(port, self.server_factory) | 695 | self.listener = reactor.listenTCP(port, self.server_factory) |
1028 | 695 | self.client_factory = PBClientFactory() | 696 | self.client_factory = PBClientFactory() |
1030 | 696 | self.connector = reactor.connectTCP(host, port, | 697 | self.connector = reactor.connectTCP(LOCALHOST, port, |
1031 | 697 | self.client_factory) | 698 | self.client_factory) |
1032 | 698 | # pylint: enable=E1101 | 699 | # pylint: enable=E1101 |
1033 | 699 | 700 | ||
1034 | @@ -945,10 +946,10 @@ | |||
1035 | 945 | self.sso_root = UbuntuSSORoot(None, None, self.creds) | 946 | self.sso_root = UbuntuSSORoot(None, None, self.creds) |
1036 | 946 | self.server_factory = SaveProtocolServerFactory(self.sso_root) | 947 | self.server_factory = SaveProtocolServerFactory(self.sso_root) |
1037 | 947 | # pylint: disable=E1101 | 948 | # pylint: disable=E1101 |
1039 | 948 | host, port = get_sso_pb_hostport() | 949 | port = get_sso_pb_port() |
1040 | 949 | self.listener = reactor.listenTCP(port, self.server_factory) | 950 | self.listener = reactor.listenTCP(port, self.server_factory) |
1041 | 950 | self.client_factory = PBClientFactory() | 951 | self.client_factory = PBClientFactory() |
1043 | 951 | self.connector = reactor.connectTCP(host, port, | 952 | self.connector = reactor.connectTCP(LOCALHOST, port, |
1044 | 952 | self.client_factory) | 953 | self.client_factory) |
1045 | 953 | # pylint: enable=E1101 | 954 | # pylint: enable=E1101 |
1046 | 954 | 955 | ||
1047 | @@ -1257,6 +1258,25 @@ | |||
1048 | 1257 | # pylint: enable=E1101 | 1258 | # pylint: enable=E1101 |
1049 | 1258 | return d | 1259 | return d |
1050 | 1259 | 1260 | ||
1051 | 1261 | def test_login_email_password(self): | ||
1052 | 1262 | """Test that root is called.""" | ||
1053 | 1263 | app_name = 'app' | ||
1054 | 1264 | args = 'args' | ||
1055 | 1265 | |||
1056 | 1266 | @defer.inlineCallbacks | ||
1057 | 1267 | def test_execution(client): | ||
1058 | 1268 | """Actual test.""" | ||
1059 | 1269 | self.root.login_email_password(app_name, args) | ||
1060 | 1270 | self.mocker.replay() | ||
1061 | 1271 | yield client.login_email_password(app_name, args) | ||
1062 | 1272 | yield client.unregister_to_signals() | ||
1063 | 1273 | |||
1064 | 1274 | d = self._get_client() | ||
1065 | 1275 | # pylint: disable=E1101 | ||
1066 | 1276 | d.addCallback(test_execution) | ||
1067 | 1277 | # pylint: enable=E1101 | ||
1068 | 1278 | return d | ||
1069 | 1279 | |||
1070 | 1260 | 1280 | ||
1071 | 1261 | class MockRemoteObject(object): | 1281 | class MockRemoteObject(object): |
1072 | 1262 | """A mock RemoteObject.""" | 1282 | """A mock RemoteObject.""" |
1073 | @@ -1330,7 +1350,6 @@ | |||
1074 | 1330 | self.assertEqual(connect_result, ussoc) | 1350 | self.assertEqual(connect_result, ussoc) |
1075 | 1331 | self.assertTrue(mac.port_requested, "The port must be requested.") | 1351 | self.assertTrue(mac.port_requested, "The port must be requested.") |
1076 | 1332 | self.assertNotEqual(ussoc.sso_login, None) | 1352 | self.assertNotEqual(ussoc.sso_login, None) |
1077 | 1333 | self.assertNotEqual(ussoc.sso_cred, None) | ||
1078 | 1334 | self.assertNotEqual(ussoc.cred_management, None) | 1353 | self.assertNotEqual(ussoc.cred_management, None) |
1079 | 1335 | 1354 | ||
1080 | 1336 | def test_get_activation_cmdline(self): | 1355 | def test_get_activation_cmdline(self): |
1081 | @@ -1340,3 +1359,69 @@ | |||
1082 | 1340 | self.patch(windows, "QueryValueEx", lambda key, v: (key, REG_SZ)) | 1359 | self.patch(windows, "QueryValueEx", lambda key, v: (key, REG_SZ)) |
1083 | 1341 | cmdline = windows.get_activation_cmdline(windows.SSO_SERVICE_NAME) | 1360 | cmdline = windows.get_activation_cmdline(windows.SSO_SERVICE_NAME) |
1084 | 1342 | self.assertEqual(SAMPLE_VALUE, cmdline) | 1361 | self.assertEqual(SAMPLE_VALUE, cmdline) |
1085 | 1362 | |||
1086 | 1363 | |||
1087 | 1364 | class MockWin32APIs(object): | ||
1088 | 1365 | """Some mock win32apis.""" | ||
1089 | 1366 | |||
1090 | 1367 | process_handle = object() | ||
1091 | 1368 | TOKEN_ALL_ACCESS = object() | ||
1092 | 1369 | TokenUser = object() | ||
1093 | 1370 | |||
1094 | 1371 | def __init__(self, sample_token): | ||
1095 | 1372 | """Initialize this mock instance.""" | ||
1096 | 1373 | self.sample_token = sample_token | ||
1097 | 1374 | self.token_handle = object() | ||
1098 | 1375 | |||
1099 | 1376 | def GetCurrentProcess(self): | ||
1100 | 1377 | """Returns a fake process_handle.""" | ||
1101 | 1378 | return self.process_handle | ||
1102 | 1379 | |||
1103 | 1380 | def OpenProcessToken(self, process_handle, access): | ||
1104 | 1381 | """Open the process token.""" | ||
1105 | 1382 | assert process_handle is self.process_handle | ||
1106 | 1383 | assert access is self.TOKEN_ALL_ACCESS | ||
1107 | 1384 | return self.token_handle | ||
1108 | 1385 | |||
1109 | 1386 | def GetTokenInformation(self, token_handle, info): | ||
1110 | 1387 | """Get the information for this token.""" | ||
1111 | 1388 | assert token_handle == self.token_handle | ||
1112 | 1389 | assert info == self.TokenUser | ||
1113 | 1390 | return (self.sample_token, 0) | ||
1114 | 1391 | |||
1115 | 1392 | |||
1116 | 1393 | class AssortedTestCase(TestCase): | ||
1117 | 1394 | """Tests for functions in the windows module.""" | ||
1118 | 1395 | |||
1119 | 1396 | def test_get_userid(self): | ||
1120 | 1397 | """The returned user id is parsed ok.""" | ||
1121 | 1398 | expected_id = 1001 | ||
1122 | 1399 | sample_token = "abc-123-1001" | ||
1123 | 1400 | |||
1124 | 1401 | win32apis = MockWin32APIs(sample_token) | ||
1125 | 1402 | self.patch(windows, "win32process", win32apis) | ||
1126 | 1403 | self.patch(windows, "win32security", win32apis) | ||
1127 | 1404 | |||
1128 | 1405 | userid = windows.get_user_id() | ||
1129 | 1406 | self.assertEqual(userid, expected_id) | ||
1130 | 1407 | |||
1131 | 1408 | def _test_port_assignation(self, uid, expected_port): | ||
1132 | 1409 | """Test a given uid/expected port combo.""" | ||
1133 | 1410 | self.patch(windows, "get_user_id", lambda: uid) | ||
1134 | 1411 | self.assertEqual(windows.get_sso_pb_port(), expected_port) | ||
1135 | 1412 | |||
1136 | 1413 | def test_get_sso_pb_port(self): | ||
1137 | 1414 | """Test the get_sso_pb_port function.""" | ||
1138 | 1415 | uid = 1001 | ||
1139 | 1416 | uid_modulo = uid % windows.SSO_RESERVED_PORTS | ||
1140 | 1417 | expected_port = (windows.SSO_BASE_PB_PORT + | ||
1141 | 1418 | uid_modulo * windows.SSO_PORT_ALLOCATION_STEP) | ||
1142 | 1419 | self._test_port_assignation(uid, expected_port) | ||
1143 | 1420 | |||
1144 | 1421 | def test_get_sso_pb_port_alt(self): | ||
1145 | 1422 | """Test the get_sso_pb_port function.""" | ||
1146 | 1423 | uid = 2011 + windows.SSO_RESERVED_PORTS | ||
1147 | 1424 | uid_modulo = uid % windows.SSO_RESERVED_PORTS | ||
1148 | 1425 | expected_port = (windows.SSO_BASE_PB_PORT + | ||
1149 | 1426 | uid_modulo * windows.SSO_PORT_ALLOCATION_STEP) | ||
1150 | 1427 | self._test_port_assignation(uid, expected_port) | ||
1151 | 1343 | 1428 | ||
1152 | === modified file 'ubuntu_sso/main/windows.py' | |||
1153 | --- ubuntu_sso/main/windows.py 2011-07-22 20:12:20 +0000 | |||
1154 | +++ ubuntu_sso/main/windows.py 2011-08-25 19:16:19 +0000 | |||
1155 | @@ -17,11 +17,16 @@ | |||
1156 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
1157 | 18 | """Main implementation on windows.""" | 18 | """Main implementation on windows.""" |
1158 | 19 | 19 | ||
1159 | 20 | import warnings | ||
1160 | 21 | |||
1161 | 20 | # pylint: disable=F0401 | 22 | # pylint: disable=F0401 |
1162 | 21 | from _winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx | 23 | from _winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx |
1163 | 22 | 24 | ||
1164 | 23 | from functools import wraps | 25 | from functools import wraps |
1165 | 24 | 26 | ||
1166 | 27 | import win32process | ||
1167 | 28 | import win32security | ||
1168 | 29 | |||
1169 | 25 | from twisted.internet import defer, reactor | 30 | from twisted.internet import defer, reactor |
1170 | 26 | from twisted.internet.threads import deferToThread | 31 | from twisted.internet.threads import deferToThread |
1171 | 27 | from twisted.spread.pb import ( | 32 | from twisted.spread.pb import ( |
1172 | @@ -44,19 +49,54 @@ | |||
1173 | 44 | U1_REG_PATH = r'Software\Ubuntu One' | 49 | U1_REG_PATH = r'Software\Ubuntu One' |
1174 | 45 | SSO_INSTALL_PATH = 'SSOInstallPath' | 50 | SSO_INSTALL_PATH = 'SSOInstallPath' |
1175 | 46 | LOCALHOST = "127.0.0.1" | 51 | LOCALHOST = "127.0.0.1" |
1177 | 47 | SSO_DEFAULT_PB_PORT = 50001 | 52 | SSO_BASE_PB_PORT = 50000 |
1178 | 53 | SSO_RESERVED_PORTS = 3000 | ||
1179 | 54 | SSO_PORT_ALLOCATION_STEP = 3 # contiguous ports for sso, u1client, and u1cp | ||
1180 | 48 | SSO_SERVICE_NAME = "ubuntu-sso-client" | 55 | SSO_SERVICE_NAME = "ubuntu-sso-client" |
1181 | 49 | 56 | ||
1182 | 50 | 57 | ||
1186 | 51 | def get_sso_pb_hostport(): | 58 | def get_user_id(): |
1187 | 52 | """Get the host and port on which the SSO pb is running.""" | 59 | """Find the numeric user id.""" |
1188 | 53 | return LOCALHOST, SSO_DEFAULT_PB_PORT | 60 | process_handle = win32process.GetCurrentProcess() |
1189 | 61 | token_handle = win32security.OpenProcessToken(process_handle, | ||
1190 | 62 | win32security.TOKEN_ALL_ACCESS) | ||
1191 | 63 | user_sid = win32security.GetTokenInformation(token_handle, | ||
1192 | 64 | win32security.TokenUser)[0] | ||
1193 | 65 | sid_parts = str(user_sid).split("-") | ||
1194 | 66 | uid = int(sid_parts[-1]) | ||
1195 | 67 | return uid | ||
1196 | 68 | |||
1197 | 69 | |||
1198 | 70 | def get_sso_pb_port(): | ||
1199 | 71 | """Get the port on which the SSO pb is running.""" | ||
1200 | 72 | uid = get_user_id() | ||
1201 | 73 | uid_modulo = uid % SSO_RESERVED_PORTS | ||
1202 | 74 | port = SSO_BASE_PB_PORT + uid_modulo * SSO_PORT_ALLOCATION_STEP | ||
1203 | 75 | return port | ||
1204 | 54 | 76 | ||
1205 | 55 | 77 | ||
1206 | 56 | def remote_handler(handler): | 78 | def remote_handler(handler): |
1208 | 57 | """Execute a callback in a remote object.""" | 79 | """Execute a callback in a remote object. |
1209 | 80 | |||
1210 | 81 | If the callback takes arguments, it's assumed that the last | ||
1211 | 82 | one is a twisted Failure, and it has no keyword arguments. | ||
1212 | 83 | """ | ||
1213 | 58 | if handler: | 84 | if handler: |
1215 | 59 | return lambda: handler.callRemote('execute') | 85 | |
1216 | 86 | def f(*args): | ||
1217 | 87 | """Process arguments and call remote.""" | ||
1218 | 88 | try: | ||
1219 | 89 | args = list(args) | ||
1220 | 90 | if args: | ||
1221 | 91 | args[-1] = except_to_errdict(args[-1].value) | ||
1222 | 92 | return handler.callRemote('execute', *args) | ||
1223 | 93 | # Yes, I want to catch everything | ||
1224 | 94 | # pylint: disable=W0703 | ||
1225 | 95 | except Exception: | ||
1226 | 96 | logger.exception("Remote handler argument processing error:") | ||
1227 | 97 | return f | ||
1228 | 98 | |||
1229 | 99 | logger.warning("Remote handler got an empty handler.") | ||
1230 | 60 | return lambda: None | 100 | return lambda: None |
1231 | 61 | 101 | ||
1232 | 62 | 102 | ||
1233 | @@ -70,7 +110,7 @@ | |||
1234 | 70 | 110 | ||
1235 | 71 | def get_activation_config(): | 111 | def get_activation_config(): |
1236 | 72 | """Get the configuration to activate the sso service.""" | 112 | """Get the configuration to activate the sso service.""" |
1238 | 73 | _, port = get_sso_pb_hostport() | 113 | port = get_sso_pb_port() |
1239 | 74 | service_name = SSO_SERVICE_NAME | 114 | service_name = SSO_SERVICE_NAME |
1240 | 75 | cmdline = get_activation_cmdline(service_name) | 115 | cmdline = get_activation_cmdline(service_name) |
1241 | 76 | return ActivationConfig(service_name, cmdline, port) | 116 | return ActivationConfig(service_name, cmdline, port) |
1242 | @@ -82,7 +122,8 @@ | |||
1243 | 82 | # the calls in twisted will be called with the args in a diff order, | 122 | # the calls in twisted will be called with the args in a diff order, |
1244 | 83 | # in order to follow the linux api, we swap them around with a lambda | 123 | # in order to follow the linux api, we swap them around with a lambda |
1245 | 84 | d.addCallback(lambda result, app: result_cb(app, result), app_name) | 124 | d.addCallback(lambda result, app: result_cb(app, result), app_name) |
1247 | 85 | d.addErrback(lambda err, app: error_cb(app, err), app_name) | 125 | d.addErrback(lambda err, app: |
1248 | 126 | error_cb(app, except_to_errdict(err.value)), app_name) | ||
1249 | 86 | 127 | ||
1250 | 87 | 128 | ||
1251 | 88 | class RemoteMeta(type): | 129 | class RemoteMeta(type): |
1252 | @@ -177,7 +218,7 @@ | |||
1253 | 177 | 218 | ||
1254 | 178 | def generate_captcha(self, app_name, filename): | 219 | def generate_captcha(self, app_name, filename): |
1255 | 179 | """Call the matching method in the processor.""" | 220 | """Call the matching method in the processor.""" |
1257 | 180 | self.root.generate_captcha(app_name, filename, blocking, | 221 | self.root.generate_captcha(app_name, filename, |
1258 | 181 | self.emit_captcha_generated, | 222 | self.emit_captcha_generated, |
1259 | 182 | self.emit_captcha_generation_error) | 223 | self.emit_captcha_generation_error) |
1260 | 183 | 224 | ||
1261 | @@ -199,7 +240,7 @@ | |||
1262 | 199 | captcha_id, captcha_solution): | 240 | captcha_id, captcha_solution): |
1263 | 200 | """Call the matching method in the processor.""" | 241 | """Call the matching method in the processor.""" |
1264 | 201 | self.root.register_user(app_name, email, password, displayname, | 242 | self.root.register_user(app_name, email, password, displayname, |
1266 | 202 | captcha_id, captcha_solution, blocking, | 243 | captcha_id, captcha_solution, |
1267 | 203 | self.emit_user_registered, | 244 | self.emit_user_registered, |
1268 | 204 | self.emit_user_registration_error) | 245 | self.emit_user_registration_error) |
1269 | 205 | 246 | ||
1270 | @@ -225,7 +266,7 @@ | |||
1271 | 225 | 266 | ||
1272 | 226 | def login(self, app_name, email, password): | 267 | def login(self, app_name, email, password): |
1273 | 227 | """Call the matching method in the processor.""" | 268 | """Call the matching method in the processor.""" |
1275 | 228 | self.root.login(app_name, email, password, blocking, | 269 | self.root.login(app_name, email, password, |
1276 | 229 | self.emit_logged_in, self.emit_login_error, | 270 | self.emit_logged_in, self.emit_login_error, |
1277 | 230 | self.emit_user_not_validated) | 271 | self.emit_user_not_validated) |
1278 | 231 | 272 | ||
1279 | @@ -246,7 +287,7 @@ | |||
1280 | 246 | def validate_email(self, app_name, email, password, email_token): | 287 | def validate_email(self, app_name, email, password, email_token): |
1281 | 247 | """Call the matching method in the processor.""" | 288 | """Call the matching method in the processor.""" |
1282 | 248 | self.root.validate_email(app_name, email, password, email_token, | 289 | self.root.validate_email(app_name, email, password, email_token, |
1284 | 249 | blocking, self.emit_email_validated, | 290 | self.emit_email_validated, |
1285 | 250 | self.emit_email_validation_error) | 291 | self.emit_email_validation_error) |
1286 | 251 | 292 | ||
1287 | 252 | # request_password_reset_token signals | 293 | # request_password_reset_token signals |
1288 | @@ -265,7 +306,7 @@ | |||
1289 | 265 | 306 | ||
1290 | 266 | def request_password_reset_token(self, app_name, email): | 307 | def request_password_reset_token(self, app_name, email): |
1291 | 267 | """Call the matching method in the processor.""" | 308 | """Call the matching method in the processor.""" |
1293 | 268 | self.root.request_password_reset_token(app_name, email, blocking, | 309 | self.root.request_password_reset_token(app_name, email, |
1294 | 269 | self.emit_password_reset_token_sent, | 310 | self.emit_password_reset_token_sent, |
1295 | 270 | self.emit_password_reset_error) | 311 | self.emit_password_reset_error) |
1296 | 271 | 312 | ||
1297 | @@ -286,7 +327,7 @@ | |||
1298 | 286 | def set_new_password(self, app_name, email, token, new_password): | 327 | def set_new_password(self, app_name, email, token, new_password): |
1299 | 287 | """Call the matching method in the processor.""" | 328 | """Call the matching method in the processor.""" |
1300 | 288 | self.root.set_new_password(app_name, email, token, new_password, | 329 | self.root.set_new_password(app_name, email, token, new_password, |
1302 | 289 | blocking, self.emit_password_changed, | 330 | self.emit_password_changed, |
1303 | 290 | self.emit_password_change_error) | 331 | self.emit_password_change_error) |
1304 | 291 | 332 | ||
1305 | 292 | 333 | ||
1306 | @@ -420,6 +461,7 @@ | |||
1307 | 420 | 'register', | 461 | 'register', |
1308 | 421 | 'shutdown', | 462 | 'shutdown', |
1309 | 422 | 'login', | 463 | 'login', |
1310 | 464 | 'login_email_password', | ||
1311 | 423 | ] | 465 | ] |
1312 | 424 | 466 | ||
1313 | 425 | def __init__(self, timeout_func, shutdown_func, *args, **kwargs): | 467 | def __init__(self, timeout_func, shutdown_func, *args, **kwargs): |
1314 | @@ -537,6 +579,10 @@ | |||
1315 | 537 | """Get credentials if found else prompt GUI to login.""" | 579 | """Get credentials if found else prompt GUI to login.""" |
1316 | 538 | self.root.login(app_name, args) | 580 | self.root.login(app_name, args) |
1317 | 539 | 581 | ||
1318 | 582 | def login_email_password(self, app_name, args): | ||
1319 | 583 | """Get credentials if found, else login.""" | ||
1320 | 584 | self.root.login_email_password(app_name, args) | ||
1321 | 585 | |||
1322 | 540 | 586 | ||
1323 | 541 | class UbuntuSSORoot(object, Root): | 587 | class UbuntuSSORoot(object, Root): |
1324 | 542 | """Root object that exposes the diff referenceable objects.""" | 588 | """Root object that exposes the diff referenceable objects.""" |
1325 | @@ -571,27 +617,31 @@ | |||
1326 | 571 | 617 | ||
1327 | 572 | def remote(function): | 618 | def remote(function): |
1328 | 573 | """Decorate the function to make the remote call.""" | 619 | """Decorate the function to make the remote call.""" |
1329 | 620 | |||
1330 | 574 | @wraps(function) | 621 | @wraps(function) |
1332 | 575 | def remote_wrapper(*args, **kwargs): | 622 | def remote_wrapper(instance, *args, **kwargs): |
1333 | 576 | """Return the deferred for the remote call.""" | 623 | """Return the deferred for the remote call.""" |
1338 | 577 | fixed_args = args[1:] | 624 | fname = function.__name__ |
1339 | 578 | logger.info('Performing %s as a remote call.', function.func_name) | 625 | logger.info('Performing %s as a remote call.', fname) |
1340 | 579 | return args[0].remote.callRemote(function.func_name, *fixed_args, | 626 | result = instance.remote.callRemote(fname, *args, **kwargs) |
1341 | 580 | **kwargs) | 627 | return result |
1342 | 628 | |||
1343 | 581 | return remote_wrapper | 629 | return remote_wrapper |
1344 | 582 | 630 | ||
1345 | 583 | 631 | ||
1346 | 584 | def signal(function): | 632 | def signal(function): |
1347 | 585 | """Decorate a function to perform the signal callback.""" | 633 | """Decorate a function to perform the signal callback.""" |
1348 | 634 | |||
1349 | 586 | @wraps(function) | 635 | @wraps(function) |
1351 | 587 | def callback_wrapper(*args, **kwargs): | 636 | def callback_wrapper(instance, *args, **kwargs): |
1352 | 588 | """Return the result of the callback if present.""" | 637 | """Return the result of the callback if present.""" |
1354 | 589 | callback = getattr(args[0], function.func_name + '_cb', None) | 638 | fname = function.__name__ |
1355 | 639 | callback = getattr(instance, fname + '_cb', None) | ||
1356 | 590 | if callback is not None: | 640 | if callback is not None: |
1361 | 591 | fixed_args = args[1:] | 641 | logger.info('Emitting remote signal for %s with callback %r.', |
1362 | 592 | if not kwargs: | 642 | fname, callback) |
1363 | 593 | return callback(*fixed_args) | 643 | return callback(*args, **kwargs) |
1364 | 594 | return callback(*fixed_args, **kwargs) | 644 | |
1365 | 595 | return callback_wrapper | 645 | return callback_wrapper |
1366 | 596 | 646 | ||
1367 | 597 | 647 | ||
1368 | @@ -618,10 +668,10 @@ | |||
1369 | 618 | """Create a new instance.""" | 668 | """Create a new instance.""" |
1370 | 619 | self.cb = cb | 669 | self.cb = cb |
1371 | 620 | 670 | ||
1373 | 621 | def remote_execute(self): | 671 | def remote_execute(self, *args, **kwargs): |
1374 | 622 | """Execute the callback.""" | 672 | """Execute the callback.""" |
1375 | 623 | if self.cb: | 673 | if self.cb: |
1377 | 624 | self.cb() | 674 | self.cb(*args, **kwargs) |
1378 | 625 | 675 | ||
1379 | 626 | 676 | ||
1380 | 627 | def callbacks(callbacks_indexes=None, callbacks_names=None): | 677 | def callbacks(callbacks_indexes=None, callbacks_names=None): |
1381 | @@ -755,7 +805,10 @@ | |||
1382 | 755 | 805 | ||
1383 | 756 | 806 | ||
1384 | 757 | class SSOCredentialsClient(RemoteClient, Referenceable): | 807 | class SSOCredentialsClient(RemoteClient, Referenceable): |
1386 | 758 | """Client that can perform calls to the remote SSOCredentials object.""" | 808 | """Deprecated client for the remote SSOCredentials object. |
1387 | 809 | |||
1388 | 810 | This class is deprecated! | ||
1389 | 811 | """ | ||
1390 | 759 | 812 | ||
1391 | 760 | __metaclass__ = RemoteMeta | 813 | __metaclass__ = RemoteMeta |
1392 | 761 | 814 | ||
1393 | @@ -768,6 +821,8 @@ | |||
1394 | 768 | 821 | ||
1395 | 769 | def __init__(self, remote_login): | 822 | def __init__(self, remote_login): |
1396 | 770 | """Create a client for the cred API.""" | 823 | """Create a client for the cred API.""" |
1397 | 824 | warnings.warn("SSOCredentialsClient is deprecated.", | ||
1398 | 825 | DeprecationWarning) | ||
1399 | 771 | super(SSOCredentialsClient, self).__init__(remote_login) | 826 | super(SSOCredentialsClient, self).__init__(remote_login) |
1400 | 772 | 827 | ||
1401 | 773 | @signal | 828 | @signal |
1402 | @@ -913,6 +968,10 @@ | |||
1403 | 913 | def login(self, app_name, args): | 968 | def login(self, app_name, args): |
1404 | 914 | """Get credentials if found else prompt GUI to login.""" | 969 | """Get credentials if found else prompt GUI to login.""" |
1405 | 915 | 970 | ||
1406 | 971 | @remote | ||
1407 | 972 | def login_email_password(self, app_name, args): | ||
1408 | 973 | """Get credentials if found else login.""" | ||
1409 | 974 | |||
1410 | 916 | 975 | ||
1411 | 917 | class UbuntuSSOClientException(Exception): | 976 | class UbuntuSSOClientException(Exception): |
1412 | 918 | """Raised when there are issues connecting to the process.""" | 977 | """Raised when there are issues connecting to the process.""" |
1413 | @@ -923,7 +982,6 @@ | |||
1414 | 923 | 982 | ||
1415 | 924 | def __init__(self): | 983 | def __init__(self): |
1416 | 925 | self.sso_login = None | 984 | self.sso_login = None |
1417 | 926 | self.sso_cred = None | ||
1418 | 927 | self.cred_management = None | 985 | self.cred_management = None |
1419 | 928 | self.factory = None | 986 | self.factory = None |
1420 | 929 | self.client = None | 987 | self.client = None |
1421 | @@ -934,8 +992,6 @@ | |||
1422 | 934 | sso_login = yield root.callRemote('get_sso_login') | 992 | sso_login = yield root.callRemote('get_sso_login') |
1423 | 935 | logger.debug('SSOLogin is %s', sso_login) | 993 | logger.debug('SSOLogin is %s', sso_login) |
1424 | 936 | self.sso_login = SSOLoginClient(sso_login) | 994 | self.sso_login = SSOLoginClient(sso_login) |
1425 | 937 | sso_cred = yield root.callRemote('get_sso_credentials') | ||
1426 | 938 | self.sso_cred = SSOCredentialsClient(sso_cred) | ||
1427 | 939 | cred_management = yield root.callRemote('get_cred_manager') | 995 | cred_management = yield root.callRemote('get_cred_manager') |
1428 | 940 | self.cred_management = CredentialsManagementClient(cred_management) | 996 | self.cred_management = CredentialsManagementClient(cred_management) |
1429 | 941 | defer.returnValue(self) | 997 | defer.returnValue(self) |
1430 | 942 | 998 | ||
1431 | === modified file 'ubuntu_sso/networkstate/windows.py' | |||
1432 | --- ubuntu_sso/networkstate/windows.py 2011-03-22 23:29:20 +0000 | |||
1433 | +++ ubuntu_sso/networkstate/windows.py 2011-08-25 19:16:19 +0000 | |||
1434 | @@ -102,9 +102,9 @@ | |||
1435 | 102 | 102 | ||
1436 | 103 | def __init__(self, connected_cb=None, connected_cb_info=None, | 103 | def __init__(self, connected_cb=None, connected_cb_info=None, |
1437 | 104 | disconnected_cb=None): | 104 | disconnected_cb=None): |
1439 | 105 | # pylint: disable=E1101 | 105 | # pylint: disable=E1101,E1120,W0231 |
1440 | 106 | self._wrap_(self) | 106 | self._wrap_(self) |
1442 | 107 | # pylint: enable=E1101 | 107 | # pylint: enable=E1101,E1120 |
1443 | 108 | self.connected_cb = connected_cb | 108 | self.connected_cb = connected_cb |
1444 | 109 | self.connected_cb_info = connected_cb_info | 109 | self.connected_cb_info = connected_cb_info |
1445 | 110 | self.disconnected_cb = disconnected_cb | 110 | self.disconnected_cb = disconnected_cb |
1446 | @@ -131,6 +131,7 @@ | |||
1447 | 131 | """Register to listen to network events.""" | 131 | """Register to listen to network events.""" |
1448 | 132 | # call the CoInitialize to allow the registration to run in another | 132 | # call the CoInitialize to allow the registration to run in another |
1449 | 133 | # thread | 133 | # thread |
1450 | 134 | # pylint: disable=E1101 | ||
1451 | 134 | pythoncom.CoInitialize() | 135 | pythoncom.CoInitialize() |
1452 | 135 | # interface to be used by com | 136 | # interface to be used by com |
1453 | 136 | manager_interface = pythoncom.WrapObject(self) | 137 | manager_interface = pythoncom.WrapObject(self) |
1454 | @@ -157,6 +158,7 @@ | |||
1455 | 157 | 'Error registering %s to event %s', e, current_event[1]) | 158 | 'Error registering %s to event %s', e, current_event[1]) |
1456 | 158 | 159 | ||
1457 | 159 | pythoncom.PumpMessages() | 160 | pythoncom.PumpMessages() |
1458 | 161 | # pylint: enable=E1101 | ||
1459 | 160 | 162 | ||
1460 | 161 | 163 | ||
1461 | 162 | def is_machine_connected(): | 164 | def is_machine_connected(): |
1462 | 163 | 165 | ||
1463 | === modified file 'ubuntu_sso/qt/controllers.py' | |||
1464 | --- ubuntu_sso/qt/controllers.py 2011-07-22 20:12:20 +0000 | |||
1465 | +++ ubuntu_sso/qt/controllers.py 2011-08-25 19:16:19 +0000 | |||
1466 | @@ -20,10 +20,12 @@ | |||
1467 | 20 | import StringIO | 20 | import StringIO |
1468 | 21 | import tempfile | 21 | import tempfile |
1469 | 22 | 22 | ||
1470 | 23 | # pylint: disable=F0401 | ||
1471 | 23 | try: | 24 | try: |
1472 | 24 | from PIL import Image | 25 | from PIL import Image |
1473 | 25 | except ImportError: | 26 | except ImportError: |
1474 | 26 | import Image | 27 | import Image |
1475 | 28 | # pylint: enable=F0401 | ||
1476 | 27 | 29 | ||
1477 | 28 | from PyQt4.QtGui import QMessageBox, QWizard, QPixmap | 30 | from PyQt4.QtGui import QMessageBox, QWizard, QPixmap |
1478 | 29 | from PyQt4.QtCore import QUrl | 31 | from PyQt4.QtCore import QUrl |
1479 | @@ -34,6 +36,7 @@ | |||
1480 | 34 | from ubuntu_sso.utils.ui import ( | 36 | from ubuntu_sso.utils.ui import ( |
1481 | 35 | CAPTCHA_LOAD_ERROR, | 37 | CAPTCHA_LOAD_ERROR, |
1482 | 36 | CAPTCHA_SOLUTION_ENTRY, | 38 | CAPTCHA_SOLUTION_ENTRY, |
1483 | 39 | CAPTCHA_REQUIRED_ERROR, | ||
1484 | 37 | EMAIL1_ENTRY, | 40 | EMAIL1_ENTRY, |
1485 | 38 | EMAIL2_ENTRY, | 41 | EMAIL2_ENTRY, |
1486 | 39 | EMAIL_LABEL, | 42 | EMAIL_LABEL, |
1487 | @@ -76,14 +79,38 @@ | |||
1488 | 76 | # disabled warnings about TODO comments | 79 | # disabled warnings about TODO comments |
1489 | 77 | 80 | ||
1490 | 78 | 81 | ||
1491 | 82 | # Based on the gtk implementation, but added error_message | ||
1492 | 83 | # support, and rewritten. | ||
1493 | 84 | def _build_general_error_message(errordict): | ||
1494 | 85 | """Concatenate __all__ and message from the errordict.""" | ||
1495 | 86 | result = None | ||
1496 | 87 | msg1 = errordict.get('__all__') | ||
1497 | 88 | msg2 = errordict.get('message') | ||
1498 | 89 | if msg2 is None: | ||
1499 | 90 | # See the errordict in LP: 828417 | ||
1500 | 91 | msg2 = errordict.get('error_message') | ||
1501 | 92 | if msg1 is not None and msg2 is not None: | ||
1502 | 93 | result = '\n'.join((msg1, msg2)) | ||
1503 | 94 | elif msg1 is not None: | ||
1504 | 95 | result = msg1 | ||
1505 | 96 | elif msg2 is not None: | ||
1506 | 97 | result = msg2 | ||
1507 | 98 | else: | ||
1508 | 99 | # I give up. | ||
1509 | 100 | result = "Error: %r" % errordict | ||
1510 | 101 | return result | ||
1511 | 102 | |||
1512 | 103 | |||
1513 | 79 | class BackendController(object): | 104 | class BackendController(object): |
1514 | 80 | """Represent a controller that talks with the sso self.backend.""" | 105 | """Represent a controller that talks with the sso self.backend.""" |
1515 | 81 | 106 | ||
1517 | 82 | def __init__(self): | 107 | def __init__(self, title='', subtitle=''): |
1518 | 83 | """Create a new instance.""" | 108 | """Create a new instance.""" |
1519 | 84 | self.root = None | 109 | self.root = None |
1520 | 85 | self.view = None | 110 | self.view = None |
1521 | 86 | self.backend = None | 111 | self.backend = None |
1522 | 112 | self._title = title | ||
1523 | 113 | self._subtitle = subtitle | ||
1524 | 87 | 114 | ||
1525 | 88 | def __del__(self): | 115 | def __del__(self): |
1526 | 89 | """Clean the resources.""" | 116 | """Clean the resources.""" |
1527 | @@ -105,22 +132,30 @@ | |||
1528 | 105 | yield self.backend.register_to_signals() | 132 | yield self.backend.register_to_signals() |
1529 | 106 | returnValue(self.backend) | 133 | returnValue(self.backend) |
1530 | 107 | 134 | ||
1533 | 108 | 135 | #pylint: disable=C0103 | |
1534 | 109 | class ChooseSignInController(object): | 136 | def pageInitialized(self): |
1535 | 137 | """Call to prepare the page just before it is shown.""" | ||
1536 | 138 | pass | ||
1537 | 139 | #pylint: enable=C0103 | ||
1538 | 140 | |||
1539 | 141 | |||
1540 | 142 | class ChooseSignInController(BackendController): | ||
1541 | 110 | """Controlled to the ChooseSignIn view/widget.""" | 143 | """Controlled to the ChooseSignIn view/widget.""" |
1542 | 111 | 144 | ||
1544 | 112 | def __init__(self, title=''): | 145 | def __init__(self, title='', subtitle=''): |
1545 | 113 | """Create a new instance to manage the view.""" | 146 | """Create a new instance to manage the view.""" |
1546 | 147 | super(ChooseSignInController, self).__init__(title, subtitle) | ||
1547 | 114 | self.view = None | 148 | self.view = None |
1548 | 115 | self._title = title | ||
1549 | 116 | 149 | ||
1550 | 117 | # use an ugly name just so have a simlar api as found in PyQt | 150 | # use an ugly name just so have a simlar api as found in PyQt |
1551 | 118 | #pylint: disable=C0103 | 151 | #pylint: disable=C0103 |
1552 | 152 | |||
1553 | 119 | def setupUi(self, view): | 153 | def setupUi(self, view): |
1554 | 120 | """Perform the required actions to set up the ui.""" | 154 | """Perform the required actions to set up the ui.""" |
1555 | 121 | self.view = view | 155 | self.view = view |
1556 | 122 | self.view.setTitle(self._title) | ||
1557 | 123 | self._set_up_translated_strings() | 156 | self._set_up_translated_strings() |
1558 | 157 | self.view.header.set_title(self._title) | ||
1559 | 158 | self.view.header.set_subtitle(self._subtitle) | ||
1560 | 124 | self._connect_buttons() | 159 | self._connect_buttons() |
1561 | 125 | #pylint: enable=C0103 | 160 | #pylint: enable=C0103 |
1562 | 126 | 161 | ||
1563 | @@ -157,12 +192,10 @@ | |||
1564 | 157 | 192 | ||
1565 | 158 | def __init__(self, backend=None, title='', subtitle='', message_box=None): | 193 | def __init__(self, backend=None, title='', subtitle='', message_box=None): |
1566 | 159 | """Create a new instance.""" | 194 | """Create a new instance.""" |
1568 | 160 | super(CurrentUserController, self).__init__() | 195 | super(CurrentUserController, self).__init__(title, subtitle) |
1569 | 161 | if message_box is None: | 196 | if message_box is None: |
1570 | 162 | message_box = QMessageBox | 197 | message_box = QMessageBox |
1571 | 163 | self.message_box = message_box | 198 | self.message_box = message_box |
1572 | 164 | self._title = title | ||
1573 | 165 | self._subtitle = subtitle | ||
1574 | 166 | 199 | ||
1575 | 167 | def _set_translated_strings(self): | 200 | def _set_translated_strings(self): |
1576 | 168 | """Set the translated strings.""" | 201 | """Set the translated strings.""" |
1577 | @@ -185,13 +218,24 @@ | |||
1578 | 185 | self.backend.on_logged_in_cb = self.on_logged_in | 218 | self.backend.on_logged_in_cb = self.on_logged_in |
1579 | 186 | self.view.ui.forgot_password_label.linkActivated.connect( | 219 | self.view.ui.forgot_password_label.linkActivated.connect( |
1580 | 187 | self.on_forgotten_password) | 220 | self.on_forgotten_password) |
1581 | 221 | self.view.ui.email_edit.textChanged.connect(self._validate) | ||
1582 | 222 | self.view.ui.password_edit.textChanged.connect(self._validate) | ||
1583 | 223 | |||
1584 | 224 | def _validate(self): | ||
1585 | 225 | """Perform input validation.""" | ||
1586 | 226 | valid = True | ||
1587 | 227 | if not is_correct_email(unicode(self.view.ui.email_edit.text())): | ||
1588 | 228 | valid = False | ||
1589 | 229 | elif not unicode(self.view.ui.password_edit.text()): | ||
1590 | 230 | valid = False | ||
1591 | 231 | self.view.ui.sign_in_button.setEnabled(valid) | ||
1592 | 188 | 232 | ||
1593 | 189 | def login(self): | 233 | def login(self): |
1594 | 190 | """Perform the login using the self.backend.""" | 234 | """Perform the login using the self.backend.""" |
1595 | 191 | logger.debug('CurrentUserController.login') | 235 | logger.debug('CurrentUserController.login') |
1596 | 192 | # grab the data from the view and call the backend | 236 | # grab the data from the view and call the backend |
1599 | 193 | email = str(self.view.ui.email_edit.text()) | 237 | email = unicode(self.view.ui.email_edit.text()) |
1600 | 194 | password = str(self.view.ui.password_edit.text()) | 238 | password = unicode(self.view.ui.password_edit.text()) |
1601 | 195 | d = self.backend.login(self.view.wizard().app_name, email, password) | 239 | d = self.backend.login(self.view.wizard().app_name, email, password) |
1602 | 196 | d.addErrback(self.on_login_error) | 240 | d.addErrback(self.on_login_error) |
1603 | 197 | 241 | ||
1604 | @@ -200,13 +244,12 @@ | |||
1605 | 200 | # let the user know | 244 | # let the user know |
1606 | 201 | logger.error('Got error when login %s, error: %s', | 245 | logger.error('Got error when login %s, error: %s', |
1607 | 202 | self.view.wizard().app_name, error) | 246 | self.view.wizard().app_name, error) |
1610 | 203 | self.message_box.critical(self.view, self.view.wizard().app_name, | 247 | self.message_box.critical(_build_general_error_message(error)) |
1609 | 204 | error['message']) | ||
1611 | 205 | 248 | ||
1612 | 206 | def on_logged_in(self, app_name, result): | 249 | def on_logged_in(self, app_name, result): |
1613 | 207 | """We managed to log in.""" | 250 | """We managed to log in.""" |
1614 | 208 | logger.info('Logged in for %s', app_name) | 251 | logger.info('Logged in for %s', app_name) |
1616 | 209 | email = str(self.view.ui.email_edit.text()) | 252 | email = unicode(self.view.ui.email_edit.text()) |
1617 | 210 | self.view.wizard().loginSuccess.emit(app_name, email) | 253 | self.view.wizard().loginSuccess.emit(app_name, email) |
1618 | 211 | logger.debug('Wizard.loginSuccess emitted.') | 254 | logger.debug('Wizard.loginSuccess emitted.') |
1619 | 212 | 255 | ||
1620 | @@ -223,9 +266,8 @@ | |||
1621 | 223 | """Setup the view.""" | 266 | """Setup the view.""" |
1622 | 224 | self.view = view | 267 | self.view = view |
1623 | 225 | self.backend = yield self.get_backend() | 268 | self.backend = yield self.get_backend() |
1627 | 226 | self.view.setTitle(self._title) | 269 | self.view.header.set_title(self._title) |
1628 | 227 | if self._subtitle: | 270 | self.view.header.set_subtitle(self._subtitle) |
1626 | 228 | self.view.setSubTitle(self._subtitle) | ||
1629 | 229 | self._set_translated_strings() | 271 | self._set_translated_strings() |
1630 | 230 | self._connect_ui() | 272 | self._connect_ui() |
1631 | 231 | #pylint: enable=C0103 | 273 | #pylint: enable=C0103 |
1632 | @@ -234,9 +276,9 @@ | |||
1633 | 234 | class SetUpAccountController(BackendController): | 276 | class SetUpAccountController(BackendController): |
1634 | 235 | """Conroller for the setup account view.""" | 277 | """Conroller for the setup account view.""" |
1635 | 236 | 278 | ||
1637 | 237 | def __init__(self, message_box=None): | 279 | def __init__(self, message_box=None, title='', subtitle=''): |
1638 | 238 | """Create a new instance.""" | 280 | """Create a new instance.""" |
1640 | 239 | super(SetUpAccountController, self).__init__() | 281 | super(SetUpAccountController, self).__init__(title, subtitle) |
1641 | 240 | if message_box is None: | 282 | if message_box is None: |
1642 | 241 | message_box = QMessageBox | 283 | message_box = QMessageBox |
1643 | 242 | self.message_box = message_box | 284 | self.message_box = message_box |
1644 | @@ -285,8 +327,6 @@ | |||
1645 | 285 | logger.debug('SetUpAccountController._connect_ui_elements') | 327 | logger.debug('SetUpAccountController._connect_ui_elements') |
1646 | 286 | self.view.ui.terms_button.clicked.connect(self.set_next_tos) | 328 | self.view.ui.terms_button.clicked.connect(self.set_next_tos) |
1647 | 287 | self.view.ui.set_up_button.clicked.connect(self.set_next_validation) | 329 | self.view.ui.set_up_button.clicked.connect(self.set_next_validation) |
1648 | 288 | self.view.ui.terms_checkbox.stateChanged.connect( | ||
1649 | 289 | self.view.ui.set_up_button.setEnabled) | ||
1650 | 290 | self.view.ui.refresh_label.linkActivated.connect(lambda url: \ | 330 | self.view.ui.refresh_label.linkActivated.connect(lambda url: \ |
1651 | 291 | self._refresh_captcha()) | 331 | self._refresh_captcha()) |
1652 | 292 | # set the callbacks for the captcha generation | 332 | # set the callbacks for the captcha generation |
1653 | @@ -296,6 +336,38 @@ | |||
1654 | 296 | self.backend.on_user_registered_cb = self.on_user_registered | 336 | self.backend.on_user_registered_cb = self.on_user_registered |
1655 | 297 | self.backend.on_user_registration_error_cb = \ | 337 | self.backend.on_user_registration_error_cb = \ |
1656 | 298 | self.on_user_registration_error | 338 | self.on_user_registration_error |
1657 | 339 | # We need to check if we enable the button on many signals | ||
1658 | 340 | self.view.ui.name_edit.textEdited.connect(self._enable_setup_button) | ||
1659 | 341 | self.view.ui.email_edit.textEdited.connect(self._enable_setup_button) | ||
1660 | 342 | self.view.ui.confirm_email_edit.textEdited.connect( | ||
1661 | 343 | self._enable_setup_button) | ||
1662 | 344 | self.view.ui.password_edit.textEdited.connect( | ||
1663 | 345 | self._enable_setup_button) | ||
1664 | 346 | self.view.ui.confirm_password_edit.textEdited.connect( | ||
1665 | 347 | self._enable_setup_button) | ||
1666 | 348 | self.view.ui.captcha_solution_edit.textEdited.connect( | ||
1667 | 349 | self._enable_setup_button) | ||
1668 | 350 | self.view.ui.terms_checkbox.stateChanged.connect( | ||
1669 | 351 | self._enable_setup_button) | ||
1670 | 352 | |||
1671 | 353 | def _enable_setup_button(self): | ||
1672 | 354 | """Only enable the setup button if the form is valid.""" | ||
1673 | 355 | email = unicode(self.view.ui.email_edit.text()) | ||
1674 | 356 | confirm_email = unicode(self.view.ui.confirm_email_edit.text()) | ||
1675 | 357 | password = unicode(self.view.ui.password_edit.text()) | ||
1676 | 358 | confirm_password = unicode(self.view.ui.confirm_password_edit.text()) | ||
1677 | 359 | captcha_solution = unicode(self.view.ui.captcha_solution_edit.text()) | ||
1678 | 360 | |||
1679 | 361 | enabled = self.view.ui.terms_checkbox.isChecked() and \ | ||
1680 | 362 | captcha_solution and is_min_required_password(password) and \ | ||
1681 | 363 | password == confirm_password and is_correct_email(email) and \ | ||
1682 | 364 | email == confirm_email | ||
1683 | 365 | |||
1684 | 366 | self.view.ui.set_up_button.setEnabled(enabled) | ||
1685 | 367 | self.view.ui.set_up_button.setProperty("DisabledState", | ||
1686 | 368 | not self.view.ui.set_up_button.isEnabled()) | ||
1687 | 369 | self.view.ui.set_up_button.style().unpolish(self.view.ui.set_up_button) | ||
1688 | 370 | self.view.ui.set_up_button.style().polish(self.view.ui.set_up_button) | ||
1689 | 299 | 371 | ||
1690 | 300 | def _refresh_captcha(self): | 372 | def _refresh_captcha(self): |
1691 | 301 | """Refresh the captcha image shown in the ui.""" | 373 | """Refresh the captcha image shown in the ui.""" |
1692 | @@ -316,9 +388,9 @@ | |||
1693 | 316 | def _set_titles(self): | 388 | def _set_titles(self): |
1694 | 317 | """Set the diff titles of the view.""" | 389 | """Set the diff titles of the view.""" |
1695 | 318 | logger.debug('SetUpAccountController._set_titles') | 390 | logger.debug('SetUpAccountController._set_titles') |
1699 | 319 | wizard = self.view.wizard() | 391 | self.view.header.set_title( |
1700 | 320 | self.view.setTitle(JOIN_HEADER_LABEL % {'app_name': wizard.app_name}) | 392 | JOIN_HEADER_LABEL % {'app_name': self.view.wizard().app_name}) |
1701 | 321 | self.view.setSubTitle(wizard.help_text) | 393 | self.view.header.set_subtitle(self.view.wizard().help_text) |
1702 | 322 | 394 | ||
1703 | 323 | def _register_fields(self): | 395 | def _register_fields(self): |
1704 | 324 | """Register the diff fields of the Ui.""" | 396 | """Register the diff fields of the Ui.""" |
1705 | @@ -348,19 +420,14 @@ | |||
1706 | 348 | def on_captcha_generation_error(self, error): | 420 | def on_captcha_generation_error(self, error): |
1707 | 349 | """An error ocurred.""" | 421 | """An error ocurred.""" |
1708 | 350 | logger.debug('SetUpAccountController.on_captcha_generation_error') | 422 | logger.debug('SetUpAccountController.on_captcha_generation_error') |
1711 | 351 | self.message_box.critical(self.view, self.view.wizard().app_name, | 423 | self.message_box.critical(CAPTCHA_LOAD_ERROR) |
1710 | 352 | CAPTCHA_LOAD_ERROR) | ||
1712 | 353 | 424 | ||
1713 | 354 | def on_user_registration_error(self, app_name, error): | 425 | def on_user_registration_error(self, app_name, error): |
1714 | 355 | """Let the user know we could not register.""" | 426 | """Let the user know we could not register.""" |
1715 | 356 | logger.debug('SetUpAccountController.on_user_registration_error') | 427 | logger.debug('SetUpAccountController.on_user_registration_error') |
1716 | 357 | # errors are returned as a dict with the data we want to show. | 428 | # errors are returned as a dict with the data we want to show. |
1717 | 358 | self._refresh_captcha() | 429 | self._refresh_captcha() |
1723 | 359 | errors = [v for _, v in sorted(error.iteritems())] | 430 | self.message_box.critical(_build_general_error_message(error)) |
1719 | 360 | self.message_box.critical( | ||
1720 | 361 | self.view, | ||
1721 | 362 | self.view.wizard().app_name, | ||
1722 | 363 | '\n'.join(errors)) | ||
1724 | 364 | 431 | ||
1725 | 365 | def on_user_registered(self, app_name, result): | 432 | def on_user_registered(self, app_name, result): |
1726 | 366 | """Execute when the user did register.""" | 433 | """Execute when the user did register.""" |
1727 | @@ -377,35 +444,35 @@ | |||
1728 | 377 | def validate_form(self): | 444 | def validate_form(self): |
1729 | 378 | """Validate the info of the form and return an error.""" | 445 | """Validate the info of the form and return an error.""" |
1730 | 379 | logger.debug('SetUpAccountController.validate_form') | 446 | logger.debug('SetUpAccountController.validate_form') |
1735 | 380 | email = str(self.view.ui.email_edit.text()) | 447 | email = unicode(self.view.ui.email_edit.text()) |
1736 | 381 | confirm_email = str(self.view.ui.confirm_email_edit.text()) | 448 | confirm_email = unicode(self.view.ui.confirm_email_edit.text()) |
1737 | 382 | password = str(self.view.ui.password_edit.text()) | 449 | password = unicode(self.view.ui.password_edit.text()) |
1738 | 383 | confirm_password = str(self.view.ui.confirm_password_edit.text()) | 450 | confirm_password = unicode(self.view.ui.confirm_password_edit.text()) |
1739 | 451 | captcha_solution = unicode(self.view.ui.captcha_solution_edit.text()) | ||
1740 | 384 | if not is_correct_email(email): | 452 | if not is_correct_email(email): |
1743 | 385 | self.message_box.critical(self.view, self.view.wizard().app_name, | 453 | self.message_box.critical(EMAIL_INVALID) |
1742 | 386 | EMAIL_INVALID) | ||
1744 | 387 | if email != confirm_email: | 454 | if email != confirm_email: |
1747 | 388 | self.message_box.critical(self.view, self.view.wizard().app_name, | 455 | self.message_box.critical(EMAIL_MISMATCH) |
1746 | 389 | EMAIL_MISMATCH) | ||
1748 | 390 | return False | 456 | return False |
1749 | 391 | if not is_min_required_password(password): | 457 | if not is_min_required_password(password): |
1752 | 392 | self.message_box.critical(self.view, self.view.wizard().app_name, | 458 | self.message_box.critical(PASSWORD_TOO_WEAK) |
1751 | 393 | PASSWORD_TOO_WEAK) | ||
1753 | 394 | return False | 459 | return False |
1754 | 395 | if password != confirm_password: | 460 | if password != confirm_password: |
1757 | 396 | self.message_box.critical(self.view, self.view.wizard().app_name, | 461 | self.message_box.critical(PASSWORD_MISMATCH) |
1758 | 397 | PASSWORD_MISMATCH) | 462 | return False |
1759 | 463 | if not captcha_solution: | ||
1760 | 464 | self.message_box.critical(CAPTCHA_REQUIRED_ERROR) | ||
1761 | 398 | return False | 465 | return False |
1762 | 399 | return True | 466 | return True |
1763 | 400 | 467 | ||
1764 | 401 | def set_next_validation(self): | 468 | def set_next_validation(self): |
1765 | 402 | """Set the validation as the next page.""" | 469 | """Set the validation as the next page.""" |
1766 | 403 | logger.debug('SetUpAccountController.set_next_validation') | 470 | logger.debug('SetUpAccountController.set_next_validation') |
1770 | 404 | email = str(self.view.ui.email_edit.text()) | 471 | email = unicode(self.view.ui.email_edit.text()) |
1771 | 405 | password = str(self.view.ui.password_edit.text()) | 472 | password = unicode(self.view.ui.password_edit.text()) |
1772 | 406 | name = str(self.view.ui.name_edit.text()) | 473 | name = unicode(self.view.ui.name_edit.text()) |
1773 | 407 | captcha_id = self.view.captcha_id | 474 | captcha_id = self.view.captcha_id |
1775 | 408 | captcha_solution = str(self.view.ui.captcha_solution_edit.text()) | 475 | captcha_solution = unicode(self.view.ui.captcha_solution_edit.text()) |
1776 | 409 | # validate the current info of the form, try to perform the action | 476 | # validate the current info of the form, try to perform the action |
1777 | 410 | # to register the user, and then move foward | 477 | # to register the user, and then move foward |
1778 | 411 | if self.validate_form(): | 478 | if self.validate_form(): |
1779 | @@ -424,12 +491,12 @@ | |||
1780 | 424 | def is_correct_email_confirmation(self, email_address): | 491 | def is_correct_email_confirmation(self, email_address): |
1781 | 425 | """Return that the email is the same.""" | 492 | """Return that the email is the same.""" |
1782 | 426 | logger.debug('SetUpAccountController.is_correct_email_confirmation') | 493 | logger.debug('SetUpAccountController.is_correct_email_confirmation') |
1784 | 427 | return self.view.ui.email_edit.text() == email_address | 494 | return unicode(self.view.ui.email_edit.text()) == email_address |
1785 | 428 | 495 | ||
1786 | 429 | def is_correct_password_confirmation(self, password): | 496 | def is_correct_password_confirmation(self, password): |
1787 | 430 | """Return that the passwords are correct.""" | 497 | """Return that the passwords are correct.""" |
1788 | 431 | logger.debug('SetUpAccountController.is_correct_password_confirmation') | 498 | logger.debug('SetUpAccountController.is_correct_password_confirmation') |
1790 | 432 | return self.view.ui.password_edit.text() == password | 499 | return unicode(self.view.ui.password_edit.text()) == password |
1791 | 433 | 500 | ||
1792 | 434 | #pylint: disable=C0103 | 501 | #pylint: disable=C0103 |
1793 | 435 | @inlineCallbacks | 502 | @inlineCallbacks |
1794 | @@ -441,28 +508,29 @@ | |||
1795 | 441 | self._connect_ui_elements() | 508 | self._connect_ui_elements() |
1796 | 442 | self._refresh_captcha() | 509 | self._refresh_captcha() |
1797 | 443 | self._set_titles() | 510 | self._set_titles() |
1798 | 511 | self.view.header.set_title(self._title) | ||
1799 | 512 | self.view.header.set_subtitle(self._subtitle) | ||
1800 | 444 | self._set_translated_strings() | 513 | self._set_translated_strings() |
1801 | 445 | self._set_line_edits_validations() | 514 | self._set_line_edits_validations() |
1802 | 446 | self._register_fields() | 515 | self._register_fields() |
1803 | 447 | #pylint: enable=C0103 | 516 | #pylint: enable=C0103 |
1804 | 448 | 517 | ||
1805 | 449 | 518 | ||
1807 | 450 | class TosController(object): | 519 | class TosController(BackendController): |
1808 | 451 | """Controller used for the tos page.""" | 520 | """Controller used for the tos page.""" |
1809 | 452 | 521 | ||
1810 | 453 | def __init__(self, title='', subtitle='', tos_url=''): | 522 | def __init__(self, title='', subtitle='', tos_url=''): |
1811 | 454 | """Create a new instance.""" | 523 | """Create a new instance.""" |
1812 | 524 | super(TosController, self).__init__(title, subtitle) | ||
1813 | 455 | self.view = None | 525 | self.view = None |
1814 | 456 | self._title = title | ||
1815 | 457 | self._subtitle = subtitle | ||
1816 | 458 | self._tos_url = tos_url | 526 | self._tos_url = tos_url |
1817 | 459 | 527 | ||
1818 | 460 | #pylint: disable=C0103 | 528 | #pylint: disable=C0103 |
1819 | 461 | def setupUi(self, view): | 529 | def setupUi(self, view): |
1820 | 462 | """Set up the ui.""" | 530 | """Set up the ui.""" |
1821 | 463 | self.view = view | 531 | self.view = view |
1824 | 464 | self.view.setTitle(self._title) | 532 | self.view.header.set_title(self._title) |
1825 | 465 | self.view.setSubTitle(self._subtitle) | 533 | self.view.header.set_subtitle(self._subtitle) |
1826 | 466 | # load the tos page | 534 | # load the tos page |
1827 | 467 | self.view.ui.terms_webkit.load(QUrl(self._tos_url)) | 535 | self.view.ui.terms_webkit.load(QUrl(self._tos_url)) |
1828 | 468 | self.view.ui.tos_link_label.setText( | 536 | self.view.ui.tos_link_label.setText( |
1829 | @@ -474,6 +542,13 @@ | |||
1830 | 474 | class EmailVerificationController(BackendController): | 542 | class EmailVerificationController(BackendController): |
1831 | 475 | """Controller used for the verification page.""" | 543 | """Controller used for the verification page.""" |
1832 | 476 | 544 | ||
1833 | 545 | def __init__(self, message_box=None, title='', subtitle=''): | ||
1834 | 546 | """Create a new instance.""" | ||
1835 | 547 | super(EmailVerificationController, self).__init__(title, subtitle) | ||
1836 | 548 | if message_box is None: | ||
1837 | 549 | message_box = QMessageBox | ||
1838 | 550 | self.message_box = message_box | ||
1839 | 551 | |||
1840 | 477 | def _set_translated_strings(self): | 552 | def _set_translated_strings(self): |
1841 | 478 | """Set the trnaslated strings.""" | 553 | """Set the trnaslated strings.""" |
1842 | 479 | logger.debug('EmailVerificationController._set_translated_strings') | 554 | logger.debug('EmailVerificationController._set_translated_strings') |
1843 | @@ -492,11 +567,11 @@ | |||
1844 | 492 | def _set_titles(self): | 567 | def _set_titles(self): |
1845 | 493 | """Set the different titles.""" | 568 | """Set the different titles.""" |
1846 | 494 | logger.debug('EmailVerificationController._set_titles') | 569 | logger.debug('EmailVerificationController._set_titles') |
1849 | 495 | self.view.setTitle(VERIFY_EMAIL_TITLE) | 570 | self.view.header.set_title(VERIFY_EMAIL_TITLE) |
1850 | 496 | self.view.setSubTitle(VERIFY_EMAIL_CONTENT % { | 571 | self.view.header.set_subtitle(VERIFY_EMAIL_CONTENT % { |
1851 | 497 | "app_name": self.view.wizard().app_name, | 572 | "app_name": self.view.wizard().app_name, |
1852 | 498 | "email": self.view.wizard().field("email_address").toString(), | 573 | "email": self.view.wizard().field("email_address").toString(), |
1854 | 499 | }) | 574 | }) |
1855 | 500 | 575 | ||
1856 | 501 | def set_titles(self): | 576 | def set_titles(self): |
1857 | 502 | """This class needs to have a public set_titles. | 577 | """This class needs to have a public set_titles. |
1858 | @@ -520,9 +595,9 @@ | |||
1859 | 520 | def validate_email(self): | 595 | def validate_email(self): |
1860 | 521 | """Call the next action.""" | 596 | """Call the next action.""" |
1861 | 522 | logger.debug('EmailVerificationController.validate_email') | 597 | logger.debug('EmailVerificationController.validate_email') |
1865 | 523 | email = str(self.view.wizard().field('email_address').toString()) | 598 | email = unicode(self.view.wizard().field('email_address').toString()) |
1866 | 524 | password = str(self.view.wizard().field('password').toString()) | 599 | password = unicode(self.view.wizard().field('password').toString()) |
1867 | 525 | code = str(self.view.ui.verification_code_edit.text()) | 600 | code = unicode(self.view.ui.verification_code_edit.text()) |
1868 | 526 | self.backend.validate_email(self.view.wizard().app_name, email, | 601 | self.backend.validate_email(self.view.wizard().app_name, email, |
1869 | 527 | password, code) | 602 | password, code) |
1870 | 528 | 603 | ||
1871 | @@ -532,16 +607,30 @@ | |||
1872 | 532 | email = self.view.wizard().field('email_address').toString() | 607 | email = self.view.wizard().field('email_address').toString() |
1873 | 533 | self.view.wizard().registrationSuccess.emit(app_name, email) | 608 | self.view.wizard().registrationSuccess.emit(app_name, email) |
1874 | 534 | 609 | ||
1876 | 535 | def on_email_validation_error(self, app_name, raised_error): | 610 | def on_email_validation_error(self, app_name, error): |
1877 | 536 | """Signal thrown when there's a problem validating the email.""" | 611 | """Signal thrown when there's a problem validating the email.""" |
1881 | 537 | 612 | msg = error.get('email_token') | |
1882 | 538 | 613 | if msg is None: | |
1883 | 539 | class ErrorController(object): | 614 | msg = _build_general_error_message(error) |
1884 | 615 | self.message_box.critical(msg) | ||
1885 | 616 | |||
1886 | 617 | #pylint: disable=C0103 | ||
1887 | 618 | def pageInitialized(self): | ||
1888 | 619 | """Called to prepare the page just before it is shown.""" | ||
1889 | 620 | self.view.next_button.setDefault(True) | ||
1890 | 621 | self.view.next_button.style().unpolish( | ||
1891 | 622 | self.view.next_button) | ||
1892 | 623 | self.view.next_button.style().polish( | ||
1893 | 624 | self.view.next_button) | ||
1894 | 625 | #pylint: enable=C0103 | ||
1895 | 626 | |||
1896 | 627 | |||
1897 | 628 | class ErrorController(BackendController): | ||
1898 | 540 | """Controller used for the error page.""" | 629 | """Controller used for the error page.""" |
1899 | 541 | 630 | ||
1901 | 542 | def __init__(self): | 631 | def __init__(self, title='', subtitle=''): |
1902 | 543 | """Create a new instance.""" | 632 | """Create a new instance.""" |
1904 | 544 | super(ErrorController, self).__init__() | 633 | super(ErrorController, self).__init__(title, subtitle) |
1905 | 545 | self.view = None | 634 | self.view = None |
1906 | 546 | 635 | ||
1907 | 547 | #pylint: disable=C0103 | 636 | #pylint: disable=C0103 |
1908 | @@ -550,15 +639,21 @@ | |||
1909 | 550 | self.view = view | 639 | self.view = view |
1910 | 551 | self.view.next = -1 | 640 | self.view.next = -1 |
1911 | 552 | self.view.ui.error_message_label.setText(ERROR) | 641 | self.view.ui.error_message_label.setText(ERROR) |
1912 | 642 | self.view.header.set_title(self._title) | ||
1913 | 643 | self.view.header.set_subtitle(self._subtitle) | ||
1914 | 553 | #pylint: enable=C0103 | 644 | #pylint: enable=C0103 |
1915 | 554 | 645 | ||
1916 | 555 | 646 | ||
1917 | 556 | class ForgottenPasswordController(BackendController): | 647 | class ForgottenPasswordController(BackendController): |
1918 | 557 | """Controller used to deal with the forgotten pwd page.""" | 648 | """Controller used to deal with the forgotten pwd page.""" |
1919 | 558 | 649 | ||
1921 | 559 | def __init__(self): | 650 | def __init__(self, message_box=None, title='', subtitle=''): |
1922 | 560 | """Create a new instance.""" | 651 | """Create a new instance.""" |
1923 | 561 | super(ForgottenPasswordController, self).__init__() | 652 | super(ForgottenPasswordController, self).__init__() |
1924 | 653 | if message_box is None: | ||
1925 | 654 | message_box = QMessageBox | ||
1926 | 655 | self.message_box = message_box | ||
1927 | 656 | super(ForgottenPasswordController, self).__init__(title, subtitle) | ||
1928 | 562 | 657 | ||
1929 | 563 | def _register_fields(self): | 658 | def _register_fields(self): |
1930 | 564 | """Register the fields of the wizard page.""" | 659 | """Register the fields of the wizard page.""" |
1931 | @@ -582,6 +677,7 @@ | |||
1932 | 582 | 677 | ||
1933 | 583 | def _connect_ui(self): | 678 | def _connect_ui(self): |
1934 | 584 | """Connect the diff signals from the Ui.""" | 679 | """Connect the diff signals from the Ui.""" |
1935 | 680 | self.view.email_address_line_edit.textChanged.connect(self._validate) | ||
1936 | 585 | self.view.send_button.clicked.connect( | 681 | self.view.send_button.clicked.connect( |
1937 | 586 | lambda: self.backend.request_password_reset_token( | 682 | lambda: self.backend.request_password_reset_token( |
1938 | 587 | self.view.wizard().app_name, | 683 | self.view.wizard().app_name, |
1939 | @@ -592,6 +688,11 @@ | |||
1940 | 592 | self.on_password_reset_token_sent() | 688 | self.on_password_reset_token_sent() |
1941 | 593 | self.backend.on_password_reset_error_cb = self.on_password_reset_error | 689 | self.backend.on_password_reset_error_cb = self.on_password_reset_error |
1942 | 594 | 690 | ||
1943 | 691 | def _validate(self): | ||
1944 | 692 | """Validate that we have an email.""" | ||
1945 | 693 | email = unicode(self.view.email_address_line_edit.text()) | ||
1946 | 694 | self.view.send_button.setEnabled(is_correct_email(email)) | ||
1947 | 695 | |||
1948 | 595 | def on_try_again(self): | 696 | def on_try_again(self): |
1949 | 596 | """Set back the widget to the initial state.""" | 697 | """Set back the widget to the initial state.""" |
1950 | 597 | self.view.error_label.setVisible(False) | 698 | self.view.error_label.setVisible(False) |
1951 | @@ -632,15 +733,20 @@ | |||
1952 | 632 | self._connect_ui() | 733 | self._connect_ui() |
1953 | 633 | self._set_enhanced_line_edit() | 734 | self._set_enhanced_line_edit() |
1954 | 634 | self._register_fields() | 735 | self._register_fields() |
1955 | 736 | self.view.header.set_title(self._title) | ||
1956 | 737 | self.view.header.set_subtitle(self._subtitle) | ||
1957 | 635 | #pylint: enable=C0103 | 738 | #pylint: enable=C0103 |
1958 | 636 | 739 | ||
1959 | 637 | 740 | ||
1960 | 638 | class ResetPasswordController(BackendController): | 741 | class ResetPasswordController(BackendController): |
1961 | 639 | """Controller used to deal with reseintg the password.""" | 742 | """Controller used to deal with reseintg the password.""" |
1962 | 640 | 743 | ||
1964 | 641 | def __init__(self): | 744 | def __init__(self, title='', subtitle='', message_box=None): |
1965 | 642 | """Create a new instance.""" | 745 | """Create a new instance.""" |
1967 | 643 | super(ResetPasswordController, self).__init__() | 746 | if message_box is None: |
1968 | 747 | message_box = QMessageBox | ||
1969 | 748 | self.message_box = message_box | ||
1970 | 749 | super(ResetPasswordController, self).__init__(title, subtitle) | ||
1971 | 644 | 750 | ||
1972 | 645 | def _set_translated_strings(self): | 751 | def _set_translated_strings(self): |
1973 | 646 | """Translate the diff strings used in the app.""" | 752 | """Translate the diff strings used in the app.""" |
1974 | @@ -658,6 +764,25 @@ | |||
1975 | 658 | self.backend.on_password_changed_cb = self.on_password_changed | 764 | self.backend.on_password_changed_cb = self.on_password_changed |
1976 | 659 | self.backend.on_password_change_error_cb = \ | 765 | self.backend.on_password_change_error_cb = \ |
1977 | 660 | self.on_password_change_error | 766 | self.on_password_change_error |
1978 | 767 | self.view.ui.reset_code_line_edit.textChanged.connect(self._validate) | ||
1979 | 768 | self.view.ui.password_line_edit.textChanged.connect(self._validate) | ||
1980 | 769 | self.view.ui.confirm_password_line_edit.textChanged.connect( | ||
1981 | 770 | self._validate) | ||
1982 | 771 | |||
1983 | 772 | def _validate(self): | ||
1984 | 773 | """Enable the submit button if data is valid.""" | ||
1985 | 774 | enabled = True | ||
1986 | 775 | code = unicode(self.view.ui.reset_code_line_edit.text()) | ||
1987 | 776 | password = unicode(self.view.ui.password_line_edit.text()) | ||
1988 | 777 | confirm_password = unicode( | ||
1989 | 778 | self.view.ui.confirm_password_line_edit.text()) | ||
1990 | 779 | if not is_min_required_password(password): | ||
1991 | 780 | enabled = False | ||
1992 | 781 | elif not self.is_correct_password_confirmation(confirm_password): | ||
1993 | 782 | enabled = False | ||
1994 | 783 | elif not code: | ||
1995 | 784 | enabled = False | ||
1996 | 785 | self.view.ui.reset_password_button.setEnabled(enabled) | ||
1997 | 661 | 786 | ||
1998 | 662 | def _add_line_edits_validations(self): | 787 | def _add_line_edits_validations(self): |
1999 | 663 | """Add the validations to be use by the line edits.""" | 788 | """Add the validations to be use by the line edits.""" |
2000 | @@ -676,20 +801,23 @@ | |||
2001 | 676 | 801 | ||
2002 | 677 | def on_password_change_error(self, app_name, error): | 802 | def on_password_change_error(self, app_name, error): |
2003 | 678 | """Let the user know that there was an error.""" | 803 | """Let the user know that there was an error.""" |
2004 | 804 | logger.error('Got error changing password for %s, error: %s', | ||
2005 | 805 | self.view.wizard().app_name, error) | ||
2006 | 806 | self.message_box.critical(_build_general_error_message(error)) | ||
2007 | 679 | 807 | ||
2008 | 680 | def set_new_password(self): | 808 | def set_new_password(self): |
2009 | 681 | """Request a new password to be set.""" | 809 | """Request a new password to be set.""" |
2010 | 682 | app_name = self.view.wizard().app_name | 810 | app_name = self.view.wizard().app_name |
2014 | 683 | email = str(self.view.wizard().field('email_address').toString()) | 811 | email = unicode(self.view.wizard().field('email_address').toString()) |
2015 | 684 | code = str(self.view.ui.reset_code_line_edit.text()) | 812 | code = unicode(self.view.ui.reset_code_line_edit.text()) |
2016 | 685 | password = str(self.view.ui.password_line_edit.text()) | 813 | password = unicode(self.view.ui.password_line_edit.text()) |
2017 | 686 | logger.info('Settig new password for %s and email %s with code %s', | 814 | logger.info('Settig new password for %s and email %s with code %s', |
2018 | 687 | app_name, email, code) | 815 | app_name, email, code) |
2019 | 688 | self.backend.set_new_password(app_name, email, code, password) | 816 | self.backend.set_new_password(app_name, email, code, password) |
2020 | 689 | 817 | ||
2021 | 690 | def is_correct_password_confirmation(self, password): | 818 | def is_correct_password_confirmation(self, password): |
2022 | 691 | """Return if the password is correct.""" | 819 | """Return if the password is correct.""" |
2024 | 692 | return self.view.ui.password_line_edit.text() == password | 820 | return unicode(self.view.ui.password_line_edit.text()) == password |
2025 | 693 | 821 | ||
2026 | 694 | #pylint: disable=C0103 | 822 | #pylint: disable=C0103 |
2027 | 695 | @inlineCallbacks | 823 | @inlineCallbacks |
2028 | @@ -700,14 +828,17 @@ | |||
2029 | 700 | self._set_translated_strings() | 828 | self._set_translated_strings() |
2030 | 701 | self._connect_ui() | 829 | self._connect_ui() |
2031 | 702 | self._add_line_edits_validations() | 830 | self._add_line_edits_validations() |
2032 | 831 | self.view.header.set_title(self._title) | ||
2033 | 832 | self.view.header.set_subtitle(self._subtitle) | ||
2034 | 703 | #pylint: enable=C0103 | 833 | #pylint: enable=C0103 |
2035 | 704 | 834 | ||
2036 | 705 | 835 | ||
2038 | 706 | class SuccessController(object): | 836 | class SuccessController(BackendController): |
2039 | 707 | """Controller used for the success page.""" | 837 | """Controller used for the success page.""" |
2040 | 708 | 838 | ||
2042 | 709 | def __init__(self): | 839 | def __init__(self, title='', subtitle=''): |
2043 | 710 | """Create a new instance.""" | 840 | """Create a new instance.""" |
2044 | 841 | super(SuccessController, self).__init__(title, subtitle) | ||
2045 | 711 | self.view = None | 842 | self.view = None |
2046 | 712 | 843 | ||
2047 | 713 | #pylint: disable=C0103 | 844 | #pylint: disable=C0103 |
2048 | @@ -716,6 +847,8 @@ | |||
2049 | 716 | self.view = view | 847 | self.view = view |
2050 | 717 | self.view.next = -1 | 848 | self.view.next = -1 |
2051 | 718 | self.view.ui.success_message_label.setText(SUCCESS) | 849 | self.view.ui.success_message_label.setText(SUCCESS) |
2052 | 850 | self.view.header.set_title(self._title) | ||
2053 | 851 | self.view.header.set_subtitle(self._subtitle) | ||
2054 | 719 | #pylint: enable=C0103 | 852 | #pylint: enable=C0103 |
2055 | 720 | 853 | ||
2056 | 721 | 854 | ||
2057 | @@ -741,7 +874,8 @@ | |||
2058 | 741 | def on_login_success(self, app_name, email): | 874 | def on_login_success(self, app_name, email): |
2059 | 742 | """Process the success of a login.""" | 875 | """Process the success of a login.""" |
2060 | 743 | logger.debug('UbuntuSSOWizardController.on_login_success') | 876 | logger.debug('UbuntuSSOWizardController.on_login_success') |
2062 | 744 | result = yield self.login_success_callback(str(app_name), str(email)) | 877 | result = yield self.login_success_callback( |
2063 | 878 | unicode(app_name), unicode(email)) | ||
2064 | 745 | logger.debug('Result from callback is %s', result) | 879 | logger.debug('Result from callback is %s', result) |
2065 | 746 | if result == 0: | 880 | if result == 0: |
2066 | 747 | logger.info('Success in calling the given success_callback') | 881 | logger.info('Success in calling the given success_callback') |
2067 | @@ -754,8 +888,8 @@ | |||
2068 | 754 | def on_registration_success(self, app_name, email): | 888 | def on_registration_success(self, app_name, email): |
2069 | 755 | """Process the success of a registration.""" | 889 | """Process the success of a registration.""" |
2070 | 756 | logger.debug('UbuntuSSOWizardController.on_registration_success') | 890 | logger.debug('UbuntuSSOWizardController.on_registration_success') |
2073 | 757 | result = yield self.registration_success_callback(str(app_name), | 891 | result = yield self.registration_success_callback(unicode(app_name), |
2074 | 758 | str(email)) | 892 | unicode(email)) |
2075 | 759 | # TODO: what to do? | 893 | # TODO: what to do? |
2076 | 760 | logger.debug('Result from callback is %s', result) | 894 | logger.debug('Result from callback is %s', result) |
2077 | 761 | if result == 0: | 895 | if result == 0: |
2078 | 762 | 896 | ||
2079 | === modified file 'ubuntu_sso/qt/gui.py' | |||
2080 | --- ubuntu_sso/qt/gui.py 2011-06-24 19:14:17 +0000 | |||
2081 | +++ ubuntu_sso/qt/gui.py 2011-08-25 19:16:19 +0000 | |||
2082 | @@ -17,15 +17,18 @@ | |||
2083 | 17 | """Qt implementation of the UI.""" | 17 | """Qt implementation of the UI.""" |
2084 | 18 | 18 | ||
2085 | 19 | from PyQt4.QtCore import pyqtSignal | 19 | from PyQt4.QtCore import pyqtSignal |
2086 | 20 | from PyQt4.QtCore import Qt | ||
2087 | 20 | from PyQt4.QtGui import ( | 21 | from PyQt4.QtGui import ( |
2088 | 21 | QApplication, | 22 | QApplication, |
2089 | 23 | QWidget, | ||
2090 | 22 | QCursor, | 24 | QCursor, |
2091 | 23 | QHBoxLayout, | 25 | QHBoxLayout, |
2092 | 26 | QVBoxLayout, | ||
2093 | 24 | QPixmap, | 27 | QPixmap, |
2094 | 25 | QPushButton, | ||
2095 | 26 | QStyle, | 28 | QStyle, |
2096 | 27 | QWizard, | 29 | QWizard, |
2098 | 28 | QWizardPage) | 30 | QWizardPage, |
2099 | 31 | QLabel) | ||
2100 | 29 | 32 | ||
2101 | 30 | from ubuntu_sso.logger import setup_logging | 33 | from ubuntu_sso.logger import setup_logging |
2102 | 31 | # pylint: disable=F0401,E0611 | 34 | # pylint: disable=F0401,E0611 |
2103 | @@ -55,6 +58,40 @@ | |||
2104 | 55 | logger = setup_logging('ubuntu_sso.gui') | 58 | logger = setup_logging('ubuntu_sso.gui') |
2105 | 56 | 59 | ||
2106 | 57 | 60 | ||
2107 | 61 | class Header(QWidget): | ||
2108 | 62 | """Header Class for Title and Subtitle in all wizard pages.""" | ||
2109 | 63 | |||
2110 | 64 | def __init__(self): | ||
2111 | 65 | """Create a new instance.""" | ||
2112 | 66 | QWidget.__init__(self) | ||
2113 | 67 | vbox = QVBoxLayout(self) | ||
2114 | 68 | self.title_label = QLabel() | ||
2115 | 69 | self.title_label.setWordWrap(True) | ||
2116 | 70 | self.title_label.setObjectName('title_label') | ||
2117 | 71 | self.subtitle_label = QLabel() | ||
2118 | 72 | self.subtitle_label.setWordWrap(True) | ||
2119 | 73 | vbox.addWidget(self.title_label) | ||
2120 | 74 | vbox.addWidget(self.subtitle_label) | ||
2121 | 75 | self.title_label.setVisible(False) | ||
2122 | 76 | self.subtitle_label.setVisible(False) | ||
2123 | 77 | |||
2124 | 78 | def set_title(self, title): | ||
2125 | 79 | """Set the Title of the page or hide it otherwise""" | ||
2126 | 80 | if title: | ||
2127 | 81 | self.title_label.setText(title) | ||
2128 | 82 | self.title_label.setVisible(True) | ||
2129 | 83 | else: | ||
2130 | 84 | self.title_label.setVisible(False) | ||
2131 | 85 | |||
2132 | 86 | def set_subtitle(self, subtitle): | ||
2133 | 87 | """Set the Subtitle of the page or hide it otherwise""" | ||
2134 | 88 | if subtitle: | ||
2135 | 89 | self.subtitle_label.setText(subtitle) | ||
2136 | 90 | self.subtitle_label.setVisible(True) | ||
2137 | 91 | else: | ||
2138 | 92 | self.subtitle_label.setVisible(False) | ||
2139 | 93 | |||
2140 | 94 | |||
2141 | 58 | class SSOWizardPage(QWizardPage): | 95 | class SSOWizardPage(QWizardPage): |
2142 | 59 | """Root class for all wizard pages.""" | 96 | """Root class for all wizard pages.""" |
2143 | 60 | 97 | ||
2144 | @@ -63,8 +100,11 @@ | |||
2145 | 63 | QWizardPage.__init__(self, parent) | 100 | QWizardPage.__init__(self, parent) |
2146 | 64 | self.ui = ui | 101 | self.ui = ui |
2147 | 65 | self.ui.setupUi(self) | 102 | self.ui.setupUi(self) |
2150 | 66 | self.controller = controller | 103 | self.header = Header() |
2151 | 67 | self.controller.setupUi(self) | 104 | self.layout().insertWidget(0, self.header) |
2152 | 105 | if controller: | ||
2153 | 106 | self.controller = controller | ||
2154 | 107 | self.controller.setupUi(self) | ||
2155 | 68 | self.next = -1 | 108 | self.next = -1 |
2156 | 69 | 109 | ||
2157 | 70 | # pylint: disable=C0103 | 110 | # pylint: disable=C0103 |
2158 | @@ -73,6 +113,25 @@ | |||
2159 | 73 | return self.next | 113 | return self.next |
2160 | 74 | # pylint: enable=C0103 | 114 | # pylint: enable=C0103 |
2161 | 75 | 115 | ||
2162 | 116 | # pylint: disable=C0103 | ||
2163 | 117 | def initializePage(self): | ||
2164 | 118 | """Called to prepare the page just before it is shown.""" | ||
2165 | 119 | if self.controller: | ||
2166 | 120 | self.controller.pageInitialized() | ||
2167 | 121 | # pylint: enable=C0103 | ||
2168 | 122 | |||
2169 | 123 | # pylint: disable=C0103 | ||
2170 | 124 | def setTitle(self, title=''): | ||
2171 | 125 | """Set the Wizard Page Title.""" | ||
2172 | 126 | self.header.set_title(title) | ||
2173 | 127 | # pylint: enable=C0103 | ||
2174 | 128 | |||
2175 | 129 | # pylint: disable=C0103 | ||
2176 | 130 | def setSubTitle(self, subtitle=''): | ||
2177 | 131 | """Set the Wizard Page Subtitle.""" | ||
2178 | 132 | self.header.set_subtitle(subtitle) | ||
2179 | 133 | # pylint: enable=C0103 | ||
2180 | 134 | |||
2181 | 76 | 135 | ||
2182 | 77 | class EnhancedLineEdit(object): | 136 | class EnhancedLineEdit(object): |
2183 | 78 | """Represents and enhanced lineedit. | 137 | """Represents and enhanced lineedit. |
2184 | @@ -81,7 +140,8 @@ | |||
2185 | 81 | that we are just adding extra items to it. | 140 | that we are just adding extra items to it. |
2186 | 82 | """ | 141 | """ |
2187 | 83 | 142 | ||
2189 | 84 | def __init__(self, line_edit, valid_cb=lambda x: False): | 143 | def __init__(self, line_edit, valid_cb=lambda x: False, |
2190 | 144 | warning_sign=False): | ||
2191 | 85 | """Create an instance.""" | 145 | """Create an instance.""" |
2192 | 86 | self._line_edit = line_edit | 146 | self._line_edit = line_edit |
2193 | 87 | layout = QHBoxLayout(self._line_edit) | 147 | layout = QHBoxLayout(self._line_edit) |
2194 | @@ -89,24 +149,27 @@ | |||
2195 | 89 | self._line_edit.setLayout(layout) | 149 | self._line_edit.setLayout(layout) |
2196 | 90 | self.valid_cb = valid_cb | 150 | self.valid_cb = valid_cb |
2197 | 91 | layout.addStretch() | 151 | layout.addStretch() |
2206 | 92 | self.clear_button = QPushButton(self._line_edit) | 152 | self.clear_label = QLabel(self._line_edit) |
2207 | 93 | layout.addWidget(self.clear_button) | 153 | self.clear_label.setMargin(2) |
2208 | 94 | self.clear_button.setMinimumSize(16, 16) | 154 | self.clear_label.setProperty("lineEditWarning", True) |
2209 | 95 | self.clear_button.setVisible(False) | 155 | layout.addWidget(self.clear_label) |
2210 | 96 | self.clear_button.setFlat(True) | 156 | self.clear_label.setMinimumSize(16, 16) |
2211 | 97 | self.clear_button.setCursor(QCursor(0)) | 157 | self.clear_label.setVisible(False) |
2212 | 98 | self.clear_button.setIcon(QApplication.style().standardIcon( | 158 | self.clear_label.setCursor(QCursor(Qt.ArrowCursor)) |
2213 | 99 | QStyle.SP_MessageBoxWarning)) | 159 | if warning_sign: |
2214 | 160 | icon = QApplication.style().standardIcon( | ||
2215 | 161 | QStyle.SP_MessageBoxWarning) | ||
2216 | 162 | self.clear_label.setPixmap(icon.pixmap(16, 16)) | ||
2217 | 100 | # connect the change of text to the cation that will check if the | 163 | # connect the change of text to the cation that will check if the |
2218 | 101 | # text is valid and if the icon should be shown. | 164 | # text is valid and if the icon should be shown. |
2219 | 102 | self._line_edit.textChanged.connect(self.show_button) | 165 | self._line_edit.textChanged.connect(self.show_button) |
2220 | 103 | 166 | ||
2221 | 104 | def show_button(self, string): | 167 | def show_button(self, string): |
2222 | 105 | """Decide if we show the button or not.""" | 168 | """Decide if we show the button or not.""" |
2225 | 106 | if not self.valid_cb(string): | 169 | if not self.valid_cb(string) and self.clear_label.pixmap() is not None: |
2226 | 107 | self.clear_button.setVisible(True) | 170 | self.clear_label.setVisible(True) |
2227 | 108 | else: | 171 | else: |
2229 | 109 | self.clear_button.setVisible(False) | 172 | self.clear_label.setVisible(False) |
2230 | 110 | 173 | ||
2231 | 111 | 174 | ||
2232 | 112 | class SSOWizardEnhancedEditPage(SSOWizardPage): | 175 | class SSOWizardEnhancedEditPage(SSOWizardPage): |
2233 | 113 | 176 | ||
2234 | === added file 'ubuntu_sso/qt/tests/login_u_p.py' | |||
2235 | --- ubuntu_sso/qt/tests/login_u_p.py 1970-01-01 00:00:00 +0000 | |||
2236 | +++ ubuntu_sso/qt/tests/login_u_p.py 2011-08-25 19:16:19 +0000 | |||
2237 | @@ -0,0 +1,54 @@ | |||
2238 | 1 | # -*- coding: utf-8 -*- | ||
2239 | 2 | # Author: Manuel de la Pena <manuel@canonical.com> | ||
2240 | 3 | # | ||
2241 | 4 | # Copyright 2011 Canonical Ltd. | ||
2242 | 5 | # | ||
2243 | 6 | # This program is free software: you can redistribute it and/or modify it | ||
2244 | 7 | # under the terms of the GNU General Public License version 3, as published | ||
2245 | 8 | # by the Free Software Foundation. | ||
2246 | 9 | # | ||
2247 | 10 | # This program is distributed in the hope that it will be useful, but | ||
2248 | 11 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2249 | 12 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2250 | 13 | # PURPOSE. See the GNU General Public License for more details. | ||
2251 | 14 | # | ||
2252 | 15 | # You should have received a copy of the GNU General Public License along | ||
2253 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2254 | 17 | """Script that shows the qt gui.""" | ||
2255 | 18 | |||
2256 | 19 | # pylint: disable=F0401, E1101 | ||
2257 | 20 | from twisted.internet import reactor | ||
2258 | 21 | from twisted.internet.defer import inlineCallbacks | ||
2259 | 22 | from ubuntu_sso.main.windows import UbuntuSSOClient | ||
2260 | 23 | |||
2261 | 24 | |||
2262 | 25 | def found(*args): | ||
2263 | 26 | """The credentials were found.""" | ||
2264 | 27 | print "creds found", args | ||
2265 | 28 | reactor.stop() | ||
2266 | 29 | |||
2267 | 30 | |||
2268 | 31 | def errback(*args): | ||
2269 | 32 | """Unsuccessful login.""" | ||
2270 | 33 | print "EB:", args | ||
2271 | 34 | |||
2272 | 35 | |||
2273 | 36 | @inlineCallbacks | ||
2274 | 37 | def main(): | ||
2275 | 38 | """Perform a client request to be logged in.""" | ||
2276 | 39 | client = UbuntuSSOClient() | ||
2277 | 40 | client = yield client.connect() | ||
2278 | 41 | yield client.cred_management.register_to_signals() | ||
2279 | 42 | client.cred_management.on_credentials_found_cb = found | ||
2280 | 43 | client.cred_management.on_credentials_error_cb = errback | ||
2281 | 44 | yield client.cred_management.login_email_password('SUPER', dict( | ||
2282 | 45 | app_name='SUPER', | ||
2283 | 46 | email='xyz@canonical.com', | ||
2284 | 47 | password='ABC', | ||
2285 | 48 | )) | ||
2286 | 49 | print "called ok" | ||
2287 | 50 | |||
2288 | 51 | |||
2289 | 52 | if __name__ == '__main__': | ||
2290 | 53 | main() | ||
2291 | 54 | reactor.run() | ||
2292 | 0 | 55 | ||
2293 | === modified file 'ubuntu_sso/qt/tests/show_gui.py' | |||
2294 | --- ubuntu_sso/qt/tests/show_gui.py 2011-07-22 20:12:20 +0000 | |||
2295 | +++ ubuntu_sso/qt/tests/show_gui.py 2011-08-25 19:16:19 +0000 | |||
2296 | @@ -20,6 +20,12 @@ | |||
2297 | 20 | from twisted.internet import reactor | 20 | from twisted.internet import reactor |
2298 | 21 | from twisted.internet.defer import inlineCallbacks | 21 | from twisted.internet.defer import inlineCallbacks |
2299 | 22 | from ubuntu_sso.main.windows import UbuntuSSOClient | 22 | from ubuntu_sso.main.windows import UbuntuSSOClient |
2300 | 23 | from ubuntu_sso.credentials import ( | ||
2301 | 24 | TC_URL_KEY, | ||
2302 | 25 | HELP_TEXT_KEY, | ||
2303 | 26 | WINDOW_ID_KEY, | ||
2304 | 27 | UI_MODULE_KEY, | ||
2305 | 28 | ) | ||
2306 | 23 | 29 | ||
2307 | 24 | 30 | ||
2308 | 25 | def found(*args): | 31 | def found(*args): |
2309 | @@ -33,11 +39,16 @@ | |||
2310 | 33 | """Perform a client request to be logged in.""" | 39 | """Perform a client request to be logged in.""" |
2311 | 34 | client = UbuntuSSOClient() | 40 | client = UbuntuSSOClient() |
2312 | 35 | client = yield client.connect() | 41 | client = yield client.connect() |
2318 | 36 | client.sso_cred.on_credentials_found_cb = found | 42 | client.cred_management.on_credentials_found_cb = found |
2319 | 37 | yield client.sso_cred.register_to_signals() | 43 | yield client.cred_management.register_to_signals() |
2320 | 38 | yield client.sso_cred.login_or_register_to_get_credentials('Ubuntu One', | 44 | yield client.cred_management.login( |
2321 | 39 | 'http://www.google.com', | 45 | 'Ubuntu One', |
2322 | 40 | 'This is a test.', 0) | 46 | { |
2323 | 47 | TC_URL_KEY: 'http://www.google.com', | ||
2324 | 48 | HELP_TEXT_KEY: 'This is a test.', | ||
2325 | 49 | WINDOW_ID_KEY: 0, | ||
2326 | 50 | UI_MODULE_KEY: 'ubuntu_sso.qt.gui', | ||
2327 | 51 | }) | ||
2328 | 41 | print "called ok" | 52 | print "called ok" |
2329 | 42 | 53 | ||
2330 | 43 | 54 | ||
2331 | 44 | 55 | ||
2332 | === added file 'ubuntu_sso/qt/tests/test_enchanced_line_edit.py' | |||
2333 | --- ubuntu_sso/qt/tests/test_enchanced_line_edit.py 1970-01-01 00:00:00 +0000 | |||
2334 | +++ ubuntu_sso/qt/tests/test_enchanced_line_edit.py 2011-08-25 19:16:19 +0000 | |||
2335 | @@ -0,0 +1,94 @@ | |||
2336 | 1 | # -*- coding: utf-8 -*- | ||
2337 | 2 | # Author: Diego Sarmentero <diego.sarmentero@canonical.com> | ||
2338 | 3 | # | ||
2339 | 4 | # Copyright 2011 Canonical Ltd. | ||
2340 | 5 | # | ||
2341 | 6 | # This program is free software: you can redistribute it and/or modify it | ||
2342 | 7 | # under the terms of the GNU General Public License version 3, as published | ||
2343 | 8 | # by the Free Software Foundation. | ||
2344 | 9 | # | ||
2345 | 10 | # This program is distributed in the hope that it will be useful, but | ||
2346 | 11 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2347 | 12 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2348 | 13 | # PURPOSE. See the GNU General Public License for more details. | ||
2349 | 14 | # | ||
2350 | 15 | # You should have received a copy of the GNU General Public License along | ||
2351 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2352 | 17 | """Test the EnhancedLineEdit.""" | ||
2353 | 18 | |||
2354 | 19 | import collections | ||
2355 | 20 | |||
2356 | 21 | from twisted.trial.unittest import TestCase | ||
2357 | 22 | |||
2358 | 23 | from PyQt4 import QtGui | ||
2359 | 24 | from PyQt4 import QtCore | ||
2360 | 25 | |||
2361 | 26 | from ubuntu_sso.qt.gui import EnhancedLineEdit | ||
2362 | 27 | |||
2363 | 28 | |||
2364 | 29 | class EnhancedLineEditTestCase(TestCase): | ||
2365 | 30 | """Tests EnhancedLineEdit for valid and invalid states.""" | ||
2366 | 31 | |||
2367 | 32 | def get_pixmap_data(self, pixmap): | ||
2368 | 33 | """Get the raw data of a QPixmap.""" | ||
2369 | 34 | byte_array = QtCore.QByteArray() | ||
2370 | 35 | array_buffer = QtCore.QBuffer(byte_array) | ||
2371 | 36 | pixmap.save(array_buffer, "PNG") | ||
2372 | 37 | return byte_array | ||
2373 | 38 | |||
2374 | 39 | # pylint: disable=C0103 | ||
2375 | 40 | def assertEqualPixmaps(self, pixmap1, pixmap2): | ||
2376 | 41 | """Compare two Qt pixmaps.""" | ||
2377 | 42 | d1 = self.get_pixmap_data(pixmap1) | ||
2378 | 43 | d2 = self.get_pixmap_data(pixmap2) | ||
2379 | 44 | self.assertEqual(d1, d2) | ||
2380 | 45 | # pylint: enable=C0103 | ||
2381 | 46 | |||
2382 | 47 | def test_enhanced_line_edit_init(self): | ||
2383 | 48 | """Tests the initial state of the enchanced line edit.""" | ||
2384 | 49 | line_edit = QtGui.QLineEdit() | ||
2385 | 50 | line_edit.show() | ||
2386 | 51 | enhanced = EnhancedLineEdit(line_edit) | ||
2387 | 52 | self.assertIsInstance(enhanced.valid_cb, collections.Callable) | ||
2388 | 53 | self.assertTrue(enhanced.clear_label.property("lineEditWarning")) | ||
2389 | 54 | self.assertFalse(enhanced.clear_label.isVisible()) | ||
2390 | 55 | self.assertEqual(enhanced.clear_label.cursor().shape(), | ||
2391 | 56 | QtCore.Qt.ArrowCursor) | ||
2392 | 57 | self.assertFalse(enhanced.clear_label.isVisible()) | ||
2393 | 58 | self.assertEqual(enhanced.clear_label.pixmap(), None) | ||
2394 | 59 | |||
2395 | 60 | def test_enhanced_line_edit_init_with_icon(self): | ||
2396 | 61 | """Tests the initial state of the enchanced line edit.""" | ||
2397 | 62 | line_edit = QtGui.QLineEdit() | ||
2398 | 63 | line_edit.show() | ||
2399 | 64 | enhanced = EnhancedLineEdit(line_edit, warning_sign=True) | ||
2400 | 65 | self.assertIsInstance(enhanced.valid_cb, collections.Callable) | ||
2401 | 66 | edit_property = enhanced.clear_label.property("lineEditWarning") | ||
2402 | 67 | self.assertTrue(edit_property) | ||
2403 | 68 | self.assertFalse(enhanced.clear_label.isVisible()) | ||
2404 | 69 | self.assertEqual(enhanced.clear_label.cursor().shape(), | ||
2405 | 70 | QtCore.Qt.ArrowCursor) | ||
2406 | 71 | self.assertFalse(enhanced.clear_label.isVisible()) | ||
2407 | 72 | icon = QtGui.QApplication.style().standardIcon( | ||
2408 | 73 | QtGui.QStyle.SP_MessageBoxWarning) | ||
2409 | 74 | self.assertEqualPixmaps(enhanced.clear_label.pixmap(), | ||
2410 | 75 | icon.pixmap(16, 16)) | ||
2411 | 76 | |||
2412 | 77 | def test_enhanced_line_edit_function_show_true(self): | ||
2413 | 78 | """Tests the EnchancedLineEdit show method with validation = True.""" | ||
2414 | 79 | line_edit = QtGui.QLineEdit() | ||
2415 | 80 | line_edit.show() | ||
2416 | 81 | func = lambda x: False | ||
2417 | 82 | enhanced = EnhancedLineEdit(line_edit, valid_cb=func, | ||
2418 | 83 | warning_sign=True) | ||
2419 | 84 | line_edit.setText("testing") | ||
2420 | 85 | self.assertTrue(enhanced.clear_label.isVisible()) | ||
2421 | 86 | |||
2422 | 87 | def test_enhanced_line_edit_function_show_false(self): | ||
2423 | 88 | """Tests the EnchancedLineEdit show method with validation = False.""" | ||
2424 | 89 | line_edit = QtGui.QLineEdit() | ||
2425 | 90 | line_edit.show() | ||
2426 | 91 | func = lambda x: True | ||
2427 | 92 | enhanced = EnhancedLineEdit(line_edit, valid_cb=func) | ||
2428 | 93 | line_edit.setText("testing") | ||
2429 | 94 | self.assertFalse(enhanced.clear_label.isVisible()) | ||
2430 | 0 | 95 | ||
2431 | === modified file 'ubuntu_sso/qt/tests/test_qt_views.py' | |||
2432 | --- ubuntu_sso/qt/tests/test_qt_views.py 2011-06-24 19:14:17 +0000 | |||
2433 | +++ ubuntu_sso/qt/tests/test_qt_views.py 2011-08-25 19:16:19 +0000 | |||
2434 | @@ -24,6 +24,7 @@ | |||
2435 | 24 | CurrentUserSignInPage, | 24 | CurrentUserSignInPage, |
2436 | 25 | EmailVerificationPage, | 25 | EmailVerificationPage, |
2437 | 26 | ErrorPage, | 26 | ErrorPage, |
2438 | 27 | Header, | ||
2439 | 27 | SetupAccountPage, | 28 | SetupAccountPage, |
2440 | 28 | SuccessPage, | 29 | SuccessPage, |
2441 | 29 | TosPage) | 30 | TosPage) |
2442 | @@ -72,7 +73,7 @@ | |||
2443 | 72 | ui.setupUi(MATCH(lambda x: isinstance(x, ChooseSignInPage))) | 73 | ui.setupUi(MATCH(lambda x: isinstance(x, ChooseSignInPage))) |
2444 | 73 | controller.setupUi(MATCH(lambda x: isinstance(x, ChooseSignInPage))) | 74 | controller.setupUi(MATCH(lambda x: isinstance(x, ChooseSignInPage))) |
2445 | 74 | mocker.replay() | 75 | mocker.replay() |
2447 | 75 | self.widget = ChooseSignInPage(ui, controller) | 76 | self.widget = ChooseSignInPage(self.ui, self.controller) |
2448 | 76 | 77 | ||
2449 | 77 | def test_next_id(self): | 78 | def test_next_id(self): |
2450 | 78 | """Test the nextId method.""" | 79 | """Test the nextId method.""" |
2451 | @@ -217,3 +218,45 @@ | |||
2452 | 217 | controller.setupUi(MATCH(lambda x: isinstance(x, ErrorPage))) | 218 | controller.setupUi(MATCH(lambda x: isinstance(x, ErrorPage))) |
2453 | 218 | mocker.replay() | 219 | mocker.replay() |
2454 | 219 | self.widget = ErrorPage(self.ui, self.controller) | 220 | self.widget = ErrorPage(self.ui, self.controller) |
2455 | 221 | |||
2456 | 222 | |||
2457 | 223 | class HeaderTest(TestCase): | ||
2458 | 224 | """Tests for injected Header in each Wizard Page.""" | ||
2459 | 225 | |||
2460 | 226 | def setUp(self): | ||
2461 | 227 | """Setup test.""" | ||
2462 | 228 | super(HeaderTest, self).setUp() | ||
2463 | 229 | self.header = Header() | ||
2464 | 230 | |||
2465 | 231 | def test_label_state(self): | ||
2466 | 232 | """Check the title and subtitle properties.""" | ||
2467 | 233 | self.assertTrue(self.header.title_label.wordWrap()) | ||
2468 | 234 | self.assertTrue(self.header.subtitle_label.wordWrap()) | ||
2469 | 235 | self.assertFalse(self.header.title_label.isVisible()) | ||
2470 | 236 | self.assertFalse(self.header.subtitle_label.isVisible()) | ||
2471 | 237 | |||
2472 | 238 | def test_set_title(self): | ||
2473 | 239 | """Check if set_title works ok, showing the widget if necessary.""" | ||
2474 | 240 | self.header.set_title('title') | ||
2475 | 241 | self.assertEqual(self.header.title_label.text(), 'title') | ||
2476 | 242 | self.header.show() | ||
2477 | 243 | self.assertTrue(self.header.title_label.isVisible()) | ||
2478 | 244 | self.header.hide() | ||
2479 | 245 | |||
2480 | 246 | def test_set_empty_title(self): | ||
2481 | 247 | """Check if the widget is hidden for empty title.""" | ||
2482 | 248 | self.header.set_title('') | ||
2483 | 249 | self.assertFalse(self.header.title_label.isVisible()) | ||
2484 | 250 | |||
2485 | 251 | def test_set_subtitle(self): | ||
2486 | 252 | """Check if set_subtitle works ok, showing the widget if necessary.""" | ||
2487 | 253 | self.header.set_subtitle('subtitle') | ||
2488 | 254 | self.assertEqual(self.header.subtitle_label.text(), 'subtitle') | ||
2489 | 255 | self.header.show() | ||
2490 | 256 | self.assertTrue(self.header.subtitle_label.isVisible()) | ||
2491 | 257 | self.header.hide() | ||
2492 | 258 | |||
2493 | 259 | def test_set_empty_subtitle(self): | ||
2494 | 260 | """Check if the widget is hidden for empty subtitle.""" | ||
2495 | 261 | self.header.set_title('') | ||
2496 | 262 | self.assertFalse(self.header.title_label.isVisible()) | ||
2497 | 220 | 263 | ||
2498 | === modified file 'ubuntu_sso/qt/tests/test_windows.py' | |||
2499 | --- ubuntu_sso/qt/tests/test_windows.py 2011-07-22 20:12:20 +0000 | |||
2500 | +++ ubuntu_sso/qt/tests/test_windows.py 2011-08-25 19:16:19 +0000 | |||
2501 | @@ -35,6 +35,7 @@ | |||
2502 | 35 | UbuntuSSOWizardController) | 35 | UbuntuSSOWizardController) |
2503 | 36 | from ubuntu_sso.utils.ui import ( | 36 | from ubuntu_sso.utils.ui import ( |
2504 | 37 | CAPTCHA_SOLUTION_ENTRY, | 37 | CAPTCHA_SOLUTION_ENTRY, |
2505 | 38 | CAPTCHA_REQUIRED_ERROR, | ||
2506 | 38 | EMAIL1_ENTRY, | 39 | EMAIL1_ENTRY, |
2507 | 39 | EMAIL2_ENTRY, | 40 | EMAIL2_ENTRY, |
2508 | 40 | EMAIL_MISMATCH, | 41 | EMAIL_MISMATCH, |
2509 | @@ -69,7 +70,7 @@ | |||
2510 | 69 | is_correct_email) | 70 | is_correct_email) |
2511 | 70 | 71 | ||
2512 | 71 | #ignore the comon mocker issues with lint | 72 | #ignore the comon mocker issues with lint |
2514 | 72 | # pylint: disable=W0212,W0104,W0106 | 73 | # pylint: disable=W0212,W0104,W0106,E1103 |
2515 | 73 | 74 | ||
2516 | 74 | 75 | ||
2517 | 75 | class ChooseSignInControllerTestCase(MockerTestCase): | 76 | class ChooseSignInControllerTestCase(MockerTestCase): |
2518 | @@ -83,6 +84,19 @@ | |||
2519 | 83 | self.controller = ChooseSignInController() | 84 | self.controller = ChooseSignInController() |
2520 | 84 | self.controller.view = self.view | 85 | self.controller.view = self.view |
2521 | 85 | self.controller.backend = self.backend | 86 | self.controller.backend = self.backend |
2522 | 87 | self.title = 'title' | ||
2523 | 88 | self.subtitle = 'sub' | ||
2524 | 89 | |||
2525 | 90 | def test_setup_ui(self): | ||
2526 | 91 | """Test the set up of the ui.""" | ||
2527 | 92 | self.controller._title = self.title | ||
2528 | 93 | self.controller._subtitle = self.subtitle | ||
2529 | 94 | self.controller._set_up_translated_strings() | ||
2530 | 95 | self.view.header.set_title(self.title) | ||
2531 | 96 | self.view.header.set_subtitle(self.subtitle) | ||
2532 | 97 | self.controller._connect_buttons() | ||
2533 | 98 | self.mocker.replay() | ||
2534 | 99 | self.controller.setupUi(self.view) | ||
2535 | 86 | 100 | ||
2536 | 87 | def test_set_up_translated_strings(self): | 101 | def test_set_up_translated_strings(self): |
2537 | 88 | """Ensure that the translations are used.""" | 102 | """Ensure that the translations are used.""" |
2538 | @@ -156,6 +170,8 @@ | |||
2539 | 156 | self.backend.on_logged_in_cb = MATCH(callable) | 170 | self.backend.on_logged_in_cb = MATCH(callable) |
2540 | 157 | self.view.ui.forgot_password_label.linkActivated.connect( | 171 | self.view.ui.forgot_password_label.linkActivated.connect( |
2541 | 158 | MATCH(callable)) | 172 | MATCH(callable)) |
2542 | 173 | self.view.ui.email_edit.textChanged.connect(MATCH(callable)) | ||
2543 | 174 | self.view.ui.password_edit.textChanged.connect(MATCH(callable)) | ||
2544 | 159 | self.mocker.replay() | 175 | self.mocker.replay() |
2545 | 160 | self.controller._connect_ui() | 176 | self.controller._connect_ui() |
2546 | 161 | 177 | ||
2547 | @@ -166,6 +182,227 @@ | |||
2548 | 166 | self.assertEqual(self.controller._subtitle, 'the subtitle') | 182 | self.assertEqual(self.controller._subtitle, 'the subtitle') |
2549 | 167 | 183 | ||
2550 | 168 | 184 | ||
2551 | 185 | class FakeLineEdit(object): | ||
2552 | 186 | |||
2553 | 187 | """A fake QLineEdit.""" | ||
2554 | 188 | |||
2555 | 189 | def __init__(self, *args): | ||
2556 | 190 | """Initialize.""" | ||
2557 | 191 | self._text = u"" | ||
2558 | 192 | |||
2559 | 193 | def text(self): | ||
2560 | 194 | """Save text.""" | ||
2561 | 195 | return self._text | ||
2562 | 196 | |||
2563 | 197 | # setText is inherited | ||
2564 | 198 | # pylint: disable=C0103 | ||
2565 | 199 | def setText(self, text): | ||
2566 | 200 | """Return saved text.""" | ||
2567 | 201 | self._text = text | ||
2568 | 202 | |||
2569 | 203 | |||
2570 | 204 | class FakePage(object): | ||
2571 | 205 | |||
2572 | 206 | """A fake wizard page.""" | ||
2573 | 207 | |||
2574 | 208 | app_name = "APP" | ||
2575 | 209 | |||
2576 | 210 | def wizard(self): | ||
2577 | 211 | """Fake wizard.""" | ||
2578 | 212 | return self | ||
2579 | 213 | |||
2580 | 214 | |||
2581 | 215 | class FakeCurrentUserPage(FakePage): | ||
2582 | 216 | |||
2583 | 217 | """Fake CurrentuserPage.""" | ||
2584 | 218 | |||
2585 | 219 | def __init__(self, *args): | ||
2586 | 220 | """Initialize.""" | ||
2587 | 221 | super(FakeCurrentUserPage, self).__init__(*args) | ||
2588 | 222 | self.ui = self | ||
2589 | 223 | self.ui.email_edit = FakeLineEdit() | ||
2590 | 224 | self.ui.password_edit = FakeLineEdit() | ||
2591 | 225 | self.sign_in_button = self | ||
2592 | 226 | self._enabled = False | ||
2593 | 227 | |||
2594 | 228 | # setEnabled is inherited | ||
2595 | 229 | # pylint: disable=C0103 | ||
2596 | 230 | def setEnabled(self, value): | ||
2597 | 231 | """Fake setEnabled.""" | ||
2598 | 232 | self._enabled = value | ||
2599 | 233 | |||
2600 | 234 | def enabled(self): | ||
2601 | 235 | """Fake enabled.""" | ||
2602 | 236 | return self._enabled | ||
2603 | 237 | |||
2604 | 238 | |||
2605 | 239 | class CurrentUserControllerValidationMockTest(MockerTestCase): | ||
2606 | 240 | """Test the choose sign in controller.""" | ||
2607 | 241 | |||
2608 | 242 | def setUp(self): | ||
2609 | 243 | """Set tests.""" | ||
2610 | 244 | super(CurrentUserControllerValidationMockTest, self).setUp() | ||
2611 | 245 | self.view = self.mocker.mock() | ||
2612 | 246 | self.backend = self.mocker.mock() | ||
2613 | 247 | self.controller = CurrentUserController() | ||
2614 | 248 | self.controller.view = self.view | ||
2615 | 249 | self.controller.backend = self.backend | ||
2616 | 250 | self.title = 'title' | ||
2617 | 251 | self.subtitle = 'sub' | ||
2618 | 252 | |||
2619 | 253 | def test_setup_ui(self): | ||
2620 | 254 | """Test the set up of the ui.""" | ||
2621 | 255 | self.controller._title = self.title | ||
2622 | 256 | self.controller._subtitle = self.subtitle | ||
2623 | 257 | self.backend = yield self.controller.get_backend() | ||
2624 | 258 | self.view.header.set_title(self.title) | ||
2625 | 259 | self.view.header.set_subtitle(self.subtitle) | ||
2626 | 260 | self.controller._set_translated_strings() | ||
2627 | 261 | self.mocker.replay() | ||
2628 | 262 | self.controller.setupUi(self.view) | ||
2629 | 263 | |||
2630 | 264 | |||
2631 | 265 | class CurrentUserControllerErrorTestCase(TestCase): | ||
2632 | 266 | |||
2633 | 267 | """Tests for CurrentUserController's error handler.""" | ||
2634 | 268 | |||
2635 | 269 | on_error_method_name = "on_login_error" | ||
2636 | 270 | controller_class = CurrentUserController | ||
2637 | 271 | |||
2638 | 272 | def setUp(self): | ||
2639 | 273 | """Setup test.""" | ||
2640 | 274 | super(CurrentUserControllerErrorTestCase, self).setUp() | ||
2641 | 275 | self.message_box = FakeMessageBox() | ||
2642 | 276 | self.controller = self.controller_class( | ||
2643 | 277 | message_box=self.message_box) | ||
2644 | 278 | self.controller.view = FakePage() | ||
2645 | 279 | self._called = False | ||
2646 | 280 | self.on_error_method = getattr( | ||
2647 | 281 | self.controller, self.on_error_method_name) | ||
2648 | 282 | |||
2649 | 283 | def test_error_message_key(self): | ||
2650 | 284 | """Test that on_login_error reacts to errors with "error_message".""" | ||
2651 | 285 | self.on_error_method({"error_message": "WORRY!"}) | ||
2652 | 286 | self.assertEqual(self.message_box.critical_args, (('WORRY!',), {})) | ||
2653 | 287 | |||
2654 | 288 | def test_message_key(self): | ||
2655 | 289 | """Test that on_login_error reacts to errors with "message".""" | ||
2656 | 290 | self.on_error_method({"message": "WORRY!"}) | ||
2657 | 291 | self.assertEqual(self.message_box.critical_args, (('WORRY!',), {})) | ||
2658 | 292 | |||
2659 | 293 | def test_broken_error(self): | ||
2660 | 294 | """Test that on_login_error reacts to broken errors.""" | ||
2661 | 295 | self.on_error_method({"boo!": "WORRY!"}) | ||
2662 | 296 | self.assertEqual(self.message_box.critical_args, | ||
2663 | 297 | (("Error: {'boo!': 'WORRY!'}",), {})) | ||
2664 | 298 | |||
2665 | 299 | def test_all_and_message(self): | ||
2666 | 300 | """Test that on_login_error reacts to broken errors.""" | ||
2667 | 301 | self.on_error_method( | ||
2668 | 302 | {"message": "WORRY!", "__all__": "MORE!"}) | ||
2669 | 303 | self.assertEqual(self.message_box.critical_args, | ||
2670 | 304 | (('MORE!\nWORRY!',), {})) | ||
2671 | 305 | |||
2672 | 306 | def test_all_and_error_message(self): | ||
2673 | 307 | """Test that on_login_error reacts to broken errors.""" | ||
2674 | 308 | self.on_error_method( | ||
2675 | 309 | {"error_message": "WORRY!", "__all__": "MORE!"}) | ||
2676 | 310 | self.assertEqual(self.message_box.critical_args, | ||
2677 | 311 | (('MORE!\nWORRY!',), {})) | ||
2678 | 312 | |||
2679 | 313 | def test_only_all(self): | ||
2680 | 314 | """Test that on_login_error reacts to broken errors.""" | ||
2681 | 315 | self.on_error_method( | ||
2682 | 316 | {"__all__": "MORE!"}) | ||
2683 | 317 | self.assertEqual(self.message_box.critical_args, | ||
2684 | 318 | (('MORE!',), {})) | ||
2685 | 319 | |||
2686 | 320 | |||
2687 | 321 | class EmailVerificationControllerErrorTestCase( | ||
2688 | 322 | CurrentUserControllerErrorTestCase): | ||
2689 | 323 | |||
2690 | 324 | """Tests for EmailVerificationController's error handler.""" | ||
2691 | 325 | |||
2692 | 326 | on_error_method_name = "on_email_validation_error" | ||
2693 | 327 | controller_class = EmailVerificationController | ||
2694 | 328 | |||
2695 | 329 | def setUp(self): | ||
2696 | 330 | """Setup test.""" | ||
2697 | 331 | super(EmailVerificationControllerErrorTestCase, self).setUp() | ||
2698 | 332 | # This error handler takes one extra argument. | ||
2699 | 333 | self.on_error_method = lambda error: getattr( | ||
2700 | 334 | self.controller, self.on_error_method_name)('APP', error) | ||
2701 | 335 | |||
2702 | 336 | |||
2703 | 337 | class SetUpAccountControllerErrorTestCase( | ||
2704 | 338 | EmailVerificationControllerErrorTestCase): | ||
2705 | 339 | |||
2706 | 340 | """Tests for SetUpAccountController's error handler.""" | ||
2707 | 341 | |||
2708 | 342 | on_error_method_name = "on_user_registration_error" | ||
2709 | 343 | controller_class = SetUpAccountController | ||
2710 | 344 | |||
2711 | 345 | def setUp(self): | ||
2712 | 346 | """Setup test.""" | ||
2713 | 347 | super(SetUpAccountControllerErrorTestCase, self).setUp() | ||
2714 | 348 | self.patch(self.controller, "_refresh_captcha", lambda *args: None) | ||
2715 | 349 | |||
2716 | 350 | |||
2717 | 351 | class ResetPasswordControllerErrorTestCase( | ||
2718 | 352 | EmailVerificationControllerErrorTestCase): | ||
2719 | 353 | |||
2720 | 354 | """Tests for ResetPasswordController's error handler.""" | ||
2721 | 355 | |||
2722 | 356 | on_error_method_name = "on_password_change_error" | ||
2723 | 357 | controller_class = ResetPasswordController | ||
2724 | 358 | |||
2725 | 359 | |||
2726 | 360 | class CurrentUserControllerValidationTest(TestCase): | ||
2727 | 361 | |||
2728 | 362 | """Tests for CurrentUserController, but without Mocker.""" | ||
2729 | 363 | |||
2730 | 364 | def setUp(self): | ||
2731 | 365 | """Setup test.""" | ||
2732 | 366 | super(CurrentUserControllerValidationTest, self).setUp() | ||
2733 | 367 | self.message_box = FakeMessageBox() | ||
2734 | 368 | self.controller = CurrentUserController( | ||
2735 | 369 | message_box=self.message_box) | ||
2736 | 370 | self.controller.view = FakeCurrentUserPage() | ||
2737 | 371 | self._called = False | ||
2738 | 372 | |||
2739 | 373 | def _set_called(self, *args, **kwargs): | ||
2740 | 374 | """Store 'args' and 'kwargs' for test assertions.""" | ||
2741 | 375 | self._called = (args, kwargs) | ||
2742 | 376 | |||
2743 | 377 | def test_valid(self): | ||
2744 | 378 | """Enable the button with a valid email/password.""" | ||
2745 | 379 | self.controller.view.email_edit.setText("a@b") | ||
2746 | 380 | self.controller.view.password_edit.setText("pass") | ||
2747 | 381 | self.controller._validate() | ||
2748 | 382 | self.assertTrue(self.controller.view.sign_in_button.enabled()) | ||
2749 | 383 | |||
2750 | 384 | def test_invalid_email(self): | ||
2751 | 385 | """The submit button should be disabled with an invalid email.""" | ||
2752 | 386 | self.controller.view.email_edit.setText("ab") | ||
2753 | 387 | self.controller.view.password_edit.setText("pass") | ||
2754 | 388 | self.controller._validate() | ||
2755 | 389 | self.assertFalse(self.controller.view.sign_in_button.enabled()) | ||
2756 | 390 | |||
2757 | 391 | def test_invalid_password(self): | ||
2758 | 392 | """The submit button should be disabled with an invalid password.""" | ||
2759 | 393 | self.controller.view.email_edit.setText("a@b") | ||
2760 | 394 | self.controller.view.password_edit.setText("") | ||
2761 | 395 | self.controller._validate() | ||
2762 | 396 | self.assertFalse(self.controller.view.sign_in_button.enabled()) | ||
2763 | 397 | |||
2764 | 398 | def test_invalid_both(self): | ||
2765 | 399 | """The submit button should be disabled with invalid data.""" | ||
2766 | 400 | self.controller.view.email_edit.setText("ab") | ||
2767 | 401 | self.controller.view.password_edit.setText("") | ||
2768 | 402 | self.controller._validate() | ||
2769 | 403 | self.assertFalse(self.controller.view.sign_in_button.enabled()) | ||
2770 | 404 | |||
2771 | 405 | |||
2772 | 169 | class SetUpAccountControllerTestCase(MockerTestCase): | 406 | class SetUpAccountControllerTestCase(MockerTestCase): |
2773 | 170 | """test the controller used to setup a new account.""" | 407 | """test the controller used to setup a new account.""" |
2774 | 171 | 408 | ||
2775 | @@ -204,14 +441,13 @@ | |||
2776 | 204 | 441 | ||
2777 | 205 | def test_set_titles(self): | 442 | def test_set_titles(self): |
2778 | 206 | """Test how the different titles are set.""" | 443 | """Test how the different titles are set.""" |
2782 | 207 | self.view.wizard() | 444 | self.view.wizard().app_name |
2780 | 208 | self.mocker.result(self.view) | ||
2781 | 209 | self.view.app_name | ||
2783 | 210 | self.mocker.result(self.app_name) | 445 | self.mocker.result(self.app_name) |
2785 | 211 | self.view.help_text | 446 | self.view.wizard().help_text |
2786 | 212 | self.mocker.result(self.help) | 447 | self.mocker.result(self.help) |
2789 | 213 | self.view.setTitle(JOIN_HEADER_LABEL % {'app_name': self.app_name}) | 448 | self.view.header.set_title( |
2790 | 214 | self.view.setSubTitle(self.help) | 449 | JOIN_HEADER_LABEL % {'app_name': self.app_name}) |
2791 | 450 | self.view.header.set_subtitle(self.help) | ||
2792 | 215 | self.mocker.replay() | 451 | self.mocker.replay() |
2793 | 216 | self.controller._set_titles() | 452 | self.controller._set_titles() |
2794 | 217 | 453 | ||
2795 | @@ -220,11 +456,17 @@ | |||
2796 | 220 | self.view.ui.terms_button.clicked.connect(self.controller.set_next_tos) | 456 | self.view.ui.terms_button.clicked.connect(self.controller.set_next_tos) |
2797 | 221 | self.view.ui.set_up_button.clicked.connect( | 457 | self.view.ui.set_up_button.clicked.connect( |
2798 | 222 | self.controller.set_next_validation) | 458 | self.controller.set_next_validation) |
2800 | 223 | self.view.ui.set_up_button.setEnabled | 459 | self.controller._enable_setup_button |
2801 | 224 | self.mocker.result(lambda: None) | 460 | self.mocker.result(lambda: None) |
2802 | 461 | self.view.ui.name_edit.textEdited.connect(MATCH(callable)) | ||
2803 | 462 | self.view.ui.email_edit.textEdited.connect(MATCH(callable)) | ||
2804 | 463 | self.view.ui.confirm_email_edit.textEdited.connect(MATCH(callable)) | ||
2805 | 464 | self.view.ui.password_edit.textEdited.connect(MATCH(callable)) | ||
2806 | 465 | self.view.ui.confirm_password_edit.textEdited.connect(MATCH(callable)) | ||
2807 | 466 | self.view.ui.captcha_solution_edit.textEdited.connect(MATCH(callable)) | ||
2808 | 225 | self.view.ui.terms_checkbox.stateChanged.connect(MATCH(callable)) | 467 | self.view.ui.terms_checkbox.stateChanged.connect(MATCH(callable)) |
2809 | 226 | self.view.ui.refresh_label.linkActivated.connect(MATCH(callable)) | 468 | self.view.ui.refresh_label.linkActivated.connect(MATCH(callable)) |
2811 | 227 | # set the callbacks for the captcha generatio | 469 | # set the callbacks for the captcha generation |
2812 | 228 | self.backend.on_captcha_generated_cb = MATCH(callable) | 470 | self.backend.on_captcha_generated_cb = MATCH(callable) |
2813 | 229 | self.backend.on_captcha_generation_error_cb = MATCH(callable) | 471 | self.backend.on_captcha_generation_error_cb = MATCH(callable) |
2814 | 230 | self.backend.on_user_registration_error_cb = MATCH(callable) | 472 | self.backend.on_user_registration_error_cb = MATCH(callable) |
2815 | @@ -309,6 +551,7 @@ | |||
2816 | 309 | captcha_id, captcha_solution) | 551 | captcha_id, captcha_solution) |
2817 | 310 | self.view.wizard().email_verification_page_id | 552 | self.view.wizard().email_verification_page_id |
2818 | 311 | self.view.wizard().page(None).controller.set_titles() | 553 | self.view.wizard().page(None).controller.set_titles() |
2819 | 554 | self.view.ui.captcha_solution_edit.text() | ||
2820 | 312 | self.mocker.replay() | 555 | self.mocker.replay() |
2821 | 313 | self.controller.set_next_validation() | 556 | self.controller.set_next_validation() |
2822 | 314 | 557 | ||
2823 | @@ -316,8 +559,7 @@ | |||
2824 | 316 | """Test the callback when there is a wrong email.""" | 559 | """Test the callback when there is a wrong email.""" |
2825 | 317 | email = 'email@example.com' | 560 | email = 'email@example.com' |
2826 | 318 | password = 'Qwerty9923' | 561 | password = 'Qwerty9923' |
2829 | 319 | self.view.wizard().app_name | 562 | captcha_solution = 'captcha' |
2828 | 320 | self.mocker.result(self.app_name) | ||
2830 | 321 | self.view.ui.email_edit.text() | 563 | self.view.ui.email_edit.text() |
2831 | 322 | self.mocker.result(email) | 564 | self.mocker.result(email) |
2832 | 323 | self.view.ui.confirm_email_edit.text() | 565 | self.view.ui.confirm_email_edit.text() |
2833 | @@ -326,7 +568,9 @@ | |||
2834 | 326 | self.mocker.result(password) | 568 | self.mocker.result(password) |
2835 | 327 | self.view.ui.confirm_password_edit.text() | 569 | self.view.ui.confirm_password_edit.text() |
2836 | 328 | self.mocker.result(password) | 570 | self.mocker.result(password) |
2838 | 329 | self.message_box.critical(self.view, self.app_name, EMAIL_MISMATCH) | 571 | self.view.ui.captcha_solution_edit.text() |
2839 | 572 | self.mocker.result(captcha_solution) | ||
2840 | 573 | self.message_box.critical(EMAIL_MISMATCH) | ||
2841 | 330 | self.mocker.replay() | 574 | self.mocker.replay() |
2842 | 331 | self.assertFalse(self.controller.validate_form()) | 575 | self.assertFalse(self.controller.validate_form()) |
2843 | 332 | 576 | ||
2844 | @@ -334,17 +578,18 @@ | |||
2845 | 334 | """Test the callback with a weak password.""" | 578 | """Test the callback with a weak password.""" |
2846 | 335 | weak_password = 'weak' | 579 | weak_password = 'weak' |
2847 | 336 | email = 'email@example.com' | 580 | email = 'email@example.com' |
2850 | 337 | self.view.wizard().app_name | 581 | captcha_solution = 'captcha' |
2849 | 338 | self.mocker.result(self.app_name) | ||
2851 | 339 | self.view.ui.email_edit.text() | 582 | self.view.ui.email_edit.text() |
2852 | 340 | self.mocker.result(email) | 583 | self.mocker.result(email) |
2853 | 341 | self.view.ui.confirm_email_edit.text() | 584 | self.view.ui.confirm_email_edit.text() |
2854 | 342 | self.mocker.result(email) | 585 | self.mocker.result(email) |
2855 | 343 | self.view.ui.password_edit.text() | 586 | self.view.ui.password_edit.text() |
2856 | 344 | self.mocker.result(weak_password) | 587 | self.mocker.result(weak_password) |
2857 | 588 | self.view.ui.captcha_solution_edit.text() | ||
2858 | 589 | self.mocker.result(captcha_solution) | ||
2859 | 345 | self.view.ui.confirm_password_edit.text() | 590 | self.view.ui.confirm_password_edit.text() |
2860 | 346 | self.mocker.result(weak_password) | 591 | self.mocker.result(weak_password) |
2862 | 347 | self.message_box.critical(self.view, self.app_name, PASSWORD_TOO_WEAK) | 592 | self.message_box.critical(PASSWORD_TOO_WEAK) |
2863 | 348 | self.mocker.replay() | 593 | self.mocker.replay() |
2864 | 349 | self.assertFalse(self.controller.validate_form()) | 594 | self.assertFalse(self.controller.validate_form()) |
2865 | 350 | 595 | ||
2866 | @@ -352,8 +597,7 @@ | |||
2867 | 352 | """Test the callback where the password is wrong.""" | 597 | """Test the callback where the password is wrong.""" |
2868 | 353 | password = 'Qwerty9923' | 598 | password = 'Qwerty9923' |
2869 | 354 | email = 'email@example.com' | 599 | email = 'email@example.com' |
2872 | 355 | self.view.wizard().app_name | 600 | captcha_solution = 'captcha' |
2871 | 356 | self.mocker.result(self.app_name) | ||
2873 | 357 | self.view.ui.email_edit.text() | 601 | self.view.ui.email_edit.text() |
2874 | 358 | self.mocker.result(email) | 602 | self.mocker.result(email) |
2875 | 359 | self.view.ui.confirm_email_edit.text() | 603 | self.view.ui.confirm_email_edit.text() |
2876 | @@ -362,7 +606,28 @@ | |||
2877 | 362 | self.mocker.result(password) | 606 | self.mocker.result(password) |
2878 | 363 | self.view.ui.confirm_password_edit.text() | 607 | self.view.ui.confirm_password_edit.text() |
2879 | 364 | self.mocker.result('other_password') | 608 | self.mocker.result('other_password') |
2881 | 365 | self.message_box.critical(self.view, self.app_name, PASSWORD_MISMATCH) | 609 | self.view.ui.captcha_solution_edit.text() |
2882 | 610 | self.mocker.result(captcha_solution) | ||
2883 | 611 | self.message_box.critical(PASSWORD_MISMATCH) | ||
2884 | 612 | self.mocker.replay() | ||
2885 | 613 | self.assertFalse(self.controller.validate_form()) | ||
2886 | 614 | |||
2887 | 615 | def test_set_next_validation_empty_captcha(self): | ||
2888 | 616 | """Test the callback where the password is wrong.""" | ||
2889 | 617 | password = 'Qwerty9923' | ||
2890 | 618 | email = 'email@example.com' | ||
2891 | 619 | captcha_solution = '' | ||
2892 | 620 | self.view.ui.email_edit.text() | ||
2893 | 621 | self.mocker.result(email) | ||
2894 | 622 | self.view.ui.confirm_email_edit.text() | ||
2895 | 623 | self.mocker.result(email) | ||
2896 | 624 | self.view.ui.password_edit.text() | ||
2897 | 625 | self.mocker.result(password) | ||
2898 | 626 | self.view.ui.confirm_password_edit.text() | ||
2899 | 627 | self.mocker.result(password) | ||
2900 | 628 | self.view.ui.captcha_solution_edit.text() | ||
2901 | 629 | self.mocker.result(captcha_solution) | ||
2902 | 630 | self.message_box.critical(CAPTCHA_REQUIRED_ERROR) | ||
2903 | 366 | self.mocker.replay() | 631 | self.mocker.replay() |
2904 | 367 | self.assertFalse(self.controller.validate_form()) | 632 | self.assertFalse(self.controller.validate_form()) |
2905 | 368 | 633 | ||
2906 | @@ -408,7 +673,7 @@ | |||
2907 | 408 | 673 | ||
2908 | 409 | class FakeView(object): | 674 | class FakeView(object): |
2909 | 410 | 675 | ||
2911 | 411 | """A fake view""" | 676 | """A fake view.""" |
2912 | 412 | 677 | ||
2913 | 413 | app_name = "TestApp" | 678 | app_name = "TestApp" |
2914 | 414 | 679 | ||
2915 | @@ -417,12 +682,13 @@ | |||
2916 | 417 | return self | 682 | return self |
2917 | 418 | 683 | ||
2918 | 419 | 684 | ||
2920 | 420 | class SetupAccountControllerTest2(TestCase): | 685 | class SetupAccountControllerValidationTest(TestCase): |
2921 | 421 | 686 | ||
2923 | 422 | """Tests for SetupAccountController, but without Mocker""" | 687 | """Tests for SetupAccountController, but without Mocker.""" |
2924 | 423 | 688 | ||
2925 | 424 | def setUp(self): | 689 | def setUp(self): |
2927 | 425 | super(SetupAccountControllerTest2, self).setUp() | 690 | """Set the different tests.""" |
2928 | 691 | super(SetupAccountControllerValidationTest, self).setUp() | ||
2929 | 426 | self.message_box = FakeMessageBox() | 692 | self.message_box = FakeMessageBox() |
2930 | 427 | self.controller = SetUpAccountController(message_box=self.message_box) | 693 | self.controller = SetUpAccountController(message_box=self.message_box) |
2931 | 428 | self.patch(self.controller, '_refresh_captcha', self._set_called) | 694 | self.patch(self.controller, '_refresh_captcha', self._set_called) |
2932 | @@ -443,9 +709,7 @@ | |||
2933 | 443 | self.controller.on_user_registration_error('TestApp', | 709 | self.controller.on_user_registration_error('TestApp', |
2934 | 444 | {'__all__': "Error in All"}) | 710 | {'__all__': "Error in All"}) |
2935 | 445 | self.assertEqual(self.message_box.critical_args, (( | 711 | self.assertEqual(self.message_box.critical_args, (( |
2939 | 446 | self.controller.view, | 712 | "Error in All", ), {})) |
2937 | 447 | self.controller.view.app_name, | ||
2938 | 448 | "Error in All"), {})) | ||
2940 | 449 | 713 | ||
2941 | 450 | def test_on_user_registration_all_fields(self): | 714 | def test_on_user_registration_all_fields(self): |
2942 | 451 | """Pass all known error keys, plus unknown one.""" | 715 | """Pass all known error keys, plus unknown one.""" |
2943 | @@ -456,11 +720,7 @@ | |||
2944 | 456 | 'unknownfield': "Error in unknown", | 720 | 'unknownfield': "Error in unknown", |
2945 | 457 | }) | 721 | }) |
2946 | 458 | self.assertEqual(self.message_box.critical_args, (( | 722 | self.assertEqual(self.message_box.critical_args, (( |
2952 | 459 | self.controller.view, | 723 | "Error in All", ), {})) |
2948 | 460 | self.controller.view.app_name, | ||
2949 | 461 | "Error in All\nError in email\n" | ||
2950 | 462 | "Error in password\nError in unknown", | ||
2951 | 463 | ), {})) | ||
2953 | 464 | 724 | ||
2954 | 465 | 725 | ||
2955 | 466 | class TosControllerTestCase(MockerTestCase): | 726 | class TosControllerTestCase(MockerTestCase): |
2956 | @@ -481,8 +741,8 @@ | |||
2957 | 481 | 741 | ||
2958 | 482 | def test_setup_ui(self): | 742 | def test_setup_ui(self): |
2959 | 483 | """Test the set up of the ui.""" | 743 | """Test the set up of the ui.""" |
2962 | 484 | self.view.setTitle(self.title) | 744 | self.view.header.set_title(self.title) |
2963 | 485 | self.view.setSubTitle(self.subtitle) | 745 | self.view.header.set_subtitle(self.subtitle) |
2964 | 486 | self.view.ui.terms_webkit.load(ANY) | 746 | self.view.ui.terms_webkit.load(ANY) |
2965 | 487 | self.view.ui.tos_link_label.setText( | 747 | self.view.ui.tos_link_label.setText( |
2966 | 488 | TOS_LABEL % | 748 | TOS_LABEL % |
2967 | @@ -499,7 +759,8 @@ | |||
2968 | 499 | super(EmailVerificationControllerTestCase, self).setUp() | 759 | super(EmailVerificationControllerTestCase, self).setUp() |
2969 | 500 | self.view = self.mocker.mock() | 760 | self.view = self.mocker.mock() |
2970 | 501 | self.backend = self.mocker.mock() | 761 | self.backend = self.mocker.mock() |
2972 | 502 | self.controller = EmailVerificationController() | 762 | self.controller = EmailVerificationController( |
2973 | 763 | message_box=self.mocker.mock()) | ||
2974 | 503 | self.controller.view = self.view | 764 | self.controller.view = self.view |
2975 | 504 | self.controller.backend = self.backend | 765 | self.controller.backend = self.backend |
2976 | 505 | 766 | ||
2977 | @@ -521,15 +782,17 @@ | |||
2978 | 521 | 782 | ||
2979 | 522 | def test_set_titles(self): | 783 | def test_set_titles(self): |
2980 | 523 | """Test that the titles are set.""" | 784 | """Test that the titles are set.""" |
2985 | 524 | self.view.setTitle(VERIFY_EMAIL_TITLE) | 785 | self.view.header.set_title(VERIFY_EMAIL_CONTENT) |
2986 | 525 | self.view.wizard().app_name | 786 | self.view.header.set_subtitle(VERIFY_EMAIL_CONTENT % { |
2983 | 526 | self.view.wizard().field("email_address").toString() | ||
2984 | 527 | self.view.setSubTitle(VERIFY_EMAIL_CONTENT % { | ||
2987 | 528 | "app_name": None, | 787 | "app_name": None, |
2988 | 529 | "email": None, | 788 | "email": None, |
2989 | 530 | }) | 789 | }) |
2990 | 531 | self.mocker.replay() | 790 | self.mocker.replay() |
2992 | 532 | self.controller._set_titles() | 791 | self.view.header.set_title(VERIFY_EMAIL_CONTENT) |
2993 | 792 | self.view.header.set_subtitle(VERIFY_EMAIL_CONTENT % { | ||
2994 | 793 | "app_name": None, | ||
2995 | 794 | "email": None, | ||
2996 | 795 | }) | ||
2997 | 533 | 796 | ||
2998 | 534 | def test_validate_email(self): | 797 | def test_validate_email(self): |
2999 | 535 | """Test the callback.""" | 798 | """Test the callback.""" |
3000 | @@ -550,6 +813,27 @@ | |||
3001 | 550 | self.controller.validate_email() | 813 | self.controller.validate_email() |
3002 | 551 | 814 | ||
3003 | 552 | 815 | ||
3004 | 816 | class EmailVerificationControllerValidationTestCase(TestCase): | ||
3005 | 817 | """Tests for EmailVerificationController, but without Mocker.""" | ||
3006 | 818 | |||
3007 | 819 | def setUp(self): | ||
3008 | 820 | """Set the different tests.""" | ||
3009 | 821 | super(EmailVerificationControllerValidationTestCase, self).setUp() | ||
3010 | 822 | self.message_box = FakeMessageBox() | ||
3011 | 823 | self.controller = EmailVerificationController( | ||
3012 | 824 | message_box=self.message_box) | ||
3013 | 825 | self.patch(self.controller, 'view', FakeView()) | ||
3014 | 826 | self._called = False | ||
3015 | 827 | |||
3016 | 828 | def test_on_email_validation_error(self): | ||
3017 | 829 | """Test that on_email_validation_error callback works as expected.""" | ||
3018 | 830 | error = dict(errtype='BadTokenError') | ||
3019 | 831 | app_name = 'app_name' | ||
3020 | 832 | self.controller.on_email_validation_error(app_name, error) | ||
3021 | 833 | self.assertEqual(self.message_box.critical_args, | ||
3022 | 834 | (("Error: {'errtype': 'BadTokenError'}",), {})) | ||
3023 | 835 | |||
3024 | 836 | |||
3025 | 553 | class ErrorControllerTestCase(MockerTestCase): | 837 | class ErrorControllerTestCase(MockerTestCase): |
3026 | 554 | """Test the success page controller.""" | 838 | """Test the success page controller.""" |
3027 | 555 | 839 | ||
3028 | @@ -564,10 +848,21 @@ | |||
3029 | 564 | 848 | ||
3030 | 565 | def test_set_ui(self): | 849 | def test_set_ui(self): |
3031 | 566 | """Test the process that sets the ui.""" | 850 | """Test the process that sets the ui.""" |
3036 | 567 | self.view.next = -1 | 851 | self.controller._title = ERROR |
3037 | 568 | self.view.ui.error_message_label | 852 | self.controller._subtitle = ERROR |
3038 | 569 | self.mocker.result(self.view) | 853 | self.view.next = -1 |
3039 | 570 | self.view.setText(ERROR) | 854 | self.view.ui.error_message_label.setText(ERROR) |
3040 | 855 | self.view.header.set_title(ERROR) | ||
3041 | 856 | self.view.header.set_subtitle(ERROR) | ||
3042 | 857 | self.mocker.replay() | ||
3043 | 858 | self.controller.setupUi(self.view) | ||
3044 | 859 | |||
3045 | 860 | def test_hide_titles(self): | ||
3046 | 861 | """Test how the different titles are set.""" | ||
3047 | 862 | self.view.next = -1 | ||
3048 | 863 | self.view.ui.error_message_label.setText(ERROR) | ||
3049 | 864 | self.view.header.set_title('') | ||
3050 | 865 | self.view.header.set_subtitle('') | ||
3051 | 571 | self.mocker.replay() | 866 | self.mocker.replay() |
3052 | 572 | self.controller.setupUi(self.view) | 867 | self.controller.setupUi(self.view) |
3053 | 573 | 868 | ||
3054 | @@ -586,10 +881,21 @@ | |||
3055 | 586 | 881 | ||
3056 | 587 | def test_set_ui(self): | 882 | def test_set_ui(self): |
3057 | 588 | """Test the process that sets the ui.""" | 883 | """Test the process that sets the ui.""" |
3062 | 589 | self.view.next = -1 | 884 | self.controller._title = SUCCESS |
3063 | 590 | self.view.ui.success_message_label | 885 | self.controller._subtitle = SUCCESS |
3064 | 591 | self.mocker.result(self.view) | 886 | self.view.next = -1 |
3065 | 592 | self.view.setText(SUCCESS) | 887 | self.view.ui.success_message_label.setText(SUCCESS) |
3066 | 888 | self.view.header.set_title(SUCCESS) | ||
3067 | 889 | self.view.header.set_subtitle(SUCCESS) | ||
3068 | 890 | self.mocker.replay() | ||
3069 | 891 | self.controller.setupUi(self.view) | ||
3070 | 892 | |||
3071 | 893 | def test_hide_titles(self): | ||
3072 | 894 | """Test how the different titles are set.""" | ||
3073 | 895 | self.view.next = -1 | ||
3074 | 896 | self.view.ui.success_message_label.setText(SUCCESS) | ||
3075 | 897 | self.view.header.set_title('') | ||
3076 | 898 | self.view.header.set_subtitle('') | ||
3077 | 593 | self.mocker.replay() | 899 | self.mocker.replay() |
3078 | 594 | self.controller.setupUi(self.view) | 900 | self.controller.setupUi(self.view) |
3079 | 595 | 901 | ||
3080 | @@ -683,6 +989,75 @@ | |||
3081 | 683 | self.controller.setupUi(self.view) | 989 | self.controller.setupUi(self.view) |
3082 | 684 | 990 | ||
3083 | 685 | 991 | ||
3084 | 992 | class FakeForgottenPasswordPage(FakeView): | ||
3085 | 993 | """Fake the page.""" | ||
3086 | 994 | |||
3087 | 995 | def __init__(self): | ||
3088 | 996 | self.email_address_line_edit = self | ||
3089 | 997 | self.send_button = self | ||
3090 | 998 | self._text = "" | ||
3091 | 999 | self._enabled = False | ||
3092 | 1000 | super(FakeForgottenPasswordPage, self).__init__() | ||
3093 | 1001 | |||
3094 | 1002 | def text(self): | ||
3095 | 1003 | """Return text.""" | ||
3096 | 1004 | return self._text | ||
3097 | 1005 | |||
3098 | 1006 | # setText, setEnabled are inherited | ||
3099 | 1007 | # pylint: disable=C0103 | ||
3100 | 1008 | def setText(self, text): | ||
3101 | 1009 | """Save text.""" | ||
3102 | 1010 | self._text = text | ||
3103 | 1011 | |||
3104 | 1012 | def setEnabled(self, value): | ||
3105 | 1013 | """Fake setEnabled.""" | ||
3106 | 1014 | self._enabled = value | ||
3107 | 1015 | |||
3108 | 1016 | def enabled(self): | ||
3109 | 1017 | """Fake enabled.""" | ||
3110 | 1018 | return self._enabled | ||
3111 | 1019 | |||
3112 | 1020 | |||
3113 | 1021 | class ForgottenPasswordControllerValidationTest(TestCase): | ||
3114 | 1022 | |||
3115 | 1023 | """Tests for ForgottenPasswordController, but without Mocker.""" | ||
3116 | 1024 | |||
3117 | 1025 | def setUp(self): | ||
3118 | 1026 | """Set the different tests.""" | ||
3119 | 1027 | super(ForgottenPasswordControllerValidationTest, self).setUp() | ||
3120 | 1028 | self.message_box = FakeMessageBox() | ||
3121 | 1029 | self.controller = ForgottenPasswordController( | ||
3122 | 1030 | message_box=self.message_box) | ||
3123 | 1031 | self.controller.view = FakeForgottenPasswordPage() | ||
3124 | 1032 | self._called = False | ||
3125 | 1033 | |||
3126 | 1034 | def _set_called(self, *args, **kwargs): | ||
3127 | 1035 | """Store 'args' and 'kwargs' for test assertions.""" | ||
3128 | 1036 | self._called = (args, kwargs) | ||
3129 | 1037 | |||
3130 | 1038 | def test_valid(self): | ||
3131 | 1039 | """The submit button should be enabled with a valid email.""" | ||
3132 | 1040 | self.controller.view.email_address_line_edit.setText("a@b") | ||
3133 | 1041 | self.assertNotEqual(unicode( | ||
3134 | 1042 | self.controller.view.email_address_line_edit.text()), u"") | ||
3135 | 1043 | self.controller._validate() | ||
3136 | 1044 | self.assertTrue(self.controller.view.send_button.enabled()) | ||
3137 | 1045 | |||
3138 | 1046 | def test_invalid(self): | ||
3139 | 1047 | """The submit button should be disabled with an invalid email.""" | ||
3140 | 1048 | self.controller.view.email_address_line_edit.setText("ab") | ||
3141 | 1049 | self.assertNotEqual( | ||
3142 | 1050 | unicode(self.controller.view.email_address_line_edit.text()), u"") | ||
3143 | 1051 | self.controller._validate() | ||
3144 | 1052 | self.assertFalse(self.controller.view.send_button.enabled()) | ||
3145 | 1053 | |||
3146 | 1054 | def test_empty(self): | ||
3147 | 1055 | """The submit button should be disabled without email.""" | ||
3148 | 1056 | self.assertEqual( | ||
3149 | 1057 | unicode(self.controller.view.email_address_line_edit.text()), u"") | ||
3150 | 1058 | self.assertFalse(self.controller.view.send_button.enabled()) | ||
3151 | 1059 | |||
3152 | 1060 | |||
3153 | 686 | class ForgottenPasswordControllerTestCase(MockerTestCase): | 1061 | class ForgottenPasswordControllerTestCase(MockerTestCase): |
3154 | 687 | """Test the controller of the fogotten password page.""" | 1062 | """Test the controller of the fogotten password page.""" |
3155 | 688 | 1063 | ||
3156 | @@ -729,6 +1104,7 @@ | |||
3157 | 729 | 1104 | ||
3158 | 730 | def test_connect_ui(self): | 1105 | def test_connect_ui(self): |
3159 | 731 | """Test that the correct ui signals are connected.""" | 1106 | """Test that the correct ui signals are connected.""" |
3160 | 1107 | self.view.email_address_line_edit.textChanged.connect(MATCH(callable)) | ||
3161 | 732 | self.view.send_button.clicked.connect(MATCH(callable)) | 1108 | self.view.send_button.clicked.connect(MATCH(callable)) |
3162 | 733 | self.view.try_again_button.clicked.connect( | 1109 | self.view.try_again_button.clicked.connect( |
3163 | 734 | self.controller.on_try_again) | 1110 | self.controller.on_try_again) |
3164 | @@ -789,6 +1165,7 @@ | |||
3165 | 789 | 1165 | ||
3166 | 790 | def test_set_translated_strings(self): | 1166 | def test_set_translated_strings(self): |
3167 | 791 | """Ensure that the correct strings are set.""" | 1167 | """Ensure that the correct strings are set.""" |
3168 | 1168 | self.controller._subtitle = PASSWORD_HELP | ||
3169 | 792 | self.view.ui.reset_code_line_edit.setPlaceholderText(RESET_CODE_ENTRY) | 1169 | self.view.ui.reset_code_line_edit.setPlaceholderText(RESET_CODE_ENTRY) |
3170 | 793 | self.view.ui.password_line_edit.setPlaceholderText(PASSWORD1_ENTRY) | 1170 | self.view.ui.password_line_edit.setPlaceholderText(PASSWORD1_ENTRY) |
3171 | 794 | self.view.ui.confirm_password_line_edit.setPlaceholderText( | 1171 | self.view.ui.confirm_password_line_edit.setPlaceholderText( |
3172 | @@ -806,6 +1183,13 @@ | |||
3173 | 806 | self.controller.on_password_changed | 1183 | self.controller.on_password_changed |
3174 | 807 | self.backend.on_password_change_error_cb = \ | 1184 | self.backend.on_password_change_error_cb = \ |
3175 | 808 | self.controller.on_password_change_error | 1185 | self.controller.on_password_change_error |
3176 | 1186 | self.view.ui.reset_code_line_edit.textChanged.connect( | ||
3177 | 1187 | MATCH(callable)) | ||
3178 | 1188 | self.view.ui.password_line_edit.textChanged.connect( | ||
3179 | 1189 | MATCH(callable)) | ||
3180 | 1190 | self.view.ui.confirm_password_line_edit.textChanged.connect( | ||
3181 | 1191 | MATCH(callable)) | ||
3182 | 1192 | |||
3183 | 809 | self.mocker.replay() | 1193 | self.mocker.replay() |
3184 | 810 | self.controller._connect_ui() | 1194 | self.controller._connect_ui() |
3185 | 811 | 1195 | ||
3186 | @@ -861,3 +1245,75 @@ | |||
3187 | 861 | self.mocker.replay() | 1245 | self.mocker.replay() |
3188 | 862 | self.assertFalse(self.controller.is_correct_password_confirmation( | 1246 | self.assertFalse(self.controller.is_correct_password_confirmation( |
3189 | 863 | password)) | 1247 | password)) |
3190 | 1248 | |||
3191 | 1249 | |||
3192 | 1250 | class FakeResetPasswordPage(object): | ||
3193 | 1251 | |||
3194 | 1252 | """Fake ResetPasswordPage.""" | ||
3195 | 1253 | |||
3196 | 1254 | def __init__(self, *args): | ||
3197 | 1255 | """Initialize.""" | ||
3198 | 1256 | self.ui = self | ||
3199 | 1257 | self.ui.reset_code_line_edit = FakeLineEdit() | ||
3200 | 1258 | self.ui.password_line_edit = FakeLineEdit() | ||
3201 | 1259 | self.ui.confirm_password_line_edit = FakeLineEdit() | ||
3202 | 1260 | self.reset_password_button = self | ||
3203 | 1261 | self._enabled = 9 # Intentionally wrong. | ||
3204 | 1262 | |||
3205 | 1263 | # setEnabled is inherited | ||
3206 | 1264 | # pylint: disable=C0103 | ||
3207 | 1265 | def setEnabled(self, value): | ||
3208 | 1266 | """Fake setEnabled.""" | ||
3209 | 1267 | self._enabled = value | ||
3210 | 1268 | |||
3211 | 1269 | def enabled(self): | ||
3212 | 1270 | """Fake enabled.""" | ||
3213 | 1271 | return self._enabled | ||
3214 | 1272 | |||
3215 | 1273 | |||
3216 | 1274 | class ResetPasswordControllerValidationTest(TestCase): | ||
3217 | 1275 | |||
3218 | 1276 | """Tests for ResetPasswordController, but without Mocker.""" | ||
3219 | 1277 | |||
3220 | 1278 | def setUp(self): | ||
3221 | 1279 | """Setup test.""" | ||
3222 | 1280 | super(ResetPasswordControllerValidationTest, self).setUp() | ||
3223 | 1281 | self.controller = ResetPasswordController() | ||
3224 | 1282 | self.controller.view = FakeResetPasswordPage() | ||
3225 | 1283 | self._called = False | ||
3226 | 1284 | |||
3227 | 1285 | def _set_called(self, *args, **kwargs): | ||
3228 | 1286 | """Store 'args' and 'kwargs' for test assertions.""" | ||
3229 | 1287 | self._called = (args, kwargs) | ||
3230 | 1288 | |||
3231 | 1289 | def test_valid(self): | ||
3232 | 1290 | """Enable the button with valid data.""" | ||
3233 | 1291 | self.controller.view.reset_code_line_edit.setText("ABCD") | ||
3234 | 1292 | self.controller.view.password_line_edit.setText("1234567A") | ||
3235 | 1293 | self.controller.view.confirm_password_line_edit.setText("1234567A") | ||
3236 | 1294 | self.controller._validate() | ||
3237 | 1295 | self.assertTrue(self.controller.view.reset_password_button.enabled()) | ||
3238 | 1296 | |||
3239 | 1297 | def test_invalid_code(self): | ||
3240 | 1298 | """Disable the button with an invalid code.""" | ||
3241 | 1299 | self.controller.view.reset_code_line_edit.setText("") | ||
3242 | 1300 | self.controller.view.password_line_edit.setText("1234567A") | ||
3243 | 1301 | self.controller.view.confirm_password_line_edit.setText("1234567A") | ||
3244 | 1302 | self.controller._validate() | ||
3245 | 1303 | self.assertFalse(self.controller.view.reset_password_button.enabled()) | ||
3246 | 1304 | |||
3247 | 1305 | def test_invalid_password(self): | ||
3248 | 1306 | """Disable the button with an invalid password.""" | ||
3249 | 1307 | self.controller.view.reset_code_line_edit.setText("") | ||
3250 | 1308 | self.controller.view.password_line_edit.setText("1234567") | ||
3251 | 1309 | self.controller.view.confirm_password_line_edit.setText("1234567") | ||
3252 | 1310 | self.controller._validate() | ||
3253 | 1311 | self.assertFalse(self.controller.view.reset_password_button.enabled()) | ||
3254 | 1312 | |||
3255 | 1313 | def test_invalid_confirm(self): | ||
3256 | 1314 | """Disable the button with an invalid password confirm.""" | ||
3257 | 1315 | self.controller.view.reset_code_line_edit.setText("") | ||
3258 | 1316 | self.controller.view.password_line_edit.setText("1234567A") | ||
3259 | 1317 | self.controller.view.confirm_password_line_edit.setText("1234567") | ||
3260 | 1318 | self.controller._validate() | ||
3261 | 1319 | self.assertFalse(self.controller.view.reset_password_button.enabled()) | ||
3262 | 864 | 1320 | ||
3263 | === modified file 'ubuntu_sso/tests/__init__.py' | |||
3264 | --- ubuntu_sso/tests/__init__.py 2011-01-12 18:56:56 +0000 | |||
3265 | +++ ubuntu_sso/tests/__init__.py 2011-08-25 19:16:19 +0000 | |||
3266 | @@ -22,30 +22,30 @@ | |||
3267 | 22 | 22 | ||
3268 | 23 | from ubuntu_sso.keyring import get_token_name | 23 | from ubuntu_sso.keyring import get_token_name |
3269 | 24 | 24 | ||
3272 | 25 | APP_NAME = 'The Super App!' | 25 | APP_NAME = u'The Super App!' |
3273 | 26 | CAPTCHA_ID = 'test' | 26 | CAPTCHA_ID = u'test' |
3274 | 27 | CAPTCHA_PATH = os.path.abspath(os.path.join(os.curdir, 'ubuntu_sso', 'tests', | 27 | CAPTCHA_PATH = os.path.abspath(os.path.join(os.curdir, 'ubuntu_sso', 'tests', |
3275 | 28 | 'files', 'captcha.png')) | 28 | 'files', 'captcha.png')) |
3279 | 29 | CAPTCHA_SOLUTION = 'william Byrd' | 29 | CAPTCHA_SOLUTION = u'william Byrd' |
3280 | 30 | EMAIL = 'test@example.com' | 30 | EMAIL = u'test@example.com' |
3281 | 31 | EMAIL_TOKEN = 'B2Pgtf' | 31 | EMAIL_TOKEN = u'B2Pgtf' |
3282 | 32 | GTK_GUI_CLASS = 'UbuntuSSOClientGUI' | 32 | GTK_GUI_CLASS = 'UbuntuSSOClientGUI' |
3283 | 33 | GTK_GUI_MODULE = 'ubuntu_sso.gtk.gui' | 33 | GTK_GUI_MODULE = 'ubuntu_sso.gtk.gui' |
3284 | 34 | HELP_TEXT = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sed | 34 | HELP_TEXT = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sed |
3285 | 35 | lorem nibh. Suspendisse gravida nulla non nunc suscipit pulvinar tempus ut | 35 | lorem nibh. Suspendisse gravida nulla non nunc suscipit pulvinar tempus ut |
3286 | 36 | augue. Morbi consequat, ligula a elementum pretium, dolor nulla tempus metus, | 36 | augue. Morbi consequat, ligula a elementum pretium, dolor nulla tempus metus, |
3287 | 37 | sed viverra nisi risus non velit.""" | 37 | sed viverra nisi risus non velit.""" |
3292 | 38 | NAME = 'Juanito Pérez' | 38 | NAME = u'Juanito Pérez' |
3293 | 39 | PASSWORD = 'h3lloWorld' | 39 | PASSWORD = u'h3lloWorld' |
3294 | 40 | PING_URL = 'http://localhost/ping-me/' | 40 | PING_URL = u'http://localhost/ping-me/' |
3295 | 41 | RESET_PASSWORD_TOKEN = '8G5Wtq' | 41 | RESET_PASSWORD_TOKEN = u'8G5Wtq' |
3296 | 42 | TOKEN = {u'consumer_key': u'xQ7xDAz', | 42 | TOKEN = {u'consumer_key': u'xQ7xDAz', |
3297 | 43 | u'consumer_secret': u'KzCJWCTNbbntwfyCKKjomJDzlgqxLy', | 43 | u'consumer_secret': u'KzCJWCTNbbntwfyCKKjomJDzlgqxLy', |
3298 | 44 | u'token_name': u'test', | 44 | u'token_name': u'test', |
3299 | 45 | u'token': u'GkInOfSMGwTXAUoVQwLUoPxElEEUdhsLVNTPhxHJDUIeHCPNEo', | 45 | u'token': u'GkInOfSMGwTXAUoVQwLUoPxElEEUdhsLVNTPhxHJDUIeHCPNEo', |
3300 | 46 | u'token_secret': u'qFYImEtlczPbsCnYyuwLoPDlPEnvNcIktZphPQklAWrvyfFMV'} | 46 | u'token_secret': u'qFYImEtlczPbsCnYyuwLoPDlPEnvNcIktZphPQklAWrvyfFMV'} |
3301 | 47 | TOKEN_NAME = get_token_name(APP_NAME) | 47 | TOKEN_NAME = get_token_name(APP_NAME) |
3303 | 48 | TC_URL = 'http://localhost/' | 48 | TC_URL = u'http://localhost/' |
3304 | 49 | WINDOW_ID = 5 | 49 | WINDOW_ID = 5 |
3305 | 50 | 50 | ||
3306 | 51 | 51 | ||
3307 | 52 | 52 | ||
3308 | === modified file 'ubuntu_sso/tests/test_account.py' | |||
3309 | --- ubuntu_sso/tests/test_account.py 2011-07-22 20:12:20 +0000 | |||
3310 | +++ ubuntu_sso/tests/test_account.py 2011-08-25 19:16:19 +0000 | |||
3311 | @@ -50,9 +50,11 @@ | |||
3312 | 50 | class FakedCaptchas(object): | 50 | class FakedCaptchas(object): |
3313 | 51 | """Fake the captcha generator.""" | 51 | """Fake the captcha generator.""" |
3314 | 52 | 52 | ||
3315 | 53 | image_uri = 'file://localhost/%s' % CAPTCHA_PATH.replace(os.path.sep, '/') | ||
3316 | 54 | |||
3317 | 53 | def new(self): | 55 | def new(self): |
3318 | 54 | """Return a local fake captcha.""" | 56 | """Return a local fake captcha.""" |
3320 | 55 | return {'image_url': 'file://%s' % CAPTCHA_PATH, | 57 | return {'image_url': self.image_uri, |
3321 | 56 | 'captcha_id': CAPTCHA_ID} | 58 | 'captcha_id': CAPTCHA_ID} |
3322 | 57 | 59 | ||
3323 | 58 | 60 | ||
3324 | @@ -162,7 +164,8 @@ | |||
3325 | 162 | def test_generate_captcha(self): | 164 | def test_generate_captcha(self): |
3326 | 163 | """Captcha can be generated.""" | 165 | """Captcha can be generated.""" |
3327 | 164 | filename = self.mktemp() | 166 | filename = self.mktemp() |
3329 | 165 | self.addCleanup(lambda: os.remove(filename)) | 167 | self.addCleanup(lambda: os.remove(filename) |
3330 | 168 | if os.path.exists(filename) else None) | ||
3331 | 166 | captcha_id = self.processor.generate_captcha(filename) | 169 | captcha_id = self.processor.generate_captcha(filename) |
3332 | 167 | self.assertEqual(CAPTCHA_ID, captcha_id, 'captcha id must be correct.') | 170 | self.assertEqual(CAPTCHA_ID, captcha_id, 'captcha id must be correct.') |
3333 | 168 | self.assertTrue(os.path.isfile(filename), '%s must exist.' % filename) | 171 | self.assertTrue(os.path.isfile(filename), '%s must exist.' % filename) |
3334 | 169 | 172 | ||
3335 | === modified file 'ubuntu_sso/tests/test_credentials.py' | |||
3336 | --- ubuntu_sso/tests/test_credentials.py 2011-06-24 19:14:17 +0000 | |||
3337 | +++ ubuntu_sso/tests/test_credentials.py 2011-08-25 19:16:19 +0000 | |||
3338 | @@ -20,19 +20,19 @@ | |||
3339 | 20 | 20 | ||
3340 | 21 | import logging | 21 | import logging |
3341 | 22 | import os | 22 | import os |
3343 | 23 | import urllib | 23 | import urllib2 |
3344 | 24 | 24 | ||
3345 | 25 | from twisted.internet import defer | 25 | from twisted.internet import defer |
3346 | 26 | from twisted.internet.defer import inlineCallbacks | ||
3347 | 27 | from twisted.trial.unittest import TestCase, FailTest | 26 | from twisted.trial.unittest import TestCase, FailTest |
3348 | 28 | from ubuntuone.devtools.handlers import MementoHandler | 27 | from ubuntuone.devtools.handlers import MementoHandler |
3349 | 29 | 28 | ||
3350 | 30 | from ubuntu_sso import credentials | 29 | from ubuntu_sso import credentials |
3351 | 30 | import ubuntu_sso.main | ||
3352 | 31 | from ubuntu_sso.credentials import (APP_NAME_KEY, HELP_TEXT_KEY, NO_OP, | 31 | from ubuntu_sso.credentials import (APP_NAME_KEY, HELP_TEXT_KEY, NO_OP, |
3353 | 32 | PING_URL_KEY, TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY, | 32 | PING_URL_KEY, TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY, |
3354 | 33 | ERROR_KEY, ERROR_DETAIL_KEY) | 33 | ERROR_KEY, ERROR_DETAIL_KEY) |
3355 | 34 | from ubuntu_sso.tests import (APP_NAME, EMAIL, GTK_GUI_CLASS, GTK_GUI_MODULE, | 34 | from ubuntu_sso.tests import (APP_NAME, EMAIL, GTK_GUI_CLASS, GTK_GUI_MODULE, |
3357 | 35 | HELP_TEXT, PING_URL, TC_URL, TOKEN, WINDOW_ID) | 35 | HELP_TEXT, PASSWORD, PING_URL, TC_URL, TOKEN, WINDOW_ID) |
3358 | 36 | 36 | ||
3359 | 37 | 37 | ||
3360 | 38 | # Access to a protected member of a client class | 38 | # Access to a protected member of a client class |
3361 | @@ -41,6 +41,9 @@ | |||
3362 | 41 | # Attribute defined outside __init__ | 41 | # Attribute defined outside __init__ |
3363 | 42 | # pylint: disable=W0201 | 42 | # pylint: disable=W0201 |
3364 | 43 | 43 | ||
3365 | 44 | # Instance of 'class' has no 'x' member (but some types could not be inferred) | ||
3366 | 45 | # pylint: disable=E1103 | ||
3367 | 46 | |||
3368 | 44 | 47 | ||
3369 | 45 | KWARGS = { | 48 | KWARGS = { |
3370 | 46 | APP_NAME_KEY: APP_NAME, | 49 | APP_NAME_KEY: APP_NAME, |
3371 | @@ -64,11 +67,13 @@ | |||
3372 | 64 | """An error to be used while testing.""" | 67 | """An error to be used while testing.""" |
3373 | 65 | 68 | ||
3374 | 66 | 69 | ||
3377 | 67 | class FailingClientGUI(object): | 70 | class FailingClient(object): |
3378 | 68 | """Fake a failing SSO GUI.""" | 71 | """Fake a failing client.""" |
3379 | 72 | |||
3380 | 73 | err_msg = 'A failing class.' | ||
3381 | 69 | 74 | ||
3382 | 70 | def __init__(self, *args, **kwargs): | 75 | def __init__(self, *args, **kwargs): |
3384 | 71 | raise SampleMiscException('A failing GUI class.') | 76 | raise SampleMiscException(self.err_msg) |
3385 | 72 | 77 | ||
3386 | 73 | 78 | ||
3387 | 74 | class FakedClientGUI(object): | 79 | class FakedClientGUI(object): |
3388 | @@ -82,6 +87,18 @@ | |||
3389 | 82 | self.user_cancellation_callback = None | 87 | self.user_cancellation_callback = None |
3390 | 83 | 88 | ||
3391 | 84 | 89 | ||
3392 | 90 | class FakedSSOLoginRoot(object): | ||
3393 | 91 | """Fake a SSOLoginRoot.""" | ||
3394 | 92 | |||
3395 | 93 | args = [] | ||
3396 | 94 | kwargs = {} | ||
3397 | 95 | |||
3398 | 96 | def login(self, *args, **kwargs): | ||
3399 | 97 | """Fake login.""" | ||
3400 | 98 | self.args = args | ||
3401 | 99 | self.kwargs = kwargs | ||
3402 | 100 | |||
3403 | 101 | |||
3404 | 85 | class BasicTestCase(TestCase): | 102 | class BasicTestCase(TestCase): |
3405 | 86 | """Test case with a helper tracker.""" | 103 | """Test case with a helper tracker.""" |
3406 | 87 | 104 | ||
3407 | @@ -113,10 +130,6 @@ | |||
3408 | 113 | denial_cb=self.denial, | 130 | denial_cb=self.denial, |
3409 | 114 | **KWARGS) | 131 | **KWARGS) |
3410 | 115 | 132 | ||
3411 | 116 | def tearDown(self): | ||
3412 | 117 | """Clean up.""" | ||
3413 | 118 | super(CredentialsTestCase, self).tearDown() | ||
3414 | 119 | |||
3415 | 120 | def success(self, *args, **kwargs): | 133 | def success(self, *args, **kwargs): |
3416 | 121 | """To be called on success.""" | 134 | """To be called on success.""" |
3417 | 122 | self._set_called('success', *args, **kwargs) | 135 | self._set_called('success', *args, **kwargs) |
3418 | @@ -232,7 +245,7 @@ | |||
3419 | 232 | class CredentialsLoginSuccessTestCase(CredentialsTestCase): | 245 | class CredentialsLoginSuccessTestCase(CredentialsTestCase): |
3420 | 233 | """Test suite for the Credentials login success callback.""" | 246 | """Test suite for the Credentials login success callback.""" |
3421 | 234 | 247 | ||
3423 | 235 | @inlineCallbacks | 248 | @defer.inlineCallbacks |
3424 | 236 | def test_cred_not_found(self): | 249 | def test_cred_not_found(self): |
3425 | 237 | """On auth success, if cred not found, self.error_cb is called.""" | 250 | """On auth success, if cred not found, self.error_cb is called.""" |
3426 | 238 | self.patch(credentials.Keyring, 'get_credentials', | 251 | self.patch(credentials.Keyring, 'get_credentials', |
3427 | @@ -245,7 +258,7 @@ | |||
3428 | 245 | detailed_error=AssertionError(msg)) | 258 | detailed_error=AssertionError(msg)) |
3429 | 246 | self.assertEqual(result, None) | 259 | self.assertEqual(result, None) |
3430 | 247 | 260 | ||
3432 | 248 | @inlineCallbacks | 261 | @defer.inlineCallbacks |
3433 | 249 | def test_cred_error(self): | 262 | def test_cred_error(self): |
3434 | 250 | """On auth success, if cred failed, self.error_cb is called.""" | 263 | """On auth success, if cred failed, self.error_cb is called.""" |
3435 | 251 | expected_error = SampleMiscException() | 264 | expected_error = SampleMiscException() |
3436 | @@ -259,7 +272,7 @@ | |||
3437 | 259 | self.assertEqual(result, None) | 272 | self.assertEqual(result, None) |
3438 | 260 | self.assertTrue(self.memento.check_exception(SampleMiscException)) | 273 | self.assertTrue(self.memento.check_exception(SampleMiscException)) |
3439 | 261 | 274 | ||
3441 | 262 | @inlineCallbacks | 275 | @defer.inlineCallbacks |
3442 | 263 | def test_ping_success(self): | 276 | def test_ping_success(self): |
3443 | 264 | """Auth success + cred found + ping success, success_cb is called.""" | 277 | """Auth success + cred found + ping success, success_cb is called.""" |
3444 | 265 | self.patch(credentials.Keyring, 'get_credentials', | 278 | self.patch(credentials.Keyring, 'get_credentials', |
3445 | @@ -271,7 +284,7 @@ | |||
3446 | 271 | self.assertEqual(self._called, (('success', APP_NAME, TOKEN), {})) | 284 | self.assertEqual(self._called, (('success', APP_NAME, TOKEN), {})) |
3447 | 272 | self.assertEqual(result, 0) | 285 | self.assertEqual(result, 0) |
3448 | 273 | 286 | ||
3450 | 274 | @inlineCallbacks | 287 | @defer.inlineCallbacks |
3451 | 275 | def test_ping_error(self): | 288 | def test_ping_error(self): |
3452 | 276 | """Auth success + cred found + ping error, error_cb is called. | 289 | """Auth success + cred found + ping error, error_cb is called. |
3453 | 277 | 290 | ||
3454 | @@ -299,7 +312,7 @@ | |||
3455 | 299 | # exception logged | 312 | # exception logged |
3456 | 300 | self.assertTrue(self.memento.check_exception(FailTest, error)) | 313 | self.assertTrue(self.memento.check_exception(FailTest, error)) |
3457 | 301 | 314 | ||
3459 | 302 | @inlineCallbacks | 315 | @defer.inlineCallbacks |
3460 | 303 | def test_pings_url(self): | 316 | def test_pings_url(self): |
3461 | 304 | """On auth success, self.ping_url is opened.""" | 317 | """On auth success, self.ping_url is opened.""" |
3462 | 305 | self.patch(credentials.Keyring, 'get_credentials', | 318 | self.patch(credentials.Keyring, 'get_credentials', |
3463 | @@ -315,7 +328,7 @@ | |||
3464 | 315 | 328 | ||
3465 | 316 | self.assertEqual(self._url_pinged, ((APP_NAME, EMAIL, TOKEN), {})) | 329 | self.assertEqual(self._url_pinged, ((APP_NAME, EMAIL, TOKEN), {})) |
3466 | 317 | 330 | ||
3468 | 318 | @inlineCallbacks | 331 | @defer.inlineCallbacks |
3469 | 319 | def test_no_ping_url_is_success(self): | 332 | def test_no_ping_url_is_success(self): |
3470 | 320 | """Auth success + cred found + no ping url, success_cb is called. | 333 | """Auth success + cred found + no ping url, success_cb is called. |
3471 | 321 | 334 | ||
3472 | @@ -353,15 +366,15 @@ | |||
3473 | 353 | def faked_urlopen(request): | 366 | def faked_urlopen(request): |
3474 | 354 | """Fake urlopener.""" | 367 | """Fake urlopener.""" |
3475 | 355 | self._request = request | 368 | self._request = request |
3480 | 356 | response = urllib.addinfourl(fp=open(os.path.devnull), | 369 | response = urllib2.addinfourl(fp=open(os.path.devnull), |
3481 | 357 | headers=request.headers, | 370 | headers=request.headers, |
3482 | 358 | url=request.get_full_url(), | 371 | url=request.get_full_url(), |
3483 | 359 | code=200) | 372 | code=200) |
3484 | 360 | return response | 373 | return response |
3485 | 361 | 374 | ||
3486 | 362 | self.patch(credentials.urllib2, 'urlopen', faked_urlopen) | 375 | self.patch(credentials.urllib2, 'urlopen', faked_urlopen) |
3487 | 363 | 376 | ||
3489 | 364 | @inlineCallbacks | 377 | @defer.inlineCallbacks |
3490 | 365 | def test_ping_url_if_url_is_none(self): | 378 | def test_ping_url_if_url_is_none(self): |
3491 | 366 | """self.ping_url is opened.""" | 379 | """self.ping_url is opened.""" |
3492 | 367 | self.patch(credentials.urllib2, 'urlopen', self.fail) | 380 | self.patch(credentials.urllib2, 'urlopen', self.fail) |
3493 | @@ -370,7 +383,7 @@ | |||
3494 | 370 | credentials=TOKEN) | 383 | credentials=TOKEN) |
3495 | 371 | # no failure | 384 | # no failure |
3496 | 372 | 385 | ||
3498 | 373 | @inlineCallbacks | 386 | @defer.inlineCallbacks |
3499 | 374 | def test_ping_url(self): | 387 | def test_ping_url(self): |
3500 | 375 | """On auth success, self.ping_url is opened.""" | 388 | """On auth success, self.ping_url is opened.""" |
3501 | 376 | yield self.obj._ping_url(app_name=APP_NAME, email=EMAIL, | 389 | yield self.obj._ping_url(app_name=APP_NAME, email=EMAIL, |
3502 | @@ -380,23 +393,23 @@ | |||
3503 | 380 | self.assertEqual(self._request.get_full_url(), | 393 | self.assertEqual(self._request.get_full_url(), |
3504 | 381 | self.obj.ping_url + EMAIL) | 394 | self.obj.ping_url + EMAIL) |
3505 | 382 | 395 | ||
3507 | 383 | @inlineCallbacks | 396 | @defer.inlineCallbacks |
3508 | 384 | def test_request_is_signed_with_credentials(self): | 397 | def test_request_is_signed_with_credentials(self): |
3509 | 385 | """The http request to self.ping_url is signed with the credentials.""" | 398 | """The http request to self.ping_url is signed with the credentials.""" |
3510 | 399 | |||
3511 | 400 | def fake_it(*a, **kw): | ||
3512 | 401 | """Fake oauth_headers.""" | ||
3513 | 402 | self._set_called(*a, **kw) | ||
3514 | 403 | return {} | ||
3515 | 404 | |||
3516 | 405 | self.patch(credentials.utils, 'oauth_headers', fake_it) | ||
3517 | 386 | result = yield self.obj._ping_url(APP_NAME, EMAIL, TOKEN) | 406 | result = yield self.obj._ping_url(APP_NAME, EMAIL, TOKEN) |
3531 | 387 | headers = self._request.headers | 407 | |
3532 | 388 | 408 | self.assertEqual(self._called, | |
3533 | 389 | self.assertIn('Authorization', headers) | 409 | ((self.obj.ping_url + EMAIL, TOKEN), {})) |
3534 | 390 | oauth_stuff = headers['Authorization'] | 410 | self.assertEqual(result.code, 200) |
3535 | 391 | 411 | ||
3536 | 392 | expected = 'oauth_consumer_key="xQ7xDAz", ' \ | 412 | @defer.inlineCallbacks |
3524 | 393 | 'oauth_signature_method="HMAC-SHA1", oauth_version="1.0", ' \ | ||
3525 | 394 | 'oauth_token="GkInOfSMGwTXAUoVQwLUoPxElEEUdhsLVNTPhxHJDUIeHCPNEo' \ | ||
3526 | 395 | '", oauth_signature="' | ||
3527 | 396 | self.assertIn(expected, oauth_stuff) | ||
3528 | 397 | self.assertEqual(result, 200) | ||
3529 | 398 | |||
3530 | 399 | @inlineCallbacks | ||
3537 | 400 | def test_ping_url_error(self): | 413 | def test_ping_url_error(self): |
3538 | 401 | """Exception is handled if ping fails.""" | 414 | """Exception is handled if ping fails.""" |
3539 | 402 | error = 'Blu' | 415 | error = 'Blu' |
3540 | @@ -408,12 +421,52 @@ | |||
3541 | 408 | self.assert_error_cb_called(msg=msg, detailed_error=FailTest(error)) | 421 | self.assert_error_cb_called(msg=msg, detailed_error=FailTest(error)) |
3542 | 409 | self.assertTrue(self.memento.check_exception(FailTest, error)) | 422 | self.assertTrue(self.memento.check_exception(FailTest, error)) |
3543 | 410 | 423 | ||
3544 | 424 | @defer.inlineCallbacks | ||
3545 | 425 | def test_ping_url_formatting(self): | ||
3546 | 426 | """The email is added as the first formatting argument.""" | ||
3547 | 427 | self.obj.ping_url = u'http://example.com/{email}/something/else' | ||
3548 | 428 | result = yield self.obj._ping_url(app_name=APP_NAME, email=EMAIL, | ||
3549 | 429 | credentials=TOKEN) | ||
3550 | 430 | |||
3551 | 431 | expected = self.obj.ping_url.format(email=EMAIL) | ||
3552 | 432 | self.assertEqual(expected, result.url) | ||
3553 | 433 | |||
3554 | 434 | @defer.inlineCallbacks | ||
3555 | 435 | def test_ping_url_formatting_with_query_params(self): | ||
3556 | 436 | """The email is added as the first formatting argument.""" | ||
3557 | 437 | self.obj.ping_url = u'http://example.com/{email}?something=else' | ||
3558 | 438 | result = yield self.obj._ping_url(app_name=APP_NAME, email=EMAIL, | ||
3559 | 439 | credentials=TOKEN) | ||
3560 | 440 | |||
3561 | 441 | expected = self.obj.ping_url.format(email=EMAIL) | ||
3562 | 442 | self.assertEqual(expected, result.url) | ||
3563 | 443 | |||
3564 | 444 | @defer.inlineCallbacks | ||
3565 | 445 | def test_ping_url_formatting_no_email_kwarg(self): | ||
3566 | 446 | """The email is added as the first formatting argument.""" | ||
3567 | 447 | self.obj.ping_url = u'http://example.com/{0}/yadda/?something=else' | ||
3568 | 448 | result = yield self.obj._ping_url(app_name=APP_NAME, email=EMAIL, | ||
3569 | 449 | credentials=TOKEN) | ||
3570 | 450 | |||
3571 | 451 | expected = self.obj.ping_url.format(EMAIL) | ||
3572 | 452 | self.assertEqual(expected, result.url) | ||
3573 | 453 | |||
3574 | 454 | @defer.inlineCallbacks | ||
3575 | 455 | def test_ping_url_formatting_no_format(self): | ||
3576 | 456 | """The email is appended if formatting could not be accomplished.""" | ||
3577 | 457 | self.obj.ping_url = u'http://example.com/yadda/' | ||
3578 | 458 | result = yield self.obj._ping_url(app_name=APP_NAME, email=EMAIL, | ||
3579 | 459 | credentials=TOKEN) | ||
3580 | 460 | |||
3581 | 461 | expected = self.obj.ping_url + EMAIL | ||
3582 | 462 | self.assertEqual(expected, result.url) | ||
3583 | 463 | |||
3584 | 411 | 464 | ||
3585 | 412 | class FindCredentialsTestCase(CredentialsTestCase): | 465 | class FindCredentialsTestCase(CredentialsTestCase): |
3586 | 413 | """Test suite for the find_credentials method.""" | 466 | """Test suite for the find_credentials method.""" |
3587 | 414 | timeout = 5 | 467 | timeout = 5 |
3588 | 415 | 468 | ||
3590 | 416 | @inlineCallbacks | 469 | @defer.inlineCallbacks |
3591 | 417 | def test_find_credentials(self): | 470 | def test_find_credentials(self): |
3592 | 418 | """A deferred with credentials is returned when found.""" | 471 | """A deferred with credentials is returned when found.""" |
3593 | 419 | self.patch(credentials.Keyring, 'get_credentials', | 472 | self.patch(credentials.Keyring, 'get_credentials', |
3594 | @@ -422,7 +475,7 @@ | |||
3595 | 422 | token = yield self.obj.find_credentials() | 475 | token = yield self.obj.find_credentials() |
3596 | 423 | self.assertEqual(token, TOKEN) | 476 | self.assertEqual(token, TOKEN) |
3597 | 424 | 477 | ||
3599 | 425 | @inlineCallbacks | 478 | @defer.inlineCallbacks |
3600 | 426 | def test_credentials_not_found(self): | 479 | def test_credentials_not_found(self): |
3601 | 427 | """find_credentials returns {} when no credentials are found.""" | 480 | """find_credentials returns {} when no credentials are found.""" |
3602 | 428 | self.patch(credentials.Keyring, 'get_credentials', | 481 | self.patch(credentials.Keyring, 'get_credentials', |
3603 | @@ -431,7 +484,7 @@ | |||
3604 | 431 | token = yield self.obj.find_credentials() | 484 | token = yield self.obj.find_credentials() |
3605 | 432 | self.assertEqual(token, {}) | 485 | self.assertEqual(token, {}) |
3606 | 433 | 486 | ||
3608 | 434 | @inlineCallbacks | 487 | @defer.inlineCallbacks |
3609 | 435 | def test_keyring_failure(self): | 488 | def test_keyring_failure(self): |
3610 | 436 | """Failures from the keyring are handled.""" | 489 | """Failures from the keyring are handled.""" |
3611 | 437 | expected_error = SampleMiscException() | 490 | expected_error = SampleMiscException() |
3612 | @@ -445,7 +498,7 @@ | |||
3613 | 445 | class ClearCredentialsTestCase(CredentialsTestCase): | 498 | class ClearCredentialsTestCase(CredentialsTestCase): |
3614 | 446 | """Test suite for the clear_credentials method.""" | 499 | """Test suite for the clear_credentials method.""" |
3615 | 447 | 500 | ||
3617 | 448 | @inlineCallbacks | 501 | @defer.inlineCallbacks |
3618 | 449 | def test_clear_credentials(self): | 502 | def test_clear_credentials(self): |
3619 | 450 | """The credentials are cleared.""" | 503 | """The credentials are cleared.""" |
3620 | 451 | self.patch(credentials.Keyring, 'delete_credentials', | 504 | self.patch(credentials.Keyring, 'delete_credentials', |
3621 | @@ -454,7 +507,7 @@ | |||
3622 | 454 | yield self.obj.clear_credentials() | 507 | yield self.obj.clear_credentials() |
3623 | 455 | self.assertEqual(self._called, ((APP_NAME,), {})) | 508 | self.assertEqual(self._called, ((APP_NAME,), {})) |
3624 | 456 | 509 | ||
3626 | 457 | @inlineCallbacks | 510 | @defer.inlineCallbacks |
3627 | 458 | def test_keyring_failure(self): | 511 | def test_keyring_failure(self): |
3628 | 459 | """Failures from the keyring are handled.""" | 512 | """Failures from the keyring are handled.""" |
3629 | 460 | expected_error = SampleMiscException() | 513 | expected_error = SampleMiscException() |
3630 | @@ -468,7 +521,7 @@ | |||
3631 | 468 | class StoreCredentialsTestCase(CredentialsTestCase): | 521 | class StoreCredentialsTestCase(CredentialsTestCase): |
3632 | 469 | """Test suite for the store_credentials method.""" | 522 | """Test suite for the store_credentials method.""" |
3633 | 470 | 523 | ||
3635 | 471 | @inlineCallbacks | 524 | @defer.inlineCallbacks |
3636 | 472 | def test_store_credentials(self): | 525 | def test_store_credentials(self): |
3637 | 473 | """The credentials are stored.""" | 526 | """The credentials are stored.""" |
3638 | 474 | self.patch(credentials.Keyring, 'set_credentials', | 527 | self.patch(credentials.Keyring, 'set_credentials', |
3639 | @@ -477,7 +530,7 @@ | |||
3640 | 477 | yield self.obj.store_credentials(TOKEN) | 530 | yield self.obj.store_credentials(TOKEN) |
3641 | 478 | self.assertEqual(self._called, ((APP_NAME, TOKEN,), {})) | 531 | self.assertEqual(self._called, ((APP_NAME, TOKEN,), {})) |
3642 | 479 | 532 | ||
3644 | 480 | @inlineCallbacks | 533 | @defer.inlineCallbacks |
3645 | 481 | def test_keyring_failure(self): | 534 | def test_keyring_failure(self): |
3646 | 482 | """Failures from the keyring are handled.""" | 535 | """Failures from the keyring are handled.""" |
3647 | 483 | expected_error = SampleMiscException() | 536 | expected_error = SampleMiscException() |
3648 | @@ -493,85 +546,89 @@ | |||
3649 | 493 | 546 | ||
3650 | 494 | operation = 'register' | 547 | operation = 'register' |
3651 | 495 | login_only = False | 548 | login_only = False |
3652 | 549 | kwargs = {} | ||
3653 | 550 | inner_class = FakedClientGUI | ||
3654 | 496 | 551 | ||
3655 | 497 | def setUp(self): | 552 | def setUp(self): |
3656 | 498 | super(RegisterTestCase, self).setUp() | 553 | super(RegisterTestCase, self).setUp() |
3659 | 499 | self.ui_kwargs = UI_KWARGS.copy() | 554 | self.inner_kwargs = UI_KWARGS.copy() |
3660 | 500 | self.ui_kwargs['login_only'] = self.login_only | 555 | self.inner_kwargs['login_only'] = self.login_only |
3661 | 556 | self.method_call = getattr(self.obj, self.operation) | ||
3662 | 501 | 557 | ||
3664 | 502 | @inlineCallbacks | 558 | @defer.inlineCallbacks |
3665 | 503 | def test_with_existent_token(self): | 559 | def test_with_existent_token(self): |
3666 | 504 | """The operation returns the credentials if already in keyring.""" | 560 | """The operation returns the credentials if already in keyring.""" |
3667 | 505 | self.patch(credentials.Keyring, 'get_credentials', | 561 | self.patch(credentials.Keyring, 'get_credentials', |
3668 | 506 | lambda kr, app: defer.succeed(TOKEN)) | 562 | lambda kr, app: defer.succeed(TOKEN)) |
3669 | 507 | 563 | ||
3671 | 508 | yield getattr(self.obj, self.operation)() | 564 | yield self.method_call(**self.kwargs) |
3672 | 509 | 565 | ||
3673 | 510 | self.assertEqual(self._called, (('success', APP_NAME, TOKEN), {})) | 566 | self.assertEqual(self._called, (('success', APP_NAME, TOKEN), {})) |
3674 | 511 | 567 | ||
3676 | 512 | @inlineCallbacks | 568 | @defer.inlineCallbacks |
3677 | 513 | def test_without_existent_token(self): | 569 | def test_without_existent_token(self): |
3679 | 514 | """The operation returns the credentials gathered by the GUI.""" | 570 | """The operation returns the credentials gathered by the inner call.""" |
3680 | 515 | self.patch(credentials.Keyring, 'get_credentials', | 571 | self.patch(credentials.Keyring, 'get_credentials', |
3681 | 516 | lambda kr, app: defer.succeed(None)) | 572 | lambda kr, app: defer.succeed(None)) |
3682 | 517 | 573 | ||
3688 | 518 | yield getattr(self.obj, self.operation)() | 574 | yield self.method_call(**self.kwargs) |
3689 | 519 | 575 | ||
3690 | 520 | self.assertEqual(self.obj.gui.kwargs, self.ui_kwargs) | 576 | self.assertEqual(self.obj.inner.kwargs, self.inner_kwargs) |
3691 | 521 | 577 | ||
3692 | 522 | @inlineCallbacks | 578 | @defer.inlineCallbacks |
3693 | 523 | def test_with_exception_on_credentials(self): | 579 | def test_with_exception_on_credentials(self): |
3694 | 524 | """The operation calls the error callback if a exception occurs.""" | 580 | """The operation calls the error callback if a exception occurs.""" |
3695 | 525 | expected_error = SampleMiscException() | 581 | expected_error = SampleMiscException() |
3696 | 526 | self.patch(credentials.Keyring, 'get_credentials', | 582 | self.patch(credentials.Keyring, 'get_credentials', |
3697 | 527 | lambda kr, app: defer.fail(expected_error)) | 583 | lambda kr, app: defer.fail(expected_error)) |
3698 | 528 | 584 | ||
3700 | 529 | yield getattr(self.obj, self.operation)() | 585 | yield self.method_call(**self.kwargs) |
3701 | 530 | 586 | ||
3702 | 531 | msg = 'Problem while retrieving credentials' | 587 | msg = 'Problem while retrieving credentials' |
3703 | 532 | self.assert_error_cb_called(msg=msg, detailed_error=expected_error) | 588 | self.assert_error_cb_called(msg=msg, detailed_error=expected_error) |
3704 | 533 | self.assertTrue(self.memento.check_exception(SampleMiscException)) | 589 | self.assertTrue(self.memento.check_exception(SampleMiscException)) |
3705 | 534 | 590 | ||
3709 | 535 | @inlineCallbacks | 591 | @defer.inlineCallbacks |
3710 | 536 | def test_with_exception_on_gui(self): | 592 | def test_with_exception_on_inner_call(self, msg=None): |
3711 | 537 | """The operation calls the error callback if a GUI exception occurs.""" | 593 | """The operation calls the error callback if a exception occurs.""" |
3712 | 538 | self.patch(credentials.Keyring, 'get_credentials', | 594 | self.patch(credentials.Keyring, 'get_credentials', |
3713 | 539 | lambda kr, app: defer.succeed(None)) | 595 | lambda kr, app: defer.succeed(None)) |
3720 | 540 | err = 'A failing GUI class.' | 596 | self.obj.ui_class = 'FailingClient' |
3721 | 541 | self.obj.ui_class = 'FailingClientGUI' | 597 | |
3722 | 542 | 598 | yield self.method_call(**self.kwargs) | |
3723 | 543 | yield getattr(self.obj, self.operation)() | 599 | |
3724 | 544 | 600 | if msg is None: | |
3725 | 545 | msg = 'Problem opening the Ubuntu SSO user interface' | 601 | msg = 'Problem opening the Ubuntu SSO user interface' |
3726 | 546 | self.assert_error_cb_called(msg=msg, | 602 | self.assert_error_cb_called(msg=msg, |
3729 | 547 | detailed_error=SampleMiscException(err)) | 603 | detailed_error=SampleMiscException(FailingClient.err_msg)) |
3730 | 548 | self.assertTrue(self.memento.check_exception(SampleMiscException, err)) | 604 | self.assertTrue(self.memento.check_exception(SampleMiscException, |
3731 | 605 | FailingClient.err_msg)) | ||
3732 | 549 | 606 | ||
3736 | 550 | @inlineCallbacks | 607 | @defer.inlineCallbacks |
3737 | 551 | def test_connects_gui_signals(self): | 608 | def test_connects_inner_signals(self): |
3738 | 552 | """GUI callbacks are properly connected.""" | 609 | """Inner callbacks are properly connected.""" |
3739 | 553 | self.patch(credentials.Keyring, 'get_credentials', | 610 | self.patch(credentials.Keyring, 'get_credentials', |
3740 | 554 | lambda kr, app: defer.succeed(None)) | 611 | lambda kr, app: defer.succeed(None)) |
3742 | 555 | yield getattr(self.obj, self.operation)() | 612 | yield self.method_call(**self.kwargs) |
3743 | 556 | 613 | ||
3749 | 557 | self.assertEqual(self.obj.gui.login_success_callback, | 614 | self.assertEqual(self.obj.inner.login_success_callback, |
3750 | 558 | self.obj._login_success_cb) | 615 | self.obj._login_success_cb) |
3751 | 559 | self.assertEqual(self.obj.gui.registration_success_callback, | 616 | self.assertEqual(self.obj.inner.registration_success_callback, |
3752 | 560 | self.obj._login_success_cb) | 617 | self.obj._login_success_cb) |
3753 | 561 | self.assertEqual(self.obj.gui.user_cancellation_callback, | 618 | self.assertEqual(self.obj.inner.user_cancellation_callback, |
3754 | 562 | self.obj._auth_denial_cb) | 619 | self.obj._auth_denial_cb) |
3755 | 563 | 620 | ||
3759 | 564 | @inlineCallbacks | 621 | @defer.inlineCallbacks |
3760 | 565 | def test_gui_is_created(self): | 622 | def test_inner_object_is_created(self): |
3761 | 566 | """The GUI is created and stored.""" | 623 | """The inner object is created and stored.""" |
3762 | 567 | self.patch(credentials.Keyring, 'get_credentials', | 624 | self.patch(credentials.Keyring, 'get_credentials', |
3763 | 568 | lambda kr, app: defer.succeed(None)) | 625 | lambda kr, app: defer.succeed(None)) |
3764 | 569 | 626 | ||
3766 | 570 | yield getattr(self.obj, self.operation)() | 627 | yield self.method_call(**self.kwargs) |
3767 | 571 | 628 | ||
3771 | 572 | self.assertIsInstance(self.obj.gui, FakedClientGUI) | 629 | self.assertIsInstance(self.obj.inner, self.inner_class) |
3772 | 573 | self.assertEqual(self.obj.gui.args, ()) | 630 | self.assertEqual(self.obj.inner.args, ()) |
3773 | 574 | self.assertEqual(self.obj.gui.kwargs, self.ui_kwargs) | 631 | self.assertEqual(self.obj.inner.kwargs, self.inner_kwargs) |
3774 | 575 | 632 | ||
3775 | 576 | 633 | ||
3776 | 577 | class LoginTestCase(RegisterTestCase): | 634 | class LoginTestCase(RegisterTestCase): |
3777 | @@ -579,3 +636,32 @@ | |||
3778 | 579 | 636 | ||
3779 | 580 | operation = 'login' | 637 | operation = 'login' |
3780 | 581 | login_only = True | 638 | login_only = True |
3781 | 639 | |||
3782 | 640 | |||
3783 | 641 | class LoginEmailPasswordTestCase(RegisterTestCase): | ||
3784 | 642 | """Test suite for the login_email_password method.""" | ||
3785 | 643 | |||
3786 | 644 | operation = 'login_email_password' | ||
3787 | 645 | login_only = True | ||
3788 | 646 | kwargs = {'email': EMAIL, 'password': PASSWORD} | ||
3789 | 647 | inner_class = FakedSSOLoginRoot | ||
3790 | 648 | |||
3791 | 649 | def setUp(self): | ||
3792 | 650 | super(LoginEmailPasswordTestCase, self).setUp() | ||
3793 | 651 | self.inner_kwargs = {APP_NAME_KEY: APP_NAME, 'email': EMAIL, | ||
3794 | 652 | 'password': PASSWORD, | ||
3795 | 653 | 'result_cb': self.obj._login_success_cb, | ||
3796 | 654 | 'error_cb': self.obj._error_cb, | ||
3797 | 655 | 'not_validated_cb': self.obj._error_cb} | ||
3798 | 656 | self.patch(ubuntu_sso.main, 'SSOLoginRoot', FakedSSOLoginRoot) | ||
3799 | 657 | |||
3800 | 658 | def test_with_exception_on_inner_call(self, msg=None): | ||
3801 | 659 | """The operation calls the error callback if a exception occurs.""" | ||
3802 | 660 | self.patch(ubuntu_sso.main, 'SSOLoginRoot', FailingClient) | ||
3803 | 661 | msg = 'Problem logging with email and password.' | ||
3804 | 662 | return super(LoginEmailPasswordTestCase, | ||
3805 | 663 | self).test_with_exception_on_inner_call(msg=msg) | ||
3806 | 664 | |||
3807 | 665 | def test_connects_inner_signals(self): | ||
3808 | 666 | """Inner callbacks are properly connected.""" | ||
3809 | 667 | # there is no inner callbacks for the SSOLoginRoot object | ||
3810 | 582 | 668 | ||
3811 | === modified file 'ubuntu_sso/utils/__init__.py' | |||
3812 | --- ubuntu_sso/utils/__init__.py 2010-11-30 13:21:17 +0000 | |||
3813 | +++ ubuntu_sso/utils/__init__.py 2011-08-25 19:16:19 +0000 | |||
3814 | @@ -17,3 +17,38 @@ | |||
3815 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
3816 | 18 | 18 | ||
3817 | 19 | """Utility modules that may find use outside ubuntu_sso.""" | 19 | """Utility modules that may find use outside ubuntu_sso.""" |
3818 | 20 | |||
3819 | 21 | import cgi | ||
3820 | 22 | |||
3821 | 23 | from oauth import oauth | ||
3822 | 24 | from urlparse import urlparse | ||
3823 | 25 | |||
3824 | 26 | |||
3825 | 27 | def oauth_headers(url, credentials, http_method='GET'): | ||
3826 | 28 | """Sign 'url' using 'credentials'. | ||
3827 | 29 | |||
3828 | 30 | * 'url' must be a valid unicode url. | ||
3829 | 31 | * 'credentials' must be a valid OAuth token. | ||
3830 | 32 | |||
3831 | 33 | Return oauth headers that can be pass to any Request like object. | ||
3832 | 34 | |||
3833 | 35 | """ | ||
3834 | 36 | assert isinstance(url, unicode) | ||
3835 | 37 | url = url.encode('utf-8') | ||
3836 | 38 | _, _, _, _, query, _ = urlparse(url) | ||
3837 | 39 | parameters = dict(cgi.parse_qsl(query)) | ||
3838 | 40 | |||
3839 | 41 | consumer = oauth.OAuthConsumer(credentials['consumer_key'], | ||
3840 | 42 | credentials['consumer_secret']) | ||
3841 | 43 | token = oauth.OAuthToken(credentials['token'], | ||
3842 | 44 | credentials['token_secret']) | ||
3843 | 45 | kwargs = dict(oauth_consumer=consumer, token=token, | ||
3844 | 46 | http_method=http_method, http_url=url, | ||
3845 | 47 | parameters=parameters) | ||
3846 | 48 | get_request = oauth.OAuthRequest.from_consumer_and_token | ||
3847 | 49 | oauth_req = get_request(**kwargs) | ||
3848 | 50 | hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1() | ||
3849 | 51 | oauth_req.sign_request(hmac_sha1, consumer, token) | ||
3850 | 52 | headers = oauth_req.to_header() | ||
3851 | 53 | |||
3852 | 54 | return headers | ||
3853 | 20 | 55 | ||
3854 | === added file 'ubuntu_sso/utils/tests/test_oauth_headers.py' | |||
3855 | --- ubuntu_sso/utils/tests/test_oauth_headers.py 1970-01-01 00:00:00 +0000 | |||
3856 | +++ ubuntu_sso/utils/tests/test_oauth_headers.py 2011-08-25 19:16:19 +0000 | |||
3857 | @@ -0,0 +1,109 @@ | |||
3858 | 1 | # -*- coding: utf-8 -*- | ||
3859 | 2 | |||
3860 | 3 | # Author: Natalia B. Bidart <natalia.bidart@canonical.com> | ||
3861 | 4 | # | ||
3862 | 5 | # Copyright 2011 Canonical Ltd. | ||
3863 | 6 | # | ||
3864 | 7 | # This program is free software: you can redistribute it and/or modify it | ||
3865 | 8 | # under the terms of the GNU General Public License version 3, as published | ||
3866 | 9 | # by the Free Software Foundation. | ||
3867 | 10 | # | ||
3868 | 11 | # This program is distributed in the hope that it will be useful, but | ||
3869 | 12 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
3870 | 13 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
3871 | 14 | # PURPOSE. See the GNU General Public License for more details. | ||
3872 | 15 | # | ||
3873 | 16 | # You should have received a copy of the GNU General Public License along | ||
3874 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3875 | 18 | |||
3876 | 19 | """Tests for the oauth_headers helper function.""" | ||
3877 | 20 | |||
3878 | 21 | from twisted.trial.unittest import TestCase | ||
3879 | 22 | |||
3880 | 23 | from ubuntu_sso.utils import oauth, oauth_headers | ||
3881 | 24 | from ubuntu_sso.tests import TOKEN | ||
3882 | 25 | |||
3883 | 26 | |||
3884 | 27 | class FakedOAuthRequest(object): | ||
3885 | 28 | """Replace the OAuthRequest class.""" | ||
3886 | 29 | |||
3887 | 30 | params = {} | ||
3888 | 31 | |||
3889 | 32 | def __init__(self): | ||
3890 | 33 | self.sign_request = lambda *args, **kwargs: None | ||
3891 | 34 | self.to_header = lambda *args, **kwargs: {} | ||
3892 | 35 | |||
3893 | 36 | def from_consumer_and_token(oauth_consumer, **kwargs): | ||
3894 | 37 | """Fake the method storing the params for check.""" | ||
3895 | 38 | FakedOAuthRequest.params.update(kwargs) | ||
3896 | 39 | return FakedOAuthRequest() | ||
3897 | 40 | from_consumer_and_token = staticmethod(from_consumer_and_token) | ||
3898 | 41 | |||
3899 | 42 | |||
3900 | 43 | class SignWithCredentialsTestCase(TestCase): | ||
3901 | 44 | """Test suite for the oauth_headers method.""" | ||
3902 | 45 | |||
3903 | 46 | url = u'http://example.com' | ||
3904 | 47 | |||
3905 | 48 | def build_header(self, url, http_method='GET'): | ||
3906 | 49 | """Build an Oauth header for comparison.""" | ||
3907 | 50 | consumer = oauth.OAuthConsumer(TOKEN['consumer_key'], | ||
3908 | 51 | TOKEN['consumer_secret']) | ||
3909 | 52 | token = oauth.OAuthToken(TOKEN['token'], | ||
3910 | 53 | TOKEN['token_secret']) | ||
3911 | 54 | get_request = oauth.OAuthRequest.from_consumer_and_token | ||
3912 | 55 | oauth_req = get_request(oauth_consumer=consumer, token=token, | ||
3913 | 56 | http_method=http_method, http_url=url) | ||
3914 | 57 | oauth_req.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(), | ||
3915 | 58 | consumer, token) | ||
3916 | 59 | return oauth_req.to_header() | ||
3917 | 60 | |||
3918 | 61 | def dictify_header(self, header): | ||
3919 | 62 | """Convert an OAuth header into a dict.""" | ||
3920 | 63 | result = {} | ||
3921 | 64 | fields = header.split(', ') | ||
3922 | 65 | for field in fields: | ||
3923 | 66 | key, value = field.split('=') | ||
3924 | 67 | result[key] = value.strip('"') | ||
3925 | 68 | |||
3926 | 69 | return result | ||
3927 | 70 | |||
3928 | 71 | def assert_header_equal(self, expected, actual): | ||
3929 | 72 | """Is 'expected' equals to 'actual'?""" | ||
3930 | 73 | expected = self.dictify_header(expected['Authorization']) | ||
3931 | 74 | actual = self.dictify_header(actual['Authorization']) | ||
3932 | 75 | for header in (expected, actual): | ||
3933 | 76 | header.pop('oauth_nonce') | ||
3934 | 77 | header.pop('oauth_timestamp') | ||
3935 | 78 | header.pop('oauth_signature') | ||
3936 | 79 | |||
3937 | 80 | self.assertEqual(expected, actual) | ||
3938 | 81 | |||
3939 | 82 | def assert_method_called(self, path, query_str='', http_method='GET'): | ||
3940 | 83 | """Assert that the url build by joining 'paths' was called.""" | ||
3941 | 84 | expected = (self.url, path, query_str) | ||
3942 | 85 | expected = ''.join(expected).encode('utf8') | ||
3943 | 86 | expected = self.build_header(expected, http_method=http_method) | ||
3944 | 87 | actual = oauth_headers(url=self.url + path, credentials=TOKEN) | ||
3945 | 88 | self.assert_header_equal(expected, actual) | ||
3946 | 89 | |||
3947 | 90 | def test_call(self): | ||
3948 | 91 | """Calling 'get' triggers an OAuth signed GET request.""" | ||
3949 | 92 | path = u'/test/' | ||
3950 | 93 | self.assert_method_called(path) | ||
3951 | 94 | |||
3952 | 95 | def test_quotes_path(self): | ||
3953 | 96 | """Calling 'get' quotes the path.""" | ||
3954 | 97 | path = u'/test me more, sÃ!/' | ||
3955 | 98 | self.assert_method_called(path) | ||
3956 | 99 | |||
3957 | 100 | def test_adds_parameters_to_oauth_request(self): | ||
3958 | 101 | """The query string from the path is used in the oauth request.""" | ||
3959 | 102 | self.patch(oauth, 'OAuthRequest', FakedOAuthRequest) | ||
3960 | 103 | |||
3961 | 104 | path = u'/test/something?foo=bar' | ||
3962 | 105 | oauth_headers(url=self.url + path, credentials=TOKEN) | ||
3963 | 106 | |||
3964 | 107 | self.assertIn('parameters', FakedOAuthRequest.params) | ||
3965 | 108 | self.assertEqual(FakedOAuthRequest.params['parameters'], | ||
3966 | 109 | {'foo': 'bar'}) | ||
3967 | 0 | 110 | ||
3968 | === modified file 'ubuntu_sso/utils/txsecrets.py' | |||
3969 | --- ubuntu_sso/utils/txsecrets.py 2011-07-22 20:12:20 +0000 | |||
3970 | +++ ubuntu_sso/utils/txsecrets.py 2011-08-25 19:16:19 +0000 | |||
3971 | @@ -21,13 +21,19 @@ | |||
3972 | 21 | * http://code.confuego.org/secrets-xdg-specs/ | 21 | * http://code.confuego.org/secrets-xdg-specs/ |
3973 | 22 | """ | 22 | """ |
3974 | 23 | 23 | ||
3976 | 24 | import gobject | 24 | import sys |
3977 | 25 | # pylint: disable=E0611 | ||
3978 | 26 | if 'gobject' in sys.modules: | ||
3979 | 27 | import gobject as GObject | ||
3980 | 28 | else: | ||
3981 | 29 | from gi.repository import GObject | ||
3982 | 30 | # pylint: enable=E0611 | ||
3983 | 25 | import dbus | 31 | import dbus |
3984 | 26 | from dbus.mainloop.glib import DBusGMainLoop | 32 | from dbus.mainloop.glib import DBusGMainLoop |
3985 | 27 | import dbus.mainloop.glib | 33 | import dbus.mainloop.glib |
3986 | 28 | from twisted.internet.defer import Deferred | 34 | from twisted.internet.defer import Deferred |
3987 | 29 | 35 | ||
3989 | 30 | gobject.threads_init() | 36 | GObject.threads_init() |
3990 | 31 | dbus.mainloop.glib.threads_init() | 37 | dbus.mainloop.glib.threads_init() |
3991 | 32 | DBusGMainLoop(set_as_default=True) | 38 | DBusGMainLoop(set_as_default=True) |
3992 | 33 | 39 | ||
3993 | 34 | 40 | ||
3994 | === modified file 'ubuntu_sso/utils/ui.py' | |||
3995 | --- ubuntu_sso/utils/ui.py 2011-07-22 20:12:20 +0000 | |||
3996 | +++ ubuntu_sso/utils/ui.py 2011-08-25 19:16:19 +0000 | |||
3997 | @@ -20,10 +20,10 @@ | |||
3998 | 20 | 20 | ||
3999 | 21 | import os | 21 | import os |
4000 | 22 | import re | 22 | import re |
4001 | 23 | import xdg | ||
4002 | 24 | import gettext | 23 | import gettext |
4003 | 25 | 24 | ||
4004 | 26 | from ubuntu_sso.logger import setup_logging | 25 | from ubuntu_sso.logger import setup_logging |
4005 | 26 | from ubuntu_sso import xdg_base_directory | ||
4006 | 27 | 27 | ||
4007 | 28 | logger = setup_logging('ubuntu_sso.utils.ui') | 28 | logger = setup_logging('ubuntu_sso.utils.ui') |
4008 | 29 | 29 | ||
4009 | @@ -35,6 +35,7 @@ | |||
4010 | 35 | CAPTCHA_SOLUTION_ENTRY = _('Type the characters above') | 35 | CAPTCHA_SOLUTION_ENTRY = _('Type the characters above') |
4011 | 36 | CAPTCHA_LOAD_ERROR = _('There was a problem getting the captcha, ' | 36 | CAPTCHA_LOAD_ERROR = _('There was a problem getting the captcha, ' |
4012 | 37 | 'reloading...') | 37 | 'reloading...') |
4013 | 38 | CAPTCHA_REQUIRED_ERROR = _('The captcha is a required field') | ||
4014 | 38 | CONNECT_HELP_LABEL = _('To connect this computer to %(app_name)s ' \ | 39 | CONNECT_HELP_LABEL = _('To connect this computer to %(app_name)s ' \ |
4015 | 39 | 'enter your details below.') | 40 | 'enter your details below.') |
4016 | 40 | EMAIL1_ENTRY = _('Email address') | 41 | EMAIL1_ENTRY = _('Email address') |
4017 | @@ -117,7 +118,7 @@ | |||
4018 | 117 | return result | 118 | return result |
4019 | 118 | 119 | ||
4020 | 119 | # no local data dir, looking within system data dirs | 120 | # no local data dir, looking within system data dirs |
4022 | 120 | data_dirs = xdg.BaseDirectory.xdg_data_dirs | 121 | data_dirs = xdg_base_directory.xdg_data_dirs |
4023 | 121 | for path in data_dirs: | 122 | for path in data_dirs: |
4024 | 122 | result = os.path.join(path, 'ubuntu-sso-client', 'data') | 123 | result = os.path.join(path, 'ubuntu-sso-client', 'data') |
4025 | 123 | result = os.path.abspath(result) | 124 | result = os.path.abspath(result) |
4026 | 124 | 125 | ||
4027 | === added directory 'ubuntu_sso/xdg_base_directory' | |||
4028 | === added file 'ubuntu_sso/xdg_base_directory/__init__.py' | |||
4029 | --- ubuntu_sso/xdg_base_directory/__init__.py 1970-01-01 00:00:00 +0000 | |||
4030 | +++ ubuntu_sso/xdg_base_directory/__init__.py 2011-08-25 19:16:19 +0000 | |||
4031 | @@ -0,0 +1,35 @@ | |||
4032 | 1 | # Author: Natalia B. Bidart <natalia.bidart@canonical.com> | ||
4033 | 2 | # | ||
4034 | 3 | # Copyright 2011 Canonical Ltd. | ||
4035 | 4 | # | ||
4036 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
4037 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
4038 | 7 | # by the Free Software Foundation. | ||
4039 | 8 | # | ||
4040 | 9 | # This program is distributed in the hope that it will be useful, but | ||
4041 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
4042 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
4043 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
4044 | 13 | # | ||
4045 | 14 | # You should have received a copy of the GNU General Public License along | ||
4046 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4047 | 16 | |||
4048 | 17 | """XDG multiplatform.""" | ||
4049 | 18 | |||
4050 | 19 | import sys | ||
4051 | 20 | |||
4052 | 21 | # pylint: disable=C0103 | ||
4053 | 22 | if sys.platform == "win32": | ||
4054 | 23 | from ubuntu_sso.xdg_base_directory import windows | ||
4055 | 24 | load_config_paths = windows.load_config_paths | ||
4056 | 25 | save_config_path = windows.save_config_path | ||
4057 | 26 | xdg_cache_home = windows.xdg_cache_home | ||
4058 | 27 | xdg_data_home = windows.xdg_data_home | ||
4059 | 28 | xdg_data_dirs = windows.xdg_data_dirs | ||
4060 | 29 | else: | ||
4061 | 30 | import xdg.BaseDirectory | ||
4062 | 31 | load_config_paths = xdg.BaseDirectory.load_config_paths | ||
4063 | 32 | save_config_path = xdg.BaseDirectory.save_config_path | ||
4064 | 33 | xdg_cache_home = xdg.BaseDirectory.xdg_cache_home | ||
4065 | 34 | xdg_data_home = xdg.BaseDirectory.xdg_data_home | ||
4066 | 35 | xdg_data_dirs = xdg.BaseDirectory.xdg_data_dirs | ||
4067 | 0 | 36 | ||
4068 | === added directory 'ubuntu_sso/xdg_base_directory/tests' | |||
4069 | === added file 'ubuntu_sso/xdg_base_directory/tests/__init__.py' | |||
4070 | --- ubuntu_sso/xdg_base_directory/tests/__init__.py 1970-01-01 00:00:00 +0000 | |||
4071 | +++ ubuntu_sso/xdg_base_directory/tests/__init__.py 2011-08-25 19:16:19 +0000 | |||
4072 | @@ -0,0 +1,16 @@ | |||
4073 | 1 | # ubuntu_sso - Ubuntu Single Sign On client support for desktop apps | ||
4074 | 2 | # | ||
4075 | 3 | # Copyright 2009-2010 Canonical Ltd. | ||
4076 | 4 | # | ||
4077 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
4078 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
4079 | 7 | # by the Free Software Foundation. | ||
4080 | 8 | # | ||
4081 | 9 | # This program is distributed in the hope that it will be useful, but | ||
4082 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
4083 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
4084 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
4085 | 13 | # | ||
4086 | 14 | # You should have received a copy of the GNU General Public License along | ||
4087 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4088 | 16 | """XDG tests.""" | ||
4089 | 0 | 17 | ||
4090 | === added file 'ubuntu_sso/xdg_base_directory/tests/test_common.py' | |||
4091 | --- ubuntu_sso/xdg_base_directory/tests/test_common.py 1970-01-01 00:00:00 +0000 | |||
4092 | +++ ubuntu_sso/xdg_base_directory/tests/test_common.py 2011-08-25 19:16:19 +0000 | |||
4093 | @@ -0,0 +1,49 @@ | |||
4094 | 1 | # -*- coding: utf-8 -*- | ||
4095 | 2 | # | ||
4096 | 3 | # Authors: Natalia B. Bidart <natalia.bidart@canonical.com> | ||
4097 | 4 | # | ||
4098 | 5 | # Copyright 2011 Canonical Ltd. | ||
4099 | 6 | # | ||
4100 | 7 | # This program is free software: you can redistribute it and/or modify it | ||
4101 | 8 | # under the terms of the GNU General Public License version 3, as published | ||
4102 | 9 | # by the Free Software Foundation. | ||
4103 | 10 | # | ||
4104 | 11 | # This program is distributed in the hope that it will be useful, but | ||
4105 | 12 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
4106 | 13 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
4107 | 14 | # PURPOSE. See the GNU General Public License for more details. | ||
4108 | 15 | # | ||
4109 | 16 | # You should have received a copy of the GNU General Public License along | ||
4110 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4111 | 18 | |||
4112 | 19 | """Platform independent tests for the XDG constants.""" | ||
4113 | 20 | |||
4114 | 21 | import os | ||
4115 | 22 | |||
4116 | 23 | from twisted.trial.unittest import TestCase | ||
4117 | 24 | |||
4118 | 25 | from ubuntu_sso import xdg_base_directory | ||
4119 | 26 | |||
4120 | 27 | |||
4121 | 28 | class TestBaseDirectory(TestCase): | ||
4122 | 29 | """Tests for the BaseDirectory module.""" | ||
4123 | 30 | |||
4124 | 31 | def test_xdg_cache_home_is_bytes(self): | ||
4125 | 32 | """The returned path is bytes.""" | ||
4126 | 33 | actual = xdg_base_directory.xdg_cache_home | ||
4127 | 34 | self.assertIsInstance(actual, str) | ||
4128 | 35 | |||
4129 | 36 | def test_xdg_data_home_is_bytes(self): | ||
4130 | 37 | """The returned path is bytes.""" | ||
4131 | 38 | actual = xdg_base_directory.xdg_data_home | ||
4132 | 39 | self.assertIsInstance(actual, str) | ||
4133 | 40 | |||
4134 | 41 | def test_load_config_paths_filter(self): | ||
4135 | 42 | """Since those folders don't exist, this should be empty.""" | ||
4136 | 43 | self.assertEqual(list(xdg_base_directory.load_config_paths("x")), []) | ||
4137 | 44 | |||
4138 | 45 | def test_save_config_path(self): | ||
4139 | 46 | """The path should end with xdg_config/x (respecting the separator).""" | ||
4140 | 47 | self.patch(os, "makedirs", lambda *args: None) | ||
4141 | 48 | result = xdg_base_directory.save_config_path("x") | ||
4142 | 49 | self.assertEqual(result.split(os.sep)[-2:], ['xdg_config', 'x']) | ||
4143 | 0 | 50 | ||
4144 | === added file 'ubuntu_sso/xdg_base_directory/tests/test_windows.py' | |||
4145 | --- ubuntu_sso/xdg_base_directory/tests/test_windows.py 1970-01-01 00:00:00 +0000 | |||
4146 | +++ ubuntu_sso/xdg_base_directory/tests/test_windows.py 2011-08-25 19:16:19 +0000 | |||
4147 | @@ -0,0 +1,112 @@ | |||
4148 | 1 | # -*- coding: utf-8 -*- | ||
4149 | 2 | # | ||
4150 | 3 | # Authors: Natalia B. Bidart <natalia.bidart@canonical.com> | ||
4151 | 4 | # | ||
4152 | 5 | # Copyright 2011 Canonical Ltd. | ||
4153 | 6 | # | ||
4154 | 7 | # This program is free software: you can redistribute it and/or modify it | ||
4155 | 8 | # under the terms of the GNU General Public License version 3, as published | ||
4156 | 9 | # by the Free Software Foundation. | ||
4157 | 10 | # | ||
4158 | 11 | # This program is distributed in the hope that it will be useful, but | ||
4159 | 12 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
4160 | 13 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
4161 | 14 | # PURPOSE. See the GNU General Public License for more details. | ||
4162 | 15 | # | ||
4163 | 16 | # You should have received a copy of the GNU General Public License along | ||
4164 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4165 | 18 | |||
4166 | 19 | """Windows-specific tests for the XDG constants.""" | ||
4167 | 20 | |||
4168 | 21 | import os | ||
4169 | 22 | import sys | ||
4170 | 23 | |||
4171 | 24 | from twisted.trial.unittest import TestCase | ||
4172 | 25 | from ubuntuone.devtools.testcase import skipIfOS | ||
4173 | 26 | |||
4174 | 27 | |||
4175 | 28 | # pylint: disable=E1101, E0611, F0401 | ||
4176 | 29 | if sys.platform == "win32": | ||
4177 | 30 | import win32com.shell | ||
4178 | 31 | from ubuntu_sso.xdg_base_directory.windows import ( | ||
4179 | 32 | get_config_dirs, | ||
4180 | 33 | get_data_dirs, | ||
4181 | 34 | get_special_folders, | ||
4182 | 35 | ) | ||
4183 | 36 | |||
4184 | 37 | |||
4185 | 38 | # pylint: disable=C0103 | ||
4186 | 39 | class FakeShellConModule(object): | ||
4187 | 40 | """Override CSIDL_ constants.""" | ||
4188 | 41 | CSIDL_PROFILE = 0 | ||
4189 | 42 | CSIDL_LOCAL_APPDATA = 1 | ||
4190 | 43 | CSIDL_COMMON_APPDATA = 2 | ||
4191 | 44 | |||
4192 | 45 | |||
4193 | 46 | class FakeShellModule(object): | ||
4194 | 47 | |||
4195 | 48 | """Fake Shell Module.""" | ||
4196 | 49 | |||
4197 | 50 | def __init__(self): | ||
4198 | 51 | """Set the proper mapping between CSIDL_ consts.""" | ||
4199 | 52 | self.values = { | ||
4200 | 53 | 0: u'c:\\path\\to\\users\\home', | ||
4201 | 54 | 1: u'c:\\path\\to\\users\\home\\appData\\local', | ||
4202 | 55 | 2: u'c:\\programData', | ||
4203 | 56 | } | ||
4204 | 57 | |||
4205 | 58 | def SHGetFolderPath(self, dummy0, shellconValue, dummy2, dummy3): | ||
4206 | 59 | """Override SHGetFolderPath functionality.""" | ||
4207 | 60 | return self.values[shellconValue] | ||
4208 | 61 | |||
4209 | 62 | |||
4210 | 63 | @skipIfOS('linux2', 'Windows-specific tests.') | ||
4211 | 64 | class TestBaseDirectoryWindows(TestCase): | ||
4212 | 65 | """Tests for the BaseDirectory module.""" | ||
4213 | 66 | |||
4214 | 67 | def test_get_special_folders(self): | ||
4215 | 68 | """Make sure we can import the platform module.""" | ||
4216 | 69 | |||
4217 | 70 | shellModule = FakeShellModule() | ||
4218 | 71 | self.patch(win32com.shell, "shell", shellModule) | ||
4219 | 72 | self.patch(win32com.shell, "shellcon", FakeShellConModule()) | ||
4220 | 73 | special_folders = get_special_folders() | ||
4221 | 74 | self.assertTrue('Personal' in special_folders) | ||
4222 | 75 | self.assertTrue('Local AppData' in special_folders) | ||
4223 | 76 | self.assertTrue('AppData' in special_folders) | ||
4224 | 77 | self.assertTrue('Common AppData' in special_folders) | ||
4225 | 78 | |||
4226 | 79 | self.assertTrue(special_folders['Personal'] == \ | ||
4227 | 80 | shellModule.values[FakeShellConModule.CSIDL_PROFILE]) | ||
4228 | 81 | self.assertTrue(special_folders['Local AppData'] == \ | ||
4229 | 82 | shellModule.values[FakeShellConModule.CSIDL_LOCAL_APPDATA]) | ||
4230 | 83 | self.assertTrue(special_folders['Local AppData'].startswith( | ||
4231 | 84 | special_folders['AppData'])) | ||
4232 | 85 | self.assertTrue(special_folders['Common AppData'] == \ | ||
4233 | 86 | shellModule.values[FakeShellConModule.CSIDL_COMMON_APPDATA]) | ||
4234 | 87 | |||
4235 | 88 | # Can't use assert_syncdaemon_path | ||
4236 | 89 | for val in special_folders.itervalues(): | ||
4237 | 90 | self.assertIsInstance(val, str) | ||
4238 | 91 | val.decode('utf8') | ||
4239 | 92 | # Should not raise exceptions | ||
4240 | 93 | |||
4241 | 94 | def test_get_data_dirs(self): | ||
4242 | 95 | """Check thet get_data_dirs uses pathsep correctly.""" | ||
4243 | 96 | bad_sep = filter(lambda x: x not in os.pathsep, ":;") | ||
4244 | 97 | dir_list = ["A", "B", bad_sep, "C"] | ||
4245 | 98 | self.patch(os, "environ", | ||
4246 | 99 | dict(XDG_DATA_DIRS=os.pathsep.join( | ||
4247 | 100 | dir_list))) | ||
4248 | 101 | dirs = get_data_dirs() | ||
4249 | 102 | self.assertEqual(dirs, dir_list) | ||
4250 | 103 | |||
4251 | 104 | def test_get_config_dirs(self): | ||
4252 | 105 | """Check thet get_data_dirs uses pathsep correctly.""" | ||
4253 | 106 | bad_sep = filter(lambda x: x not in os.pathsep, ":;") | ||
4254 | 107 | dir_list = ["A", "B", bad_sep, "C"] | ||
4255 | 108 | self.patch(os, "environ", | ||
4256 | 109 | dict(XDG_CONFIG_DIRS=os.pathsep.join( | ||
4257 | 110 | dir_list))) | ||
4258 | 111 | dirs = get_config_dirs()[1:] | ||
4259 | 112 | self.assertEqual(dirs, dir_list) | ||
4260 | 0 | 113 | ||
4261 | === added file 'ubuntu_sso/xdg_base_directory/windows.py' | |||
4262 | --- ubuntu_sso/xdg_base_directory/windows.py 1970-01-01 00:00:00 +0000 | |||
4263 | +++ ubuntu_sso/xdg_base_directory/windows.py 2011-08-25 19:16:19 +0000 | |||
4264 | @@ -0,0 +1,119 @@ | |||
4265 | 1 | # Authors: Manuel de la Pena <manuel@canonical.com> | ||
4266 | 2 | # Diego Sarmentero <diego.sarmentero@canonical.com> | ||
4267 | 3 | # | ||
4268 | 4 | # Copyright 2011 Canonical Ltd. | ||
4269 | 5 | # | ||
4270 | 6 | # This program is free software: you can redistribute it and/or modify it | ||
4271 | 7 | # under the terms of the GNU General Public License version 3, as published | ||
4272 | 8 | # by the Free Software Foundation. | ||
4273 | 9 | # | ||
4274 | 10 | # This program is distributed in the hope that it will be useful, but | ||
4275 | 11 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
4276 | 12 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
4277 | 13 | # PURPOSE. See the GNU General Public License for more details. | ||
4278 | 14 | # | ||
4279 | 15 | # You should have received a copy of the GNU General Public License along | ||
4280 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4281 | 17 | |||
4282 | 18 | """XDG helpers for windows.""" | ||
4283 | 19 | |||
4284 | 20 | import os | ||
4285 | 21 | |||
4286 | 22 | |||
4287 | 23 | # pylint: disable=C0103 | ||
4288 | 24 | def get_special_folders(): | ||
4289 | 25 | """ Routine to grab all the Windows Special Folders locations. | ||
4290 | 26 | |||
4291 | 27 | If successful, returns dictionary | ||
4292 | 28 | of shell folder locations indexed on Windows keyword for each; | ||
4293 | 29 | otherwise, returns an empty dictionary. | ||
4294 | 30 | """ | ||
4295 | 31 | # pylint: disable=W0621, F0401, E0611 | ||
4296 | 32 | special_folders = {} | ||
4297 | 33 | |||
4298 | 34 | from win32com.shell import shell, shellcon | ||
4299 | 35 | # CSIDL_LOCAL_APPDATA = C:\Users\<username>\AppData\Local | ||
4300 | 36 | # CSIDL_PROFILE = C:\Users\<username> | ||
4301 | 37 | # CSIDL_COMMON_APPDATA = C:\ProgramData | ||
4302 | 38 | # More information on these at | ||
4303 | 39 | # http://msdn.microsoft.com/en-us/library/bb762494(v=vs.85).aspx | ||
4304 | 40 | get_path = lambda name: shell.SHGetFolderPath( | ||
4305 | 41 | 0, getattr(shellcon, name), None, 0).encode('utf8') | ||
4306 | 42 | special_folders['Personal'] = get_path("CSIDL_PROFILE") | ||
4307 | 43 | special_folders['Local AppData'] = get_path("CSIDL_LOCAL_APPDATA") | ||
4308 | 44 | special_folders['AppData'] = os.path.dirname( | ||
4309 | 45 | special_folders['Local AppData']) | ||
4310 | 46 | special_folders['Common AppData'] = get_path("CSIDL_COMMON_APPDATA") | ||
4311 | 47 | return special_folders | ||
4312 | 48 | |||
4313 | 49 | special_folders = get_special_folders() | ||
4314 | 50 | |||
4315 | 51 | home_path = special_folders['Personal'] | ||
4316 | 52 | app_local_data_path = special_folders['Local AppData'] | ||
4317 | 53 | app_global_data_path = special_folders['Common AppData'] | ||
4318 | 54 | |||
4319 | 55 | # use the non roaming app data | ||
4320 | 56 | xdg_data_home = os.environ.get('XDG_DATA_HOME', | ||
4321 | 57 | os.path.join(app_local_data_path, 'xdg')) | ||
4322 | 58 | |||
4323 | 59 | |||
4324 | 60 | def get_data_dirs(): | ||
4325 | 61 | """Returns XDG data directories.""" | ||
4326 | 62 | return os.environ.get('XDG_DATA_DIRS', | ||
4327 | 63 | '{0}{1}{2}'.format(app_local_data_path, os.pathsep, | ||
4328 | 64 | app_global_data_path)).split(os.pathsep) | ||
4329 | 65 | |||
4330 | 66 | xdg_data_dirs = get_data_dirs() | ||
4331 | 67 | |||
4332 | 68 | # we will return the roaming data wich is as close as we get in windows | ||
4333 | 69 | # regarding caching. | ||
4334 | 70 | xdg_cache_home = os.environ.get('XDG_CACHE_HOME', | ||
4335 | 71 | os.path.join(xdg_data_home, 'cache')) | ||
4336 | 72 | |||
4337 | 73 | # point to the not roaming app data for the user | ||
4338 | 74 | xdg_config_home = os.environ.get('XDG_CONFIG_HOME', | ||
4339 | 75 | app_local_data_path) | ||
4340 | 76 | |||
4341 | 77 | |||
4342 | 78 | def get_config_dirs(): | ||
4343 | 79 | """Return XDG config directories.""" | ||
4344 | 80 | return [xdg_config_home] + \ | ||
4345 | 81 | os.environ.get('XDG_CONFIG_DIRS', | ||
4346 | 82 | app_global_data_path, | ||
4347 | 83 | ).split(os.pathsep) | ||
4348 | 84 | |||
4349 | 85 | xdg_config_dirs = get_config_dirs() | ||
4350 | 86 | |||
4351 | 87 | xdg_data_dirs = filter(lambda x: x, xdg_data_dirs) | ||
4352 | 88 | xdg_config_dirs = filter(lambda x: x, xdg_config_dirs) | ||
4353 | 89 | |||
4354 | 90 | |||
4355 | 91 | def load_config_paths(*resource): | ||
4356 | 92 | """Iterator of configuration paths. | ||
4357 | 93 | |||
4358 | 94 | Return an iterator which gives each directory named 'resource' in | ||
4359 | 95 | the configuration search path. Information provided by earlier | ||
4360 | 96 | directories should take precedence over later ones (ie, the user's | ||
4361 | 97 | config dir comes first). | ||
4362 | 98 | """ | ||
4363 | 99 | resource = os.path.join(*resource) | ||
4364 | 100 | for config_dir in xdg_config_dirs: | ||
4365 | 101 | path = os.path.join(config_dir, resource) | ||
4366 | 102 | if os.path.exists(path): | ||
4367 | 103 | yield path | ||
4368 | 104 | |||
4369 | 105 | |||
4370 | 106 | def save_config_path(*resource): | ||
4371 | 107 | """Path to save configuration. | ||
4372 | 108 | |||
4373 | 109 | Ensure $XDG_CONFIG_HOME/<resource>/ exists, and return its path. | ||
4374 | 110 | 'resource' should normally be the name of your application. Use this | ||
4375 | 111 | when SAVING configuration settings. Use the xdg_config_dirs variable | ||
4376 | 112 | for loading. | ||
4377 | 113 | """ | ||
4378 | 114 | resource = os.path.join(*resource) | ||
4379 | 115 | assert not resource.startswith('/') | ||
4380 | 116 | path = os.path.join(xdg_config_home, resource) | ||
4381 | 117 | if not os.path.isdir(path): | ||
4382 | 118 | os.makedirs(path, 0700) | ||
4383 | 119 | return path |