Merge lp:~elopio/u1-test-utils/update_sso_pages1-tests2 into lp:u1-test-utils
- update_sso_pages1-tests2
- Merge into trunk
Proposed by
Leo Arias
Status: | Merged |
---|---|
Approved by: | Leo Arias |
Approved revision: | 93 |
Merged at revision: | 87 |
Proposed branch: | lp:~elopio/u1-test-utils/update_sso_pages1-tests2 |
Merge into: | lp:u1-test-utils |
Diff against target: |
455 lines (+285/-86) 3 files modified
requirements.txt (+1/-0) u1testutils/sso/selftests/acceptance/test_sst_helpers.py (+270/-74) u1testutils/sso/sst/__init__.py (+14/-12) |
To merge this branch: | bzr merge lp:~elopio/u1-test-utils/update_sso_pages1-tests2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Vincent Ladeuil (community) | Approve | ||
Review via email: mp+173300@code.launchpad.net |
Commit message
Added acceptance tests for the create account helper.
Run the sign in and create account tests for the ubuntuone brand and for the other brands.
Description of the change
I added the tests for the create account helper, and afterwards refactored all the tests to use a FakeSSOWebsite that works as a context manager deleting all its files on exit.
To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote : | # |
> 218 + def __exit__(self, exc_type, exc_val, exc_tb):
> 219 + shutil.
>
> That would be easier to find (and to think about) if it was closer to
> __enter__.
I'll take a look at contextlib. I think this might look nicer with the decorator. But that tomorrow, I'll merge it now.
Thanks!
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'requirements.txt' | |||
2 | --- requirements.txt 2013-07-03 07:23:07 +0000 | |||
3 | +++ requirements.txt 2013-07-06 07:12:27 +0000 | |||
4 | @@ -4,6 +4,7 @@ | |||
5 | 4 | mock | 4 | mock |
6 | 5 | pep8 | 5 | pep8 |
7 | 6 | pyflakes | 6 | pyflakes |
8 | 7 | testscenarios==0.4 | ||
9 | 7 | Twisted | 8 | Twisted |
10 | 8 | bzr+ssh://bazaar.launchpad.net/~bloodearnest/localmail/trunk@36 | 9 | bzr+ssh://bazaar.launchpad.net/~bloodearnest/localmail/trunk@36 |
11 | 9 | bzr+http://bazaar.launchpad.net/~ubuntuone-hackers/payclient/trunk@4 | 10 | bzr+http://bazaar.launchpad.net/~ubuntuone-hackers/payclient/trunk@4 |
12 | 10 | 11 | ||
13 | === modified file 'u1testutils/sso/selftests/acceptance/test_sst_helpers.py' | |||
14 | --- u1testutils/sso/selftests/acceptance/test_sst_helpers.py 2013-07-03 07:44:12 +0000 | |||
15 | +++ u1testutils/sso/selftests/acceptance/test_sst_helpers.py 2013-07-06 07:12:27 +0000 | |||
16 | @@ -15,7 +15,9 @@ | |||
17 | 15 | import os | 15 | import os |
18 | 16 | import shutil | 16 | import shutil |
19 | 17 | import tempfile | 17 | import tempfile |
20 | 18 | import uuid | ||
21 | 18 | 19 | ||
22 | 20 | import testscenarios | ||
23 | 19 | from sst import cases | 21 | from sst import cases |
24 | 20 | 22 | ||
25 | 21 | import u1testutils.sst | 23 | import u1testutils.sst |
26 | @@ -26,17 +28,27 @@ | |||
27 | 26 | ) | 28 | ) |
28 | 27 | 29 | ||
29 | 28 | 30 | ||
30 | 31 | _WRONG_PAGE_SOURCE = ( | ||
31 | 32 | """ | ||
32 | 33 | <html data-qa-id="wrong"> | ||
33 | 34 | </html> | ||
34 | 35 | """ | ||
35 | 36 | ) | ||
36 | 37 | |||
37 | 29 | _LOGIN_FROM_REDIRECT_PAGE_SOURCE = ( | 38 | _LOGIN_FROM_REDIRECT_PAGE_SOURCE = ( |
38 | 30 | """ | 39 | """ |
39 | 31 | <html data-qa-id="login"> | 40 | <html data-qa-id="login"> |
40 | 32 | <head> | 41 | <head> |
41 | 33 | <title>Log in</title> | 42 | <title>Log in</title> |
42 | 34 | </head> | 43 | </head> |
44 | 35 | <form data-qa-id="login_form" action="{0}" method="get" > | 44 | <span data-qa-id="brand_ubuntu" /> |
45 | 45 | <form data-qa-id="login_form" action="{login_form_submit_link}" | ||
46 | 46 | method="get" > | ||
47 | 36 | <input id="id_email" type="email" /> | 47 | <input id="id_email" type="email" /> |
48 | 37 | <input id="id_password" type="password" /> | 48 | <input id="id_password" type="password" /> |
49 | 38 | <button data-qa-id="login_button" type="submit" /> | 49 | <button data-qa-id="login_button" type="submit" /> |
50 | 39 | </form> | 50 | </form> |
51 | 51 | <a href="{create_account_link}" data-qa-id="create_account_link" /> | ||
52 | 40 | </html> | 52 | </html> |
53 | 41 | """ | 53 | """ |
54 | 42 | ) | 54 | ) |
55 | @@ -52,100 +64,284 @@ | |||
56 | 52 | """ | 64 | """ |
57 | 53 | ) | 65 | ) |
58 | 54 | 66 | ||
68 | 55 | _WRONG_PAGE_SOURCE = ( | 67 | _CREATE_ACCOUNT_FROM_REDIRECT_PAGE_SOURCE = ( |
69 | 56 | """ | 68 | """ |
70 | 57 | <html data-qa-id="wrong"> | 69 | <html data-qa-id="new_account"> |
71 | 58 | </html> | 70 | <form data-qa-id="create_account_form" |
72 | 59 | """ | 71 | action="{create_account_form_submit_link}" method="get" > |
73 | 60 | ) | 72 | <input id="id_email" type="email" /> |
74 | 61 | 73 | <input id="id_displayname" type="text" /> | |
75 | 62 | 74 | <input id="id_password" type="password" /> | |
76 | 63 | class SignInTestCase(cases.SSTTestCase, logging.LogHandlerTestCase): | 75 | <input id="id_passwordconfirm" type="password" /> |
77 | 76 | <input id="recaptcha_response_field" type="text" /> | ||
78 | 77 | <input id="id_accept_tos" type="checkbox" /> | ||
79 | 78 | <button data-qa-id="register_button" type="submit" /> | ||
80 | 79 | </form> | ||
81 | 80 | </html> | ||
82 | 81 | """ | ||
83 | 82 | ) | ||
84 | 83 | |||
85 | 84 | _UNIFIED_LOGIN_FROM_REDIRECT_PAGE_SOURCE = ( | ||
86 | 85 | """ | ||
87 | 86 | <html data-qa-id="login"> | ||
88 | 87 | <head> | ||
89 | 88 | <title>Log in</title> | ||
90 | 89 | </head> | ||
91 | 90 | <span data-qa-id="brand_ubuntuone" /> | ||
92 | 91 | <form data-qa-id="login_form" action="{login_form_submit_link}" | ||
93 | 92 | method="get" > | ||
94 | 93 | <input id="id_email" type="email" /> | ||
95 | 94 | <input id="id_password" type="password" /> | ||
96 | 95 | <button data-qa-id="login_button" type="submit" /> | ||
97 | 96 | </form> | ||
98 | 97 | <a href="{create_account_link}" data-qa-id="user_intention_create" /> | ||
99 | 98 | </html> | ||
100 | 99 | """ | ||
101 | 100 | ) | ||
102 | 101 | |||
103 | 102 | |||
104 | 103 | _UNIFIED_CREATE_ACCOUNT_FROM_REDIRECT_PAGE_SOURCE = ( | ||
105 | 104 | """ | ||
106 | 105 | <html data-qa-id="login"> | ||
107 | 106 | <head> | ||
108 | 107 | <title>Log in</title> | ||
109 | 108 | </head> | ||
110 | 109 | <span data-qa-id="brand_ubuntuone" /> | ||
111 | 110 | <form data-qa-id="create_account_form" | ||
112 | 111 | action="{create_account_form_submit_link}" method="get" > | ||
113 | 112 | <input id="id_email" type="email" /> | ||
114 | 113 | <input id="id_displayname" type="text" /> | ||
115 | 114 | <input id="id_password" type="password" /> | ||
116 | 115 | <input id="id_passwordconfirm" type="password" /> | ||
117 | 116 | <input id="recaptcha_response_field" type="text" /> | ||
118 | 117 | <input id="id_accept_tos" type="checkbox" /> | ||
119 | 118 | <button data-qa-id="register_button" type="submit" /> | ||
120 | 119 | </form> | ||
121 | 120 | </html> | ||
122 | 121 | """ | ||
123 | 122 | ) | ||
124 | 123 | |||
125 | 124 | |||
126 | 125 | class FakeSSOWebsite(object): | ||
127 | 126 | |||
128 | 127 | def __init__(self, is_user_logged_in, is_site_recognized, brand): | ||
129 | 128 | super(FakeSSOWebsite, self).__init__() | ||
130 | 129 | self.is_user_logged_in = is_user_logged_in | ||
131 | 130 | self.is_site_recognized = is_site_recognized | ||
132 | 131 | self.brand = brand | ||
133 | 132 | |||
134 | 133 | def __enter__(self): | ||
135 | 134 | self.temp_directory = tempfile.mkdtemp() | ||
136 | 135 | self._write_fake_pages() | ||
137 | 136 | |||
138 | 137 | def _write_fake_pages(self): | ||
139 | 138 | if self.is_site_recognized: | ||
140 | 139 | not_recognized_path = '' | ||
141 | 140 | else: | ||
142 | 141 | not_recognized_path = self._write_fake_site_not_recognized_page() | ||
143 | 142 | if not self.is_user_logged_in: | ||
144 | 143 | self._write_login_and_create_account_pages(not_recognized_path) | ||
145 | 144 | |||
146 | 145 | def _write_fake_site_not_recognized_page(self): | ||
147 | 146 | source = _SITE_NOT_RECOGNIZED_PAGE_SOURCE | ||
148 | 147 | path = '+decide' | ||
149 | 148 | qa_anchor = 'decide' | ||
150 | 149 | return self._write_fake_page_with_token(path, source, qa_anchor) | ||
151 | 150 | |||
152 | 151 | def _write_fake_page_with_token(self, path, source, qa_anchor, **links): | ||
153 | 152 | # We do not check the tokens, so the easiest thing is to have the | ||
154 | 153 | # every page in separate paths, to write them to HTML files and be able | ||
155 | 154 | # to open all of them on the same test. In real life, the tokens are | ||
156 | 155 | # the same. To check the token can be a future improvement. | ||
157 | 156 | # -- elopio - 2013-07-03 | ||
158 | 157 | token = str(uuid.uuid1()) | ||
159 | 158 | token_directory = os.path.join(self.temp_directory, token) | ||
160 | 159 | os.mkdir(token_directory) | ||
161 | 160 | return self._write_fake_page( | ||
162 | 161 | token_directory, path, source, qa_anchor, **links) | ||
163 | 162 | |||
164 | 163 | def _write_fake_page(self, directory, path, source, qa_anchor, **links): | ||
165 | 164 | if links: | ||
166 | 165 | source = source.format(**links) | ||
167 | 166 | page_path = os.path.join(directory, path) | ||
168 | 167 | u1testutils.sst.StringHTMLPage( | ||
169 | 168 | source, page_path, qa_anchor, open_page=True) | ||
170 | 169 | return page_path | ||
171 | 170 | |||
172 | 171 | def _write_login_and_create_account_pages(self, next_page_path): | ||
173 | 172 | if self.brand == 'ubuntuone': | ||
174 | 173 | create_account_path = self._write_fake_unified_create_account_page( | ||
175 | 174 | next_page_path) | ||
176 | 175 | self._write_fake_unified_login_page( | ||
177 | 176 | next_page_path, create_account_path) | ||
178 | 177 | else: | ||
179 | 178 | create_account_path = self._write_fake_create_account_page( | ||
180 | 179 | next_page_path) | ||
181 | 180 | self._write_fake_login_page( | ||
182 | 181 | next_page_path, create_account_path) | ||
183 | 182 | |||
184 | 183 | def _write_fake_unified_create_account_page(self, next_page_path): | ||
185 | 184 | source = _UNIFIED_CREATE_ACCOUNT_FROM_REDIRECT_PAGE_SOURCE | ||
186 | 185 | path = '+decide' | ||
187 | 186 | qa_anchor = 'login' | ||
188 | 187 | return self._write_fake_page_with_token( | ||
189 | 188 | path, source, qa_anchor, | ||
190 | 189 | create_account_form_submit_link=next_page_path) | ||
191 | 190 | |||
192 | 191 | def _write_fake_unified_login_page( | ||
193 | 192 | self, next_page_path, create_account_path): | ||
194 | 193 | source = _UNIFIED_LOGIN_FROM_REDIRECT_PAGE_SOURCE | ||
195 | 194 | path = '+decide' | ||
196 | 195 | qa_anchor = 'login' | ||
197 | 196 | return self._write_fake_page_with_token( | ||
198 | 197 | path, source, qa_anchor, | ||
199 | 198 | login_form_submit_link=next_page_path, | ||
200 | 199 | create_account_link=create_account_path) | ||
201 | 200 | |||
202 | 201 | def _write_fake_create_account_page(self, next_page_path): | ||
203 | 202 | source = _CREATE_ACCOUNT_FROM_REDIRECT_PAGE_SOURCE | ||
204 | 203 | path = '+new_account' | ||
205 | 204 | qa_anchor = 'new_account' | ||
206 | 205 | return self._write_fake_page_with_token( | ||
207 | 206 | path, source, qa_anchor, | ||
208 | 207 | create_account_form_submit_link=next_page_path) | ||
209 | 208 | |||
210 | 209 | def _write_fake_login_page(self, next_page_path, create_account_path): | ||
211 | 210 | source = _LOGIN_FROM_REDIRECT_PAGE_SOURCE | ||
212 | 211 | path = '+decide' | ||
213 | 212 | qa_anchor = 'login' | ||
214 | 213 | return self._write_fake_page_with_token( | ||
215 | 214 | path, source, qa_anchor, login_form_submit_link=next_page_path, | ||
216 | 215 | create_account_link=create_account_path) | ||
217 | 216 | |||
218 | 217 | def __exit__(self, exc_type, exc_val, exc_tb): | ||
219 | 218 | shutil.rmtree(self.temp_directory) | ||
220 | 219 | |||
221 | 220 | |||
222 | 221 | class WrongSSOSiteTestCase(cases.SSTTestCase): | ||
223 | 64 | 222 | ||
224 | 65 | xserver_headless = True | 223 | xserver_headless = True |
225 | 66 | 224 | ||
226 | 67 | def setUp(self): | 225 | def setUp(self): |
231 | 68 | self.temp_directory = tempfile.mkdtemp() | 226 | self.base_url = 'file://' |
232 | 69 | self.addCleanup(shutil.rmtree, self.temp_directory) | 227 | super(WrongSSOSiteTestCase, self).setUp() |
233 | 70 | self.base_url = 'file://' + self.temp_directory | 228 | self._write_wrong_page() |
230 | 71 | super(SignInTestCase, self).setUp() | ||
234 | 72 | 229 | ||
237 | 73 | def test_sign_in_to_wrong_page(self): | 230 | def _write_wrong_page(self): |
238 | 74 | page_path = os.path.join(self.temp_directory, 'wrong') | 231 | temp_directory = tempfile.mkdtemp() |
239 | 232 | self.addCleanup(shutil.rmtree, temp_directory) | ||
240 | 233 | page_path = os.path.join(temp_directory, 'wrong') | ||
241 | 75 | u1testutils.sst.StringHTMLPage( | 234 | u1testutils.sst.StringHTMLPage( |
242 | 76 | _WRONG_PAGE_SOURCE, page_path, qa_anchor='wrong', | 235 | _WRONG_PAGE_SOURCE, page_path, qa_anchor='wrong', |
243 | 77 | open_page=True) | 236 | open_page=True) |
244 | 78 | 237 | ||
248 | 79 | self.assertRaises( | 238 | def test_sign_in(self): |
249 | 80 | AssertionError, sso_sst.sign_in, user=None, | 239 | self.assertRaises( |
250 | 81 | is_site_recognized=False) | 240 | AssertionError, sso_sst.sign_in, user='not important', |
251 | 241 | is_site_recognized=False) | ||
252 | 242 | |||
253 | 243 | def test_create_account(self): | ||
254 | 244 | self.assertRaises( | ||
255 | 245 | AssertionError, sso_sst.sign_in, user='not important', | ||
256 | 246 | is_site_recognized=False) | ||
257 | 247 | |||
258 | 248 | |||
259 | 249 | class SignInTestCase( | ||
260 | 250 | testscenarios.TestWithScenarios, cases.SSTTestCase, | ||
261 | 251 | logging.LogHandlerTestCase): | ||
262 | 252 | |||
263 | 253 | scenarios = [ | ||
264 | 254 | ('ubuntuone brand', {'brand': 'ubuntuone'}), | ||
265 | 255 | ('other brand', {'brand': 'other'}), | ||
266 | 256 | ] | ||
267 | 257 | |||
268 | 258 | xserver_headless = True | ||
269 | 259 | |||
270 | 260 | def setUp(self): | ||
271 | 261 | self.base_url = 'file://' | ||
272 | 262 | super(SignInTestCase, self).setUp() | ||
273 | 82 | 263 | ||
274 | 83 | def test_sign_in_with_already_signed_user_to_site_recognized(self): | 264 | def test_sign_in_with_already_signed_user_to_site_recognized(self): |
275 | 84 | # Sign in will do nothing. | 265 | # Sign in will do nothing. |
276 | 85 | sso_sst.sign_in(user=None, is_site_recognized=True) | 266 | sso_sst.sign_in(user=None, is_site_recognized=True) |
277 | 86 | 267 | ||
278 | 87 | def test_sign_in_with_already_signed_user_to_site_not_recognized(self): | 268 | def test_sign_in_with_already_signed_user_to_site_not_recognized(self): |
291 | 88 | self._write_fake_site_not_recognized_page(open_page=True) | 269 | with FakeSSOWebsite( |
292 | 89 | sso_sst.sign_in(user=None, is_site_recognized=False) | 270 | is_user_logged_in=True, is_site_recognized=False, |
293 | 90 | 271 | brand=self.brand): | |
294 | 91 | def _write_fake_site_not_recognized_page(self, open_page, token='token'): | 272 | sso_sst.sign_in(user=None, is_site_recognized=False) |
283 | 92 | token_directory = os.path.join(self.temp_directory, token) | ||
284 | 93 | os.mkdir(token_directory) | ||
285 | 94 | site_not_recognized_page_path = os.path.join( | ||
286 | 95 | token_directory, '+decide') | ||
287 | 96 | u1testutils.sst.StringHTMLPage( | ||
288 | 97 | _SITE_NOT_RECOGNIZED_PAGE_SOURCE, site_not_recognized_page_path, | ||
289 | 98 | qa_anchor='decide', open_page=open_page) | ||
290 | 99 | return site_not_recognized_page_path | ||
295 | 100 | 273 | ||
296 | 101 | def test_sign_in_to_site_recognized(self): | 274 | def test_sign_in_to_site_recognized(self): |
297 | 102 | self._write_fake_log_in_page(open_page=True) | ||
298 | 103 | user = data.User.make_unique() | 275 | user = data.User.make_unique() |
315 | 104 | 276 | with FakeSSOWebsite( | |
316 | 105 | sso_sst.sign_in(user, is_site_recognized=True) | 277 | is_user_logged_in=False, is_site_recognized=True, |
317 | 106 | 278 | brand=self.brand): | |
318 | 107 | def _write_fake_log_in_page( | 279 | sso_sst.sign_in(user, is_site_recognized=True) |
303 | 108 | self, open_page, token='token', | ||
304 | 109 | site_not_recognized_page_path=None): | ||
305 | 110 | log_in_page_source = _LOGIN_FROM_REDIRECT_PAGE_SOURCE | ||
306 | 111 | if site_not_recognized_page_path is not None: | ||
307 | 112 | log_in_page_source = log_in_page_source.format( | ||
308 | 113 | site_not_recognized_page_path) | ||
309 | 114 | token_directory = os.path.join(self.temp_directory, token) | ||
310 | 115 | os.mkdir(token_directory) | ||
311 | 116 | log_in_page_path = os.path.join(token_directory, '+decide') | ||
312 | 117 | u1testutils.sst.StringHTMLPage( | ||
313 | 118 | log_in_page_source, log_in_page_path, qa_anchor='login', | ||
314 | 119 | open_page=open_page) | ||
319 | 120 | 280 | ||
320 | 121 | def test_sign_in_to_site_not_recognized(self): | 281 | def test_sign_in_to_site_not_recognized(self): |
321 | 122 | self._write_fake_log_in_to_site_not_recognized_pages(open_page=True) | ||
322 | 123 | user = data.User.make_unique() | 282 | user = data.User.make_unique() |
338 | 124 | 283 | with FakeSSOWebsite( | |
339 | 125 | sso_sst.sign_in(user, is_site_recognized=False) | 284 | is_user_logged_in=False, is_site_recognized=False, |
340 | 126 | 285 | brand=self.brand): | |
341 | 127 | def _write_fake_log_in_to_site_not_recognized_pages(self, open_page): | 286 | sso_sst.sign_in(user, is_site_recognized=False) |
327 | 128 | # We do not check the tokens, so the easiest thing is to have the | ||
328 | 129 | # two pages in separate paths, to write both to HTML files and be able | ||
329 | 130 | # to open the second from the first. In real life, the tokens are the | ||
330 | 131 | # same. To check the token can be a future improvement. | ||
331 | 132 | # -- elopio - 2013-07-03 | ||
332 | 133 | site_not_recognized_page_path = ( | ||
333 | 134 | self._write_fake_site_not_recognized_page( | ||
334 | 135 | open_page=False, token='not_recognized')) | ||
335 | 136 | self._write_fake_log_in_page( | ||
336 | 137 | open_page=open_page, token='login', | ||
337 | 138 | site_not_recognized_page_path=site_not_recognized_page_path) | ||
342 | 139 | 287 | ||
343 | 140 | def test_sign_in_with_unexpected_site_not_recognized(self): | 288 | def test_sign_in_with_unexpected_site_not_recognized(self): |
354 | 141 | self._write_fake_log_in_to_site_not_recognized_pages(open_page=True) | 289 | user = data.User.make_unique() |
355 | 142 | user = data.User.make_unique() | 290 | with FakeSSOWebsite( |
356 | 143 | 291 | is_user_logged_in=False, is_site_recognized=False, | |
357 | 144 | self.assertRaises( | 292 | brand=self.brand): |
358 | 145 | AssertionError, sso_sst.sign_in, user, is_site_recognized=True) | 293 | self.assertRaises( |
359 | 146 | self.assertLogLevelContains( | 294 | AssertionError, sso_sst.sign_in, user, is_site_recognized=True) |
360 | 147 | 'ERROR', | 295 | self.assertLogLevelContains( |
361 | 148 | 'Please check that you are logging in from a server that is ' | 296 | 'ERROR', |
362 | 149 | 'trusted by SSO. Otherwise, the unexpected Site Not Recognized ' | 297 | 'Please check that you are accessing SSO from a server that is ' |
363 | 150 | 'page will be opened.' | 298 | 'trusted. Otherwise, the unexpected Site Not Recognized page will ' |
364 | 299 | 'be opened.' | ||
365 | 300 | ) | ||
366 | 301 | |||
367 | 302 | |||
368 | 303 | class CreateNewAccountTestCase( | ||
369 | 304 | testscenarios.TestWithScenarios, cases.SSTTestCase, | ||
370 | 305 | logging.LogHandlerTestCase): | ||
371 | 306 | |||
372 | 307 | scenarios = [ | ||
373 | 308 | ('ubuntuone brand', {'brand': 'ubuntuone'}), | ||
374 | 309 | ('other brand', {'brand': 'other'}), | ||
375 | 310 | ] | ||
376 | 311 | |||
377 | 312 | xserver_headless = True | ||
378 | 313 | |||
379 | 314 | def setUp(self): | ||
380 | 315 | self.temp_directory = tempfile.mkdtemp() | ||
381 | 316 | self.addCleanup(shutil.rmtree, self.temp_directory) | ||
382 | 317 | self.base_url = 'file://' + self.temp_directory | ||
383 | 318 | super(CreateNewAccountTestCase, self).setUp() | ||
384 | 319 | |||
385 | 320 | def test_create_account_to_site_recognized(self): | ||
386 | 321 | user = data.User.make_unique() | ||
387 | 322 | with FakeSSOWebsite( | ||
388 | 323 | is_user_logged_in=False, is_site_recognized=True, | ||
389 | 324 | brand=self.brand): | ||
390 | 325 | sso_sst.create_new_account(user, is_site_recognized=True) | ||
391 | 326 | |||
392 | 327 | def test_create_account_to_site_not_recognized(self): | ||
393 | 328 | user = data.User.make_unique() | ||
394 | 329 | with FakeSSOWebsite( | ||
395 | 330 | is_user_logged_in=False, is_site_recognized=False, | ||
396 | 331 | brand=self.brand): | ||
397 | 332 | sso_sst.create_new_account(user, is_site_recognized=False) | ||
398 | 333 | |||
399 | 334 | def test_create_account_with_unexpected_site_not_recognized(self): | ||
400 | 335 | user = data.User.make_unique() | ||
401 | 336 | with FakeSSOWebsite( | ||
402 | 337 | is_user_logged_in=False, is_site_recognized=False, | ||
403 | 338 | brand=self.brand): | ||
404 | 339 | self.assertRaises( | ||
405 | 340 | AssertionError, sso_sst.create_new_account, user, | ||
406 | 341 | is_site_recognized=True) | ||
407 | 342 | self.assertLogLevelContains( | ||
408 | 343 | 'ERROR', | ||
409 | 344 | 'Please check that you are accessing SSO from a server that is ' | ||
410 | 345 | 'trusted. Otherwise, the unexpected Site Not Recognized page will ' | ||
411 | 346 | 'be opened.' | ||
412 | 151 | ) | 347 | ) |
413 | 152 | 348 | ||
414 | === modified file 'u1testutils/sso/sst/__init__.py' | |||
415 | --- u1testutils/sso/sst/__init__.py 2013-07-03 07:50:35 +0000 | |||
416 | +++ u1testutils/sso/sst/__init__.py 2013-07-06 07:12:27 +0000 | |||
417 | @@ -49,6 +49,20 @@ | |||
418 | 49 | site_not_recognized = pages.SiteNotRecognized() | 49 | site_not_recognized = pages.SiteNotRecognized() |
419 | 50 | site_not_recognized.make_all_information_available_to_website() | 50 | site_not_recognized.make_all_information_available_to_website() |
420 | 51 | site_not_recognized.yes_sign_me_in() | 51 | site_not_recognized.yes_sign_me_in() |
421 | 52 | else: | ||
422 | 53 | _assert_site_not_recognized_page_not_opened() | ||
423 | 54 | |||
424 | 55 | |||
425 | 56 | def _assert_site_not_recognized_page_not_opened(): | ||
426 | 57 | try: | ||
427 | 58 | sst.actions.fails(pages.SiteNotRecognized) | ||
428 | 59 | except AssertionError: | ||
429 | 60 | suggestion = ( | ||
430 | 61 | 'Please check that you are accessing SSO from a server that is ' | ||
431 | 62 | 'trusted. Otherwise, the unexpected Site Not Recognized page will ' | ||
432 | 63 | 'be opened.') | ||
433 | 64 | logger.error(suggestion) | ||
434 | 65 | raise | ||
435 | 52 | 66 | ||
436 | 53 | 67 | ||
437 | 54 | def validate_user_email(user): | 68 | def validate_user_email(user): |
438 | @@ -109,18 +123,6 @@ | |||
439 | 109 | site_not_recognized.yes_sign_me_in() | 123 | site_not_recognized.yes_sign_me_in() |
440 | 110 | 124 | ||
441 | 111 | 125 | ||
442 | 112 | def _assert_site_not_recognized_page_not_opened(): | ||
443 | 113 | try: | ||
444 | 114 | sst.actions.fails(pages.SiteNotRecognized) | ||
445 | 115 | except AssertionError: | ||
446 | 116 | suggestion = ( | ||
447 | 117 | 'Please check that you are logging in from a server that is ' | ||
448 | 118 | 'trusted by SSO. Otherwise, the unexpected Site Not Recognized ' | ||
449 | 119 | 'page will be opened.') | ||
450 | 120 | logger.error(suggestion) | ||
451 | 121 | raise | ||
452 | 122 | |||
453 | 123 | |||
454 | 124 | def log_out(): | 126 | def log_out(): |
455 | 125 | """Log out from the Ubuntu Single Sign On site. | 127 | """Log out from the Ubuntu Single Sign On site. |
456 | 126 | 128 |
218 + def __exit__(self, exc_type, exc_val, exc_tb): rmtree( self.temp_ directory)
219 + shutil.
That would be easier to find (and to think about) if it was closer to __enter__.
222 +class WrongSSOSiteTes tCase(cases. SSTTestCase) :
Nice simplifications in these tests !