Merge lp:~elopio/u1-test-utils/assert_page_path into lp:u1-test-utils

Proposed by Leo Arias
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
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.

To post a comment you must log in.
47. By Leo Arias

Stricter match for the url_path.

48. By Leo Arias

Make sure the path doesn't have prefix or suffix.

49. By Leo Arias

Escape the sso page paths.

50. By Leo Arias

Escape the sso page paths.

Revision history for this message
Matias Bordese (matiasb) wrote :

+1

review: Approve
Revision history for this message
Leo Arias (elopio) wrote :
Download full text (3.3 KiB)

<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_url_path='/123/testing/test' and url_path='/321/testing/test', right? but maybe that's not a problem, I guess
<matiasb> sorry, url_path='/testing/test'
<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(current_url_path, self.url_path) sounds good
<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(self.url_path, current_url_path), the pattern first)
<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 +?...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'u1testutils/sst/__init__.py'
--- u1testutils/sst/__init__.py 2013-04-05 06:06:38 +0000
+++ u1testutils/sst/__init__.py 2013-04-10 19:49:23 +0000
@@ -13,6 +13,8 @@
13# with this program. If not, see <http://www.gnu.org/licenses/>.13# with this program. If not, see <http://www.gnu.org/licenses/>.
1414
15import logging15import logging
16import re
17import urlparse
1618
17import sst.actions19import sst.actions
1820
@@ -25,6 +27,10 @@
2527
26 Instance variables:28 Instance variables:
27 title -- The title of the page.29 title -- The title of the page.
30 url_path -- The path of the page. It is a regular expression, so you can
31 use python's re special characters, but you will have to escape them
32 if they are part of the path. The URL structure is explained in the
33 documentation of python's urlparse.
28 headings1 -- A list with the expected text of the h1 elements. If it's34 headings1 -- A list with the expected text of the h1 elements. If it's
29 empty, the h1 elements will not be checked.35 empty, the h1 elements will not be checked.
30 headings2 -- A list with the expected text of the h2 elements. If it's36 headings2 -- A list with the expected text of the h2 elements. If it's
@@ -33,6 +39,7 @@
33 """39 """
3440
35 title = None41 title = None
42 url_path = None
36 headings1 = []43 headings1 = []
37 headings2 = []44 headings2 = []
3845
@@ -48,6 +55,7 @@
48 'An oops error is displayed: {0}'.format(55 'An oops error is displayed: {0}'.format(
49 self._get_oops_element().text)56 self._get_oops_element().text)
50 self.assert_title()57 self.assert_title()
58 self.assert_url_path()
51 if self.headings1:59 if self.headings1:
52 self.assert_headings1()60 self.assert_headings1()
53 if self.headings2:61 if self.headings2:
@@ -69,8 +77,17 @@
69 return sst.actions.get_element(css_class=oops_class)77 return sst.actions.get_element(css_class=oops_class)
7078
71 def assert_title(self):79 def assert_title(self):
80 """Assert the title of the page."""
72 sst.actions.assert_title(self.title)81 sst.actions.assert_title(self.title)
7382
83 def assert_url_path(self):
84 """Assert the path of the page URL."""
85 current_url = sst.actions.browser.current_url
86 current_url_path = urlparse.urlparse(current_url).path
87 # Make sure that there are no more characters at the end of the path.
88 url_path_regexp = self.url_path + '$'
89 assert re.match(url_path_regexp, current_url_path)
90
74 def assert_headings1(self):91 def assert_headings1(self):
75 """Assert the h1 elements of the page."""92 """Assert the h1 elements of the page."""
76 self._assert_elements_text('h1', self.headings1)93 self._assert_elements_text('h1', self.headings1)
7794
=== modified file 'u1testutils/sst/selftests/acceptance/test_page.py'
--- u1testutils/sst/selftests/acceptance/test_page.py 2013-04-05 06:06:38 +0000
+++ u1testutils/sst/selftests/acceptance/test_page.py 2013-04-10 19:49:23 +0000
@@ -16,6 +16,7 @@
16import tempfile16import tempfile
1717
18import bs418import bs4
19import mock
19import sst.runtests20import sst.runtests
20from testtools.matchers import Contains21from testtools.matchers import Contains
2122
@@ -35,6 +36,7 @@
35 if not page_source:36 if not page_source:
36 page_source = self.page_source37 page_source = self.page_source
37 page_file = tempfile.NamedTemporaryFile(delete=False)38 page_file = tempfile.NamedTemporaryFile(delete=False)
39 self.url_path = page_file.name
38 page_file.write(page_source)40 page_file.write(page_source)
39 page_file.close()41 page_file.close()
40 sst.actions.go_to('file://{0}'.format(page_file.name))42 sst.actions.go_to('file://{0}'.format(page_file.name))
@@ -97,6 +99,30 @@
97 self.page.title = 'Wrong title'99 self.page.title = 'Wrong title'
98 self.assertRaises(AssertionError, self.page.assert_title)100 self.assertRaises(AssertionError, self.page.assert_title)
99101
102 def test_wrong_url_path(self):
103 self.page.url_path = 'Wrong path'
104 self.assertRaises(AssertionError, self.page.assert_url_path)
105
106 def test_wrong_url_path_with_a_match(self):
107 self.page.url_path = '/test_path'
108 with mock.patch('sst.actions.browser') as mock_browser:
109 mock_url = 'http://test_netloc/wrong/test_path/wrong'
110 mock_browser.current_url = mock_url
111 self.assertRaises(AssertionError, self.page.assert_url_path)
112
113 def test_wrong_url_path_with_a_suffix(self):
114 self.page.url_path = '/test_path'
115 with mock.patch('sst.actions.browser') as mock_browser:
116 mock_url = 'http://test_netloc/test_path/wrong'
117 mock_browser.current_url = mock_url
118 self.assertRaises(AssertionError, self.page.assert_url_path)
119
120 def test_assert_url_path_with_query(self):
121 self.page.url_path = '/test_path'
122 with mock.patch('sst.actions.browser') as mock_browser:
123 mock_browser.current_url = 'http://test_netloc/test_path?query'
124 self.page.assert_url_path()
125
100 def test_wrong_headings1_text(self):126 def test_wrong_headings1_text(self):
101 self.page.headings1 = ['Test h1 1', 'Wrong h1']127 self.page.headings1 = ['Test h1 1', 'Wrong h1']
102 self.page.open_page()128 self.page.open_page()
@@ -123,8 +149,10 @@
123 soup.body.append(oops_element)149 soup.body.append(oops_element)
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.
125 self.page.assert_title = lambda: None151 self.page.assert_title = lambda: None
152 self.page.assert_url_path = lambda: None
126 self.page.headings1 = []153 self.page.headings1 = []
127 self.page.headings2 = []154 self.page.headings2 = []
155
128 self.page.open_page(page_source=str(soup))156 self.page.open_page(page_source=str(soup))
129 error = self.assertRaises(157 error = self.assertRaises(
130 AssertionError, self.page.assert_page_is_open)158 AssertionError, self.page.assert_page_is_open)
131159
=== modified file 'u1testutils/sst/selftests/unit/test_pages.py'
--- u1testutils/sst/selftests/unit/test_pages.py 2013-04-05 05:19:12 +0000
+++ u1testutils/sst/selftests/unit/test_pages.py 2013-04-10 19:49:23 +0000
@@ -36,6 +36,9 @@
36 def assert_title(self):36 def assert_title(self):
37 pass37 pass
3838
39 def assert_url_path(self):
40 pass
41
39 def _is_oops_displayed(self):42 def _is_oops_displayed(self):
40 pass43 pass
4144
4245
=== modified file 'u1testutils/sst/sso/pages.py'
--- u1testutils/sst/sso/pages.py 2013-03-26 16:00:53 +0000
+++ u1testutils/sst/sso/pages.py 2013-04-10 19:49:23 +0000
@@ -26,10 +26,12 @@
2626
27 Instance variables:27 Instance variables:
28 title -- The title of the page.28 title -- The title of the page.
29 url_path -- The path of the page.
2930
30 """31 """
3132
32 title = 'Log in'33 title = 'Log in'
34 url_path = '/'
3335
34 def assert_page_is_open(self):36 def assert_page_is_open(self):
35 """Assert that the page is open."""37 """Assert that the page is open."""
@@ -100,10 +102,12 @@
100102
101 Instance variables:103 Instance variables:
102 title -- The title of the page.104 title -- The title of the page.
105 url_path -- The path of the page.
103106
104 """107 """
105108
106 title = 'Create account'109 title = 'Create account'
110 url_path = '/\+new_account'
107111
108 def create_ubuntu_sso_account(self, user):112 def create_ubuntu_sso_account(self, user):
109 """Fill the new account form and continue to the next step.113 """Fill the new account form and continue to the next step.
@@ -136,10 +140,12 @@
136140
137 Instance variables:141 Instance variables:
138 title -- The title of the page.142 title -- The title of the page.
143 url_path -- The path of the page.
139144
140 """145 """
141146
142 title = 'Registration mail sent'147 title = 'Registration mail sent'
148 url_path = '/\+new_account'
143149
144 def confirm_email_to_site_recognized(self, confirmation_code):150 def confirm_email_to_site_recognized(self, confirmation_code):
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.
@@ -189,10 +195,12 @@
189195
190 Instance variables:196 Instance variables:
191 title -- The title of the page.197 title -- The title of the page.
198 url_path -- The path of the page.
192199
193 """200 """
194201
195 title = "Complete email address validation"202 title = "Complete email address validation"
203 url_path = '/token/.*/\+newemail/*.@*.'
196204
197 def __init__(self, user_name):205 def __init__(self, user_name):
198 self.user_name = user_name206 self.user_name = user_name
@@ -224,10 +232,12 @@
224232
225 Instance variables:233 Instance variables:
226 title -- The regular expression of the title of the page.234 title -- The regular expression of the title of the page.
235 url_path -- The path of the page.
227236
228 """237 """
229238
230 title = 'Authenticate to .+'239 title = 'Authenticate to .+'
240 url_path = '/.*/\+decide'
231241
232 def assert_page_is_open(self):242 def assert_page_is_open(self):
233 """Assert that the page is open.243 """Assert that the page is open.
@@ -272,12 +282,14 @@
272 Instance variables:282 Instance variables:
273 title -- The title of the page. It's build when the page is instantiated283 title -- The title of the page. It's build when the page is instantiated
274 using the user name.284 using the user name.
285 url_path -- The path of the page.
275 sub_header -- The sub header menu displayed on the pages shown to logged286 sub_header -- The sub header menu displayed on the pages shown to logged
276 in users.287 in users.
277288
278 """289 """
279290
280 title = "{0}'s details"291 title = "{0}'s details"
292 url_path = '/'
281293
282 def __init__(self, user_name):294 def __init__(self, user_name):
283 self.title = self.title.format(user_name)295 self.title = self.title.format(user_name)
@@ -301,7 +313,9 @@
301 Instance variables:313 Instance variables:
302 title -- The title of the page. It's build when the page is instantiated314 title -- The title of the page. It's build when the page is instantiated
303 using the user name.315 using the user name.
316 url_path -- The path of the page.
304317
305 """318 """
306319
307 title = 'You have been logged out'320 title = 'You have been logged out'
321 url_path = '/\+logout'

Subscribers

People subscribed via source and target branches

to all changes: