Merge lp:~elopio/u1-test-utils/assert_page_path into lp:u1-test-utils
- assert_page_path
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Leo Arias |
Approved revision: | 50 |
Merged at revision: | 44 |
Proposed branch: | lp:~elopio/u1-test-utils/assert_page_path |
Merge into: | lp:u1-test-utils |
Diff against target: |
227 lines (+62/-0) 4 files modified
u1testutils/sst/__init__.py (+17/-0) u1testutils/sst/selftests/acceptance/test_page.py (+28/-0) u1testutils/sst/selftests/unit/test_pages.py (+3/-0) u1testutils/sst/sso/pages.py (+14/-0) |
To merge this branch: | bzr merge lp:~elopio/u1-test-utils/assert_page_path |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matias Bordese (community) | Approve | ||
Review via email: mp+157784@code.launchpad.net |
Commit message
Added the path url to the page, and tests for it.
Description of the change
Leo Arias (elopio) wrote : | # |
<matiasb> elopio: on the first one, l.41, wondering if you can't know the url prefix at that point, instead of allowing anything as a url_path prefix (I guess url_path should be the path from /, but there may be a url suffix that matches a suffix of another url? or a login redirect, with a next via query string?)
<elopio> matiasb: I didn't understand the first part, but I think I understood the second.
<elopio> so, do you think it would be better to use urlparse and match just the path
<elopio> ?
<matiasb> elopio: yeah, maybe; wondering if it is worth it, but when I read that assert, I read it as check the url ends with url_path, so checking if that's enough
<elopio> nessita: they do. I'm wondering if it will work setting the info level as default. Would that be ok for you?
<matiasb> elopio: or maybe change the regex to force the match to match starting from the root, if that's not too complicated
<elopio> matiasb: I think it would be easier to get the path from urlparse, and then match the regex there.
<elopio> which makes me wonder if we should add helpers to check query strings and other stuff.
<elopio> but for now, I just want to check the url_path.
<matiasb> yeap, makes sense
<matiasb> elopio: +1 to the add_open_page one
<elopio> \o/
<elopio> matiasb: please take a look at the url_path assertion.
-*- matiasb looks
<matiasb> elopio: I think that would work better; but I think that would still work if current_
<matiasb> sorry, url_path=
<elopio> humph, that would be a problem.
<elopio> but easy fixable putting $ at the end of the url_path.
<elopio> matiasb: but the url_path is documented as a regexp. Should I hardcode the $ on the assert_url_path method, or should I define the url_path on the pages with '$'?
<matiasb> elopio: hmm... that makes sense; putting a ^ at the beginning and a $ at the end? (similar to django urls, indeed) I would add that to the url_path definition, to make it more flexible
<matiasb> and in that case you have a re.match instead of a re.search, heh
<elopio> matiasb: ok, but what to you mean with the url_path definition? in the actual page object instances and not in the base class?
<matiasb> (ie, using the regex with ^ and $ for re.search would be really a re.match without the ^ and $)
<elopio> matiasb: ah, yes, you are right.
<matiasb> I think, if it is not too restrictive, having re.match(
<elopio> but still I don't get what's the best solution for you.
<elopio> no, sounds fine for me. matiasb I'll add a test and change it.
<matiasb> ack, thanks
<matiasb> (it would be the other way round, indeed: re.match(
<elopio> matiasb: pushed. It seems that match takes care only of the ^, so I had to add the $
<matiasb> really? ok, looking
<elopio> matiasb: yes, the suffix test I added was failing.
<matiasb> elopio: ok, looks good :) you just need to escape the + in l.173 and l.227
<elopio> matiasb: good catch. I'll be struggling with that for some time :)
<elopio> pushed.
<matiasb> elopio: you missed one +?...
Preview Diff
1 | === modified file 'u1testutils/sst/__init__.py' | |||
2 | --- u1testutils/sst/__init__.py 2013-04-05 06:06:38 +0000 | |||
3 | +++ u1testutils/sst/__init__.py 2013-04-10 19:49:23 +0000 | |||
4 | @@ -13,6 +13,8 @@ | |||
5 | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
6 | 14 | 14 | ||
7 | 15 | import logging | 15 | import logging |
8 | 16 | import re | ||
9 | 17 | import urlparse | ||
10 | 16 | 18 | ||
11 | 17 | import sst.actions | 19 | import sst.actions |
12 | 18 | 20 | ||
13 | @@ -25,6 +27,10 @@ | |||
14 | 25 | 27 | ||
15 | 26 | Instance variables: | 28 | Instance variables: |
16 | 27 | title -- The title of the page. | 29 | title -- The title of the page. |
17 | 30 | url_path -- The path of the page. It is a regular expression, so you can | ||
18 | 31 | use python's re special characters, but you will have to escape them | ||
19 | 32 | if they are part of the path. The URL structure is explained in the | ||
20 | 33 | documentation of python's urlparse. | ||
21 | 28 | headings1 -- A list with the expected text of the h1 elements. If it's | 34 | headings1 -- A list with the expected text of the h1 elements. If it's |
22 | 29 | empty, the h1 elements will not be checked. | 35 | empty, the h1 elements will not be checked. |
23 | 30 | headings2 -- A list with the expected text of the h2 elements. If it's | 36 | headings2 -- A list with the expected text of the h2 elements. If it's |
24 | @@ -33,6 +39,7 @@ | |||
25 | 33 | """ | 39 | """ |
26 | 34 | 40 | ||
27 | 35 | title = None | 41 | title = None |
28 | 42 | url_path = None | ||
29 | 36 | headings1 = [] | 43 | headings1 = [] |
30 | 37 | headings2 = [] | 44 | headings2 = [] |
31 | 38 | 45 | ||
32 | @@ -48,6 +55,7 @@ | |||
33 | 48 | 'An oops error is displayed: {0}'.format( | 55 | 'An oops error is displayed: {0}'.format( |
34 | 49 | self._get_oops_element().text) | 56 | self._get_oops_element().text) |
35 | 50 | self.assert_title() | 57 | self.assert_title() |
36 | 58 | self.assert_url_path() | ||
37 | 51 | if self.headings1: | 59 | if self.headings1: |
38 | 52 | self.assert_headings1() | 60 | self.assert_headings1() |
39 | 53 | if self.headings2: | 61 | if self.headings2: |
40 | @@ -69,8 +77,17 @@ | |||
41 | 69 | return sst.actions.get_element(css_class=oops_class) | 77 | return sst.actions.get_element(css_class=oops_class) |
42 | 70 | 78 | ||
43 | 71 | def assert_title(self): | 79 | def assert_title(self): |
44 | 80 | """Assert the title of the page.""" | ||
45 | 72 | sst.actions.assert_title(self.title) | 81 | sst.actions.assert_title(self.title) |
46 | 73 | 82 | ||
47 | 83 | def assert_url_path(self): | ||
48 | 84 | """Assert the path of the page URL.""" | ||
49 | 85 | current_url = sst.actions.browser.current_url | ||
50 | 86 | current_url_path = urlparse.urlparse(current_url).path | ||
51 | 87 | # Make sure that there are no more characters at the end of the path. | ||
52 | 88 | url_path_regexp = self.url_path + '$' | ||
53 | 89 | assert re.match(url_path_regexp, current_url_path) | ||
54 | 90 | |||
55 | 74 | def assert_headings1(self): | 91 | def assert_headings1(self): |
56 | 75 | """Assert the h1 elements of the page.""" | 92 | """Assert the h1 elements of the page.""" |
57 | 76 | self._assert_elements_text('h1', self.headings1) | 93 | self._assert_elements_text('h1', self.headings1) |
58 | 77 | 94 | ||
59 | === modified file 'u1testutils/sst/selftests/acceptance/test_page.py' | |||
60 | --- u1testutils/sst/selftests/acceptance/test_page.py 2013-04-05 06:06:38 +0000 | |||
61 | +++ u1testutils/sst/selftests/acceptance/test_page.py 2013-04-10 19:49:23 +0000 | |||
62 | @@ -16,6 +16,7 @@ | |||
63 | 16 | import tempfile | 16 | import tempfile |
64 | 17 | 17 | ||
65 | 18 | import bs4 | 18 | import bs4 |
66 | 19 | import mock | ||
67 | 19 | import sst.runtests | 20 | import sst.runtests |
68 | 20 | from testtools.matchers import Contains | 21 | from testtools.matchers import Contains |
69 | 21 | 22 | ||
70 | @@ -35,6 +36,7 @@ | |||
71 | 35 | if not page_source: | 36 | if not page_source: |
72 | 36 | page_source = self.page_source | 37 | page_source = self.page_source |
73 | 37 | page_file = tempfile.NamedTemporaryFile(delete=False) | 38 | page_file = tempfile.NamedTemporaryFile(delete=False) |
74 | 39 | self.url_path = page_file.name | ||
75 | 38 | page_file.write(page_source) | 40 | page_file.write(page_source) |
76 | 39 | page_file.close() | 41 | page_file.close() |
77 | 40 | sst.actions.go_to('file://{0}'.format(page_file.name)) | 42 | sst.actions.go_to('file://{0}'.format(page_file.name)) |
78 | @@ -97,6 +99,30 @@ | |||
79 | 97 | self.page.title = 'Wrong title' | 99 | self.page.title = 'Wrong title' |
80 | 98 | self.assertRaises(AssertionError, self.page.assert_title) | 100 | self.assertRaises(AssertionError, self.page.assert_title) |
81 | 99 | 101 | ||
82 | 102 | def test_wrong_url_path(self): | ||
83 | 103 | self.page.url_path = 'Wrong path' | ||
84 | 104 | self.assertRaises(AssertionError, self.page.assert_url_path) | ||
85 | 105 | |||
86 | 106 | def test_wrong_url_path_with_a_match(self): | ||
87 | 107 | self.page.url_path = '/test_path' | ||
88 | 108 | with mock.patch('sst.actions.browser') as mock_browser: | ||
89 | 109 | mock_url = 'http://test_netloc/wrong/test_path/wrong' | ||
90 | 110 | mock_browser.current_url = mock_url | ||
91 | 111 | self.assertRaises(AssertionError, self.page.assert_url_path) | ||
92 | 112 | |||
93 | 113 | def test_wrong_url_path_with_a_suffix(self): | ||
94 | 114 | self.page.url_path = '/test_path' | ||
95 | 115 | with mock.patch('sst.actions.browser') as mock_browser: | ||
96 | 116 | mock_url = 'http://test_netloc/test_path/wrong' | ||
97 | 117 | mock_browser.current_url = mock_url | ||
98 | 118 | self.assertRaises(AssertionError, self.page.assert_url_path) | ||
99 | 119 | |||
100 | 120 | def test_assert_url_path_with_query(self): | ||
101 | 121 | self.page.url_path = '/test_path' | ||
102 | 122 | with mock.patch('sst.actions.browser') as mock_browser: | ||
103 | 123 | mock_browser.current_url = 'http://test_netloc/test_path?query' | ||
104 | 124 | self.page.assert_url_path() | ||
105 | 125 | |||
106 | 100 | def test_wrong_headings1_text(self): | 126 | def test_wrong_headings1_text(self): |
107 | 101 | self.page.headings1 = ['Test h1 1', 'Wrong h1'] | 127 | self.page.headings1 = ['Test h1 1', 'Wrong h1'] |
108 | 102 | self.page.open_page() | 128 | self.page.open_page() |
109 | @@ -123,8 +149,10 @@ | |||
110 | 123 | soup.body.append(oops_element) | 149 | soup.body.append(oops_element) |
111 | 124 | # We don't need to make the assertions for the rest of the page. | 150 | # We don't need to make the assertions for the rest of the page. |
112 | 125 | self.page.assert_title = lambda: None | 151 | self.page.assert_title = lambda: None |
113 | 152 | self.page.assert_url_path = lambda: None | ||
114 | 126 | self.page.headings1 = [] | 153 | self.page.headings1 = [] |
115 | 127 | self.page.headings2 = [] | 154 | self.page.headings2 = [] |
116 | 155 | |||
117 | 128 | self.page.open_page(page_source=str(soup)) | 156 | self.page.open_page(page_source=str(soup)) |
118 | 129 | error = self.assertRaises( | 157 | error = self.assertRaises( |
119 | 130 | AssertionError, self.page.assert_page_is_open) | 158 | AssertionError, self.page.assert_page_is_open) |
120 | 131 | 159 | ||
121 | === modified file 'u1testutils/sst/selftests/unit/test_pages.py' | |||
122 | --- u1testutils/sst/selftests/unit/test_pages.py 2013-04-05 05:19:12 +0000 | |||
123 | +++ u1testutils/sst/selftests/unit/test_pages.py 2013-04-10 19:49:23 +0000 | |||
124 | @@ -36,6 +36,9 @@ | |||
125 | 36 | def assert_title(self): | 36 | def assert_title(self): |
126 | 37 | pass | 37 | pass |
127 | 38 | 38 | ||
128 | 39 | def assert_url_path(self): | ||
129 | 40 | pass | ||
130 | 41 | |||
131 | 39 | def _is_oops_displayed(self): | 42 | def _is_oops_displayed(self): |
132 | 40 | pass | 43 | pass |
133 | 41 | 44 | ||
134 | 42 | 45 | ||
135 | === modified file 'u1testutils/sst/sso/pages.py' | |||
136 | --- u1testutils/sst/sso/pages.py 2013-03-26 16:00:53 +0000 | |||
137 | +++ u1testutils/sst/sso/pages.py 2013-04-10 19:49:23 +0000 | |||
138 | @@ -26,10 +26,12 @@ | |||
139 | 26 | 26 | ||
140 | 27 | Instance variables: | 27 | Instance variables: |
141 | 28 | title -- The title of the page. | 28 | title -- The title of the page. |
142 | 29 | url_path -- The path of the page. | ||
143 | 29 | 30 | ||
144 | 30 | """ | 31 | """ |
145 | 31 | 32 | ||
146 | 32 | title = 'Log in' | 33 | title = 'Log in' |
147 | 34 | url_path = '/' | ||
148 | 33 | 35 | ||
149 | 34 | def assert_page_is_open(self): | 36 | def assert_page_is_open(self): |
150 | 35 | """Assert that the page is open.""" | 37 | """Assert that the page is open.""" |
151 | @@ -100,10 +102,12 @@ | |||
152 | 100 | 102 | ||
153 | 101 | Instance variables: | 103 | Instance variables: |
154 | 102 | title -- The title of the page. | 104 | title -- The title of the page. |
155 | 105 | url_path -- The path of the page. | ||
156 | 103 | 106 | ||
157 | 104 | """ | 107 | """ |
158 | 105 | 108 | ||
159 | 106 | title = 'Create account' | 109 | title = 'Create account' |
160 | 110 | url_path = '/\+new_account' | ||
161 | 107 | 111 | ||
162 | 108 | def create_ubuntu_sso_account(self, user): | 112 | def create_ubuntu_sso_account(self, user): |
163 | 109 | """Fill the new account form and continue to the next step. | 113 | """Fill the new account form and continue to the next step. |
164 | @@ -136,10 +140,12 @@ | |||
165 | 136 | 140 | ||
166 | 137 | Instance variables: | 141 | Instance variables: |
167 | 138 | title -- The title of the page. | 142 | title -- The title of the page. |
168 | 143 | url_path -- The path of the page. | ||
169 | 139 | 144 | ||
170 | 140 | """ | 145 | """ |
171 | 141 | 146 | ||
172 | 142 | title = 'Registration mail sent' | 147 | title = 'Registration mail sent' |
173 | 148 | url_path = '/\+new_account' | ||
174 | 143 | 149 | ||
175 | 144 | def confirm_email_to_site_recognized(self, confirmation_code): | 150 | def confirm_email_to_site_recognized(self, confirmation_code): |
176 | 145 | """Confirm email and continue to the site that requested the log in. | 151 | """Confirm email and continue to the site that requested the log in. |
177 | @@ -189,10 +195,12 @@ | |||
178 | 189 | 195 | ||
179 | 190 | Instance variables: | 196 | Instance variables: |
180 | 191 | title -- The title of the page. | 197 | title -- The title of the page. |
181 | 198 | url_path -- The path of the page. | ||
182 | 192 | 199 | ||
183 | 193 | """ | 200 | """ |
184 | 194 | 201 | ||
185 | 195 | title = "Complete email address validation" | 202 | title = "Complete email address validation" |
186 | 203 | url_path = '/token/.*/\+newemail/*.@*.' | ||
187 | 196 | 204 | ||
188 | 197 | def __init__(self, user_name): | 205 | def __init__(self, user_name): |
189 | 198 | self.user_name = user_name | 206 | self.user_name = user_name |
190 | @@ -224,10 +232,12 @@ | |||
191 | 224 | 232 | ||
192 | 225 | Instance variables: | 233 | Instance variables: |
193 | 226 | title -- The regular expression of the title of the page. | 234 | title -- The regular expression of the title of the page. |
194 | 235 | url_path -- The path of the page. | ||
195 | 227 | 236 | ||
196 | 228 | """ | 237 | """ |
197 | 229 | 238 | ||
198 | 230 | title = 'Authenticate to .+' | 239 | title = 'Authenticate to .+' |
199 | 240 | url_path = '/.*/\+decide' | ||
200 | 231 | 241 | ||
201 | 232 | def assert_page_is_open(self): | 242 | def assert_page_is_open(self): |
202 | 233 | """Assert that the page is open. | 243 | """Assert that the page is open. |
203 | @@ -272,12 +282,14 @@ | |||
204 | 272 | Instance variables: | 282 | Instance variables: |
205 | 273 | title -- The title of the page. It's build when the page is instantiated | 283 | title -- The title of the page. It's build when the page is instantiated |
206 | 274 | using the user name. | 284 | using the user name. |
207 | 285 | url_path -- The path of the page. | ||
208 | 275 | sub_header -- The sub header menu displayed on the pages shown to logged | 286 | sub_header -- The sub header menu displayed on the pages shown to logged |
209 | 276 | in users. | 287 | in users. |
210 | 277 | 288 | ||
211 | 278 | """ | 289 | """ |
212 | 279 | 290 | ||
213 | 280 | title = "{0}'s details" | 291 | title = "{0}'s details" |
214 | 292 | url_path = '/' | ||
215 | 281 | 293 | ||
216 | 282 | def __init__(self, user_name): | 294 | def __init__(self, user_name): |
217 | 283 | self.title = self.title.format(user_name) | 295 | self.title = self.title.format(user_name) |
218 | @@ -301,7 +313,9 @@ | |||
219 | 301 | Instance variables: | 313 | Instance variables: |
220 | 302 | title -- The title of the page. It's build when the page is instantiated | 314 | title -- The title of the page. It's build when the page is instantiated |
221 | 303 | using the user name. | 315 | using the user name. |
222 | 316 | url_path -- The path of the page. | ||
223 | 304 | 317 | ||
224 | 305 | """ | 318 | """ |
225 | 306 | 319 | ||
226 | 307 | title = 'You have been logged out' | 320 | title = 'You have been logged out' |
227 | 321 | url_path = '/\+logout' |
+1