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
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 # with this program. If not, see <http://www.gnu.org/licenses/>.
6
7 import logging
8+import re
9+import urlparse
10
11 import sst.actions
12
13@@ -25,6 +27,10 @@
14
15 Instance variables:
16 title -- The title of the page.
17+ url_path -- The path of the page. It is a regular expression, so you can
18+ use python's re special characters, but you will have to escape them
19+ if they are part of the path. The URL structure is explained in the
20+ documentation of python's urlparse.
21 headings1 -- A list with the expected text of the h1 elements. If it's
22 empty, the h1 elements will not be checked.
23 headings2 -- A list with the expected text of the h2 elements. If it's
24@@ -33,6 +39,7 @@
25 """
26
27 title = None
28+ url_path = None
29 headings1 = []
30 headings2 = []
31
32@@ -48,6 +55,7 @@
33 'An oops error is displayed: {0}'.format(
34 self._get_oops_element().text)
35 self.assert_title()
36+ self.assert_url_path()
37 if self.headings1:
38 self.assert_headings1()
39 if self.headings2:
40@@ -69,8 +77,17 @@
41 return sst.actions.get_element(css_class=oops_class)
42
43 def assert_title(self):
44+ """Assert the title of the page."""
45 sst.actions.assert_title(self.title)
46
47+ def assert_url_path(self):
48+ """Assert the path of the page URL."""
49+ current_url = sst.actions.browser.current_url
50+ current_url_path = urlparse.urlparse(current_url).path
51+ # Make sure that there are no more characters at the end of the path.
52+ url_path_regexp = self.url_path + '$'
53+ assert re.match(url_path_regexp, current_url_path)
54+
55 def assert_headings1(self):
56 """Assert the h1 elements of the page."""
57 self._assert_elements_text('h1', self.headings1)
58
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 import tempfile
64
65 import bs4
66+import mock
67 import sst.runtests
68 from testtools.matchers import Contains
69
70@@ -35,6 +36,7 @@
71 if not page_source:
72 page_source = self.page_source
73 page_file = tempfile.NamedTemporaryFile(delete=False)
74+ self.url_path = page_file.name
75 page_file.write(page_source)
76 page_file.close()
77 sst.actions.go_to('file://{0}'.format(page_file.name))
78@@ -97,6 +99,30 @@
79 self.page.title = 'Wrong title'
80 self.assertRaises(AssertionError, self.page.assert_title)
81
82+ def test_wrong_url_path(self):
83+ self.page.url_path = 'Wrong path'
84+ self.assertRaises(AssertionError, self.page.assert_url_path)
85+
86+ def test_wrong_url_path_with_a_match(self):
87+ self.page.url_path = '/test_path'
88+ with mock.patch('sst.actions.browser') as mock_browser:
89+ mock_url = 'http://test_netloc/wrong/test_path/wrong'
90+ mock_browser.current_url = mock_url
91+ self.assertRaises(AssertionError, self.page.assert_url_path)
92+
93+ def test_wrong_url_path_with_a_suffix(self):
94+ self.page.url_path = '/test_path'
95+ with mock.patch('sst.actions.browser') as mock_browser:
96+ mock_url = 'http://test_netloc/test_path/wrong'
97+ mock_browser.current_url = mock_url
98+ self.assertRaises(AssertionError, self.page.assert_url_path)
99+
100+ def test_assert_url_path_with_query(self):
101+ self.page.url_path = '/test_path'
102+ with mock.patch('sst.actions.browser') as mock_browser:
103+ mock_browser.current_url = 'http://test_netloc/test_path?query'
104+ self.page.assert_url_path()
105+
106 def test_wrong_headings1_text(self):
107 self.page.headings1 = ['Test h1 1', 'Wrong h1']
108 self.page.open_page()
109@@ -123,8 +149,10 @@
110 soup.body.append(oops_element)
111 # We don't need to make the assertions for the rest of the page.
112 self.page.assert_title = lambda: None
113+ self.page.assert_url_path = lambda: None
114 self.page.headings1 = []
115 self.page.headings2 = []
116+
117 self.page.open_page(page_source=str(soup))
118 error = self.assertRaises(
119 AssertionError, self.page.assert_page_is_open)
120
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 def assert_title(self):
126 pass
127
128+ def assert_url_path(self):
129+ pass
130+
131 def _is_oops_displayed(self):
132 pass
133
134
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
140 Instance variables:
141 title -- The title of the page.
142+ url_path -- The path of the page.
143
144 """
145
146 title = 'Log in'
147+ url_path = '/'
148
149 def assert_page_is_open(self):
150 """Assert that the page is open."""
151@@ -100,10 +102,12 @@
152
153 Instance variables:
154 title -- The title of the page.
155+ url_path -- The path of the page.
156
157 """
158
159 title = 'Create account'
160+ url_path = '/\+new_account'
161
162 def create_ubuntu_sso_account(self, user):
163 """Fill the new account form and continue to the next step.
164@@ -136,10 +140,12 @@
165
166 Instance variables:
167 title -- The title of the page.
168+ url_path -- The path of the page.
169
170 """
171
172 title = 'Registration mail sent'
173+ url_path = '/\+new_account'
174
175 def confirm_email_to_site_recognized(self, confirmation_code):
176 """Confirm email and continue to the site that requested the log in.
177@@ -189,10 +195,12 @@
178
179 Instance variables:
180 title -- The title of the page.
181+ url_path -- The path of the page.
182
183 """
184
185 title = "Complete email address validation"
186+ url_path = '/token/.*/\+newemail/*.@*.'
187
188 def __init__(self, user_name):
189 self.user_name = user_name
190@@ -224,10 +232,12 @@
191
192 Instance variables:
193 title -- The regular expression of the title of the page.
194+ url_path -- The path of the page.
195
196 """
197
198 title = 'Authenticate to .+'
199+ url_path = '/.*/\+decide'
200
201 def assert_page_is_open(self):
202 """Assert that the page is open.
203@@ -272,12 +282,14 @@
204 Instance variables:
205 title -- The title of the page. It's build when the page is instantiated
206 using the user name.
207+ url_path -- The path of the page.
208 sub_header -- The sub header menu displayed on the pages shown to logged
209 in users.
210
211 """
212
213 title = "{0}'s details"
214+ url_path = '/'
215
216 def __init__(self, user_name):
217 self.title = self.title.format(user_name)
218@@ -301,7 +313,9 @@
219 Instance variables:
220 title -- The title of the page. It's build when the page is instantiated
221 using the user name.
222+ url_path -- The path of the page.
223
224 """
225
226 title = 'You have been logged out'
227+ url_path = '/\+logout'

Subscribers

People subscribed via source and target branches

to all changes: