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

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 76
Merged at revision: 50
Proposed branch: lp:~elopio/u1-test-utils/url_paths_no_regexp
Merge into: lp:u1-test-utils
Prerequisite: lp:~elopio/u1-test-utils/sso-helpers
Diff against target: 230 lines (+49/-46)
4 files modified
u1testutils/sso/sst/pages.py (+9/-27)
u1testutils/sst/__init__.py (+24/-13)
u1testutils/sst/selftests/acceptance/test_page.py (+11/-0)
u1testutils/sst/selftests/unit/test_pages.py (+5/-6)
To merge this branch: bzr merge lp:~elopio/u1-test-utils/url_paths_no_regexp
Reviewer Review Type Date Requested Status
Corey Goldberg (community) Approve
Review via email: mp+159210@code.launchpad.net

Commit message

Changed the implementation of regex in url paths.

To post a comment you must log in.
Revision history for this message
Corey Goldberg (coreygoldberg) wrote :

better.. thanks

review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'u1testutils/sso/sst/pages.py'
2--- u1testutils/sso/sst/pages.py 2013-04-16 18:41:26 +0000
3+++ u1testutils/sso/sst/pages.py 2013-04-16 18:41:26 +0000
4@@ -117,7 +117,7 @@
5 """
6
7 title = 'Create account'
8- url_path = '/\+new_account'
9+ url_path = '/+new_account'
10 headings1 = ['Ubuntu Single Sign On', 'Create an account']
11
12 @log_action(logging.info)
13@@ -158,7 +158,7 @@
14 """
15
16 title = 'Account creation mail sent'
17- url_path = '/\+new_account'
18+ url_path = '/+new_account'
19 headings1 = ['Account creation mail sent']
20 headings2 = ["Haven't received it?"]
21
22@@ -229,23 +229,15 @@
23 This is a subclass of the Page object. It adds methods for the actions
24 available in this page.
25
26- Instance variables:
27- title -- The title of the page.
28- url_path -- The path of the page.
29-
30 """
31
32 title = "Complete email address validation"
33- url_path = '/token/.*/\+newemail/.*@.*'
34+ url_path = '/token/.+/\+newemail/.+@.+'
35+ is_url_path_regex = True
36
37 def __init__(self, check=True):
38 super(CompleteEmailValidation, self).__init__(check)
39
40- def open_page(self, check=True):
41- # TODO we can receive the token and email as parameters.
42- # Currently not needed.
43- raise NotImplementedError('Not yet implemented.')
44-
45 def _click_continue_button(self):
46 continue_button = sst.actions.get_element(css_class='btn',
47 name='continue')
48@@ -274,20 +266,13 @@
49 method to check only the first part of the title, and adds methods for the
50 actions available in this page.
51
52- Instance variables:
53- title -- The regular expression of the title of the page.
54- url_path -- The path of the page.
55-
56 """
57
58 title = '^Authenticate to .+'
59- url_path = '/.*/\+decide'
60-
61- def open_page(self, check=True):
62- # TODO we can receive the token as parameter. Currently not needed.
63- raise NotImplementedError('Not yet implemented.')
64-
65- def assert_page_is_open(self):
66+ url_path = '/.+/\+decide'
67+ is_url_path_regex = True
68+
69+ def assert_title(self):
70 """Assert that the page is open.
71
72 We use a regular expression because the title has the URL of the site
73@@ -332,9 +317,6 @@
74 Instance variables:
75 title -- The title of the page. It's build when the page is instantiated
76 using the user name.
77- url_path -- The path of the page.
78- sub_header -- The sub header menu displayed on the pages shown to logged
79- in users.
80
81 """
82
83@@ -350,5 +332,5 @@
84 """Your account page of the Ubuntu Single Sign On website."""
85
86 title = 'You have been logged out'
87- url_path = '/\+logout'
88+ url_path = '/+logout'
89 headings1 = ['Ubuntu Single Sign On', 'You have been logged out']
90
91=== modified file 'u1testutils/sst/__init__.py'
92--- u1testutils/sst/__init__.py 2013-04-16 18:41:26 +0000
93+++ u1testutils/sst/__init__.py 2013-04-16 18:41:26 +0000
94@@ -51,10 +51,9 @@
95
96 Instance variables:
97 title -- The title of the page.
98- url_path -- The path of the page. It is a regular expression, so you can
99- use python's re special characters, but you will have to escape them
100- if they are part of the path. The URL structure is explained in the
101- documentation of python's urlparse.
102+ url_path -- The path of the page.
103+ is_url_path_regex -- If True, the url path will be considered as a regular
104+ expression.
105 headings1 -- A list with the expected text of the h1 elements. If it's
106 empty, the h1 elements will not be checked.
107 headings2 -- A list with the expected text of the h2 elements. If it's
108@@ -64,6 +63,7 @@
109
110 title = None
111 url_path = None
112+ is_url_path_regex = False
113 headings1 = []
114 headings2 = []
115
116@@ -75,13 +75,15 @@
117 @log_action(logging.info)
118 def open_page(self, check=True):
119 """Open the page."""
120- assert self.url_path is not None
121- # We need to remove the \ used to escape the special characters of the
122- # path.
123- sst.actions.go_to(self.url_path.replace('\\', ''))
124- if check:
125- self.assert_page_is_open()
126- return self
127+ if self.is_url_path_regex:
128+ raise ValueError(
129+ "We can't open a page with a regular expression on the path.")
130+ else:
131+ assert self.url_path is not None
132+ sst.actions.go_to(self.url_path)
133+ if check:
134+ self.assert_page_is_open()
135+ return self
136
137 def assert_page_is_open(self):
138 """Assert that the page is open and that no oops are displayed."""
139@@ -117,14 +119,23 @@
140
141 def assert_url_path(self):
142 """Assert the path of the page URL."""
143- current_url = sst.actions.get_current_url()
144- current_url_path = urlparse.urlparse(current_url).path
145+ if not self.is_url_path_regex:
146+ assert self.url_path == self._get_current_url_path()
147+ else:
148+ self._assert_url_path_match()
149+
150+ def _assert_url_path_match(self):
151 # Make sure that there are no more characters at the end of the path.
152 url_path_regexp = self.url_path + '$'
153+ current_url_path = self._get_current_url_path()
154 assert re.match(url_path_regexp, current_url_path), \
155 "The current URL path {0} doesn't match {1}".format(
156 current_url_path, url_path_regexp)
157
158+ def _get_current_url_path(self):
159+ current_url = sst.actions.get_current_url()
160+ return urlparse.urlparse(current_url).path
161+
162 def assert_headings1(self):
163 """Assert the h1 elements of the page."""
164 self._assert_elements_text('h1', self.headings1)
165
166=== modified file 'u1testutils/sst/selftests/acceptance/test_page.py'
167--- u1testutils/sst/selftests/acceptance/test_page.py 2013-04-16 18:41:26 +0000
168+++ u1testutils/sst/selftests/acceptance/test_page.py 2013-04-16 18:41:26 +0000
169@@ -95,6 +95,15 @@
170 self.page.open_page()
171 self.page.assert_page_is_open()
172
173+ def test_assert_page_with_url_path_regexp(self):
174+ self.page.title = 'Test title'
175+ self.page.url_path = '.+'
176+ self.page.is_url_path_regex = True
177+ self.page.headings1 = ['Test h1 1', 'Test h1 2']
178+ self.page.headings2 = ['Test h2 1', 'Test h2 2']
179+ self.page.open_page()
180+ self.page.assert_page_is_open()
181+
182 def test_wrong_title(self):
183 self.page.title = 'Wrong title'
184 self.assertRaises(AssertionError, self.page.assert_title)
185@@ -105,6 +114,7 @@
186
187 def test_wrong_url_path_with_a_match(self):
188 self.page.url_path = '/test_path'
189+ self.page.is_url_path_regex = True
190 with mock.patch('sst.actions.get_current_url') as mock_action:
191 mock_url = 'http://test_netloc/wrong/test_path/wrong'
192 mock_action.return_value = mock_url
193@@ -112,6 +122,7 @@
194
195 def test_wrong_url_path_with_a_suffix(self):
196 self.page.url_path = '/test_path'
197+ self.page.is_url_path_regex = True
198 with mock.patch('sst.actions.get_current_url') as mock_action:
199 mock_url = 'http://test_netloc/test_path/wrong'
200 mock_action.return_value = mock_url
201
202=== modified file 'u1testutils/sst/selftests/unit/test_pages.py'
203--- u1testutils/sst/selftests/unit/test_pages.py 2013-04-16 18:41:26 +0000
204+++ u1testutils/sst/selftests/unit/test_pages.py 2013-04-16 18:41:26 +0000
205@@ -55,7 +55,7 @@
206 page.open_page()
207 mock_assert.assert_called_once_with()
208
209- def test_open_page_wihtout_check(self):
210+ def test_open_page_without_check(self):
211 self.create_patch('sst.actions.go_to')
212 with mock.patch.object(Page, 'assert_page_is_open') as mock_assert:
213 page = Page(check=False)
214@@ -68,12 +68,11 @@
215 page.url_path = None
216 self.assertRaises(AssertionError, page.open_page)
217
218- def test_open_page_with_special_character_in_url_path(self):
219+ def test_open_page_with_path_regex(self):
220 page = Page(check=False)
221- page.url_path = '/test/\+path'
222- with mock.patch('sst.actions.go_to') as mock_action:
223- page.open_page(check=False)
224- mock_action.assert_called_with('/test/+path')
225+ page.url_path = '/test/.*'
226+ page.is_url_path_regex = True
227+ self.assertRaises(ValueError, page.open_page)
228
229
230 class PageWithOnlyHeadingsAssertions(Page):

Subscribers

People subscribed via source and target branches

to all changes: