Show More
@@ -29,8 +29,6 b' from urllib import unquote_plus' | |||||
29 |
|
29 | |||
30 | import pytest |
|
30 | import pytest | |
31 | import rc_testdata |
|
31 | import rc_testdata | |
32 | from lxml.html import fromstring, tostring |
|
|||
33 | from lxml.cssselect import CSSSelector |
|
|||
34 |
|
32 | |||
35 | from rhodecode.model.db import User |
|
33 | from rhodecode.model.db import User | |
36 | from rhodecode.model.meta import Session |
|
34 | from rhodecode.model.meta import Session | |
@@ -134,6 +132,11 b' class AssertResponse(object):' | |||||
134 | def __init__(self, response): |
|
132 | def __init__(self, response): | |
135 | self.response = response |
|
133 | self.response = response | |
136 |
|
134 | |||
|
135 | def get_imports(self): | |||
|
136 | from lxml.html import fromstring, tostring | |||
|
137 | from lxml.cssselect import CSSSelector | |||
|
138 | return fromstring, tostring, CSSSelector | |||
|
139 | ||||
137 | def one_element_exists(self, css_selector): |
|
140 | def one_element_exists(self, css_selector): | |
138 | self.get_element(css_selector) |
|
141 | self.get_element(css_selector) | |
139 |
|
142 | |||
@@ -154,6 +157,7 b' class AssertResponse(object):' | |||||
154 | assert expected_content in element.value |
|
157 | assert expected_content in element.value | |
155 |
|
158 | |||
156 | def contains_one_link(self, link_text, href): |
|
159 | def contains_one_link(self, link_text, href): | |
|
160 | fromstring, tostring, CSSSelector = self.get_imports() | |||
157 | doc = fromstring(self.response.body) |
|
161 | doc = fromstring(self.response.body) | |
158 | sel = CSSSelector('a[href]') |
|
162 | sel = CSSSelector('a[href]') | |
159 | elements = [ |
|
163 | elements = [ | |
@@ -162,6 +166,7 b' class AssertResponse(object):' | |||||
162 | self._ensure_url_equal(elements[0].attrib.get('href'), href) |
|
166 | self._ensure_url_equal(elements[0].attrib.get('href'), href) | |
163 |
|
167 | |||
164 | def contains_one_anchor(self, anchor_id): |
|
168 | def contains_one_anchor(self, anchor_id): | |
|
169 | fromstring, tostring, CSSSelector = self.get_imports() | |||
165 | doc = fromstring(self.response.body) |
|
170 | doc = fromstring(self.response.body) | |
166 | sel = CSSSelector('#' + anchor_id) |
|
171 | sel = CSSSelector('#' + anchor_id) | |
167 | elements = sel(doc) |
|
172 | elements = sel(doc) | |
@@ -179,12 +184,14 b' class AssertResponse(object):' | |||||
179 | return self._get_elements(css_selector) |
|
184 | return self._get_elements(css_selector) | |
180 |
|
185 | |||
181 | def _get_elements(self, css_selector): |
|
186 | def _get_elements(self, css_selector): | |
|
187 | fromstring, tostring, CSSSelector = self.get_imports() | |||
182 | doc = fromstring(self.response.body) |
|
188 | doc = fromstring(self.response.body) | |
183 | sel = CSSSelector(css_selector) |
|
189 | sel = CSSSelector(css_selector) | |
184 | elements = sel(doc) |
|
190 | elements = sel(doc) | |
185 | return elements |
|
191 | return elements | |
186 |
|
192 | |||
187 | def _element_to_string(self, element): |
|
193 | def _element_to_string(self, element): | |
|
194 | fromstring, tostring, CSSSelector = self.get_imports() | |||
188 | return tostring(element) |
|
195 | return tostring(element) | |
189 |
|
196 | |||
190 |
|
197 | |||
@@ -230,7 +237,7 b' def run_test_concurrently(times, raise_c' | |||||
230 | def call_test_func(): |
|
237 | def call_test_func(): | |
231 | try: |
|
238 | try: | |
232 | test_func(*args, **kwargs) |
|
239 | test_func(*args, **kwargs) | |
233 |
except Exception |
|
240 | except Exception as e: | |
234 | exceptions.append(e) |
|
241 | exceptions.append(e) | |
235 | if raise_catched_exc: |
|
242 | if raise_catched_exc: | |
236 | raise |
|
243 | raise | |
@@ -260,11 +267,11 b' def wait_for_url(url, timeout=10):' | |||||
260 | last = 0 |
|
267 | last = 0 | |
261 | wait = 0.1 |
|
268 | wait = 0.1 | |
262 |
|
269 | |||
263 |
while |
|
270 | while timeout > last: | |
264 | last = time.time() |
|
271 | last = time.time() | |
265 | if is_url_reachable(url): |
|
272 | if is_url_reachable(url): | |
266 | break |
|
273 | break | |
267 |
elif |
|
274 | elif (last + wait) > time.time(): | |
268 | # Go to sleep because not enough time has passed since last check. |
|
275 | # Go to sleep because not enough time has passed since last check. | |
269 | time.sleep(wait) |
|
276 | time.sleep(wait) | |
270 | else: |
|
277 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now