Skip to content

Commit 2bdcc6b

Browse files
committed
test - fix parsing of integer param values
CI broke on the string '1\r#' expecting a 400 but got a 200 in test_element_url_param_accepting_integer_values(). The #, & characters mark a url fragment or start of another parameter and not part of the value. In a couple of tests, I parse the hypothesis generated value to remove a # or & and anything after. Then I set the value to the preceding string. If the string starts with # or &, the value is set to "0" as the server ignores the parameter and returns 200. "0" is a value that asserts that status is 200. The code doing this parsing was different (and broken) between test_element_url_param_accepting_integer_values and test_class_url_param_accepting_integer_values It's now consistent and if it finds a & or #, it actually tests the resulting value/status rather than skipping the test.
1 parent 8547740 commit 2bdcc6b

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

test/test_liveserver.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class FuzzGetUrls(WsgiSetup, ClientSetup):
256256

257257
@given(sampled_from(['@verbose', '@page_size', '@page_index']),
258258
text(min_size=1))
259+
@example("@verbose", "0\r#")
259260
@example("@verbose", "1#")
260261
@example("@verbose", "#1stuff")
261262
@example("@verbose", "0 #stuff")
@@ -271,10 +272,18 @@ def test_class_url_param_accepting_integer_values(self, param, value):
271272
f = session.get(url, params=query)
272273
try:
273274
# test case '0 #', '0#', '12345#stuff' '12345&stuff'
274-
match = re.match(r'(^[0-9]*\s*)[#&]', value)
275+
# Normalize like a server does by breaking value at
276+
# # or & as these mark a fragment or subsequent
277+
# query arg and are not part of the value.
278+
match = re.match(r'^(.*)[#&]', value)
275279
if match is not None:
276280
value = match[1]
277-
elif int(value) >= 0:
281+
# parameter is ignored by server if empty.
282+
# so set it to 0 to force 200 status code.
283+
if value == "":
284+
value = "0"
285+
286+
if int(value) >= 0:
278287
self.assertEqual(f.status_code, 200)
279288
except ValueError:
280289
# test case '#' '#0', '&', '&anything here really'
@@ -285,6 +294,7 @@ def test_class_url_param_accepting_integer_values(self, param, value):
285294
self.assertEqual(f.status_code, 400)
286295

287296
@given(sampled_from(['@verbose']), text(min_size=1))
297+
@example("@verbose", "0\r#")
288298
@example("@verbose", "10#")
289299
@example("@verbose", u'Ø\U000dd990')
290300
@settings(max_examples=_max_examples,
@@ -298,10 +308,18 @@ def test_element_url_param_accepting_integer_values(self, param, value):
298308
f = session.get(url, params=query)
299309
try:
300310
# test case '0#' '12345#stuff' '12345&stuff'
301-
match = re.match('(^[0-9]*)[#&]', value)
311+
# Normalize like a server does by breaking value at
312+
# # or & as these mark a fragment or subsequent
313+
# query arg and are not part of the value.
314+
match = re.match(r'^(.*)[#&]', value)
302315
if match is not None:
303316
value = match[1]
304-
elif int(value) >= 0:
317+
# parameter is ignored by server if empty.
318+
# so set it to 0 to force 200 status code.
319+
if value == "":
320+
value = "0"
321+
322+
if int(value) >= 0:
305323
self.assertEqual(f.status_code, 200)
306324
except ValueError:
307325
# test case '#' '#0', '&', '&anything here really'

0 commit comments

Comments
 (0)