diff test/test_liveserver.py @ 8438:98e17dd0197f

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.
author John Rouillard <rouilj@ieee.org>
date Thu, 28 Aug 2025 12:39:38 -0400
parents cc3edb260c1b
children
line wrap: on
line diff
--- a/test/test_liveserver.py	Thu Aug 28 11:30:11 2025 -0400
+++ b/test/test_liveserver.py	Thu Aug 28 12:39:38 2025 -0400
@@ -256,6 +256,7 @@
 
     @given(sampled_from(['@verbose', '@page_size', '@page_index']),
            text(min_size=1))
+    @example("@verbose", "0\r#")
     @example("@verbose", "1#")
     @example("@verbose", "#1stuff")
     @example("@verbose", "0 #stuff")
@@ -271,10 +272,18 @@
         f = session.get(url, params=query)
         try:
             # test case '0 #', '0#', '12345#stuff' '12345&stuff'
-            match = re.match(r'(^[0-9]*\s*)[#&]', value)
+            # Normalize like a server does by breaking value at
+            # # or & as these mark a fragment or subsequent
+            # query arg and are not part of the value.
+            match = re.match(r'^(.*)[#&]', value)
             if match is not None:
                 value = match[1]
-            elif int(value) >= 0:
+                # parameter is ignored by server if empty.
+                # so set it to 0 to force 200 status code.
+                if value == "":
+                    value = "0"
+
+            if int(value) >= 0:
                 self.assertEqual(f.status_code, 200)
         except ValueError:
             # test case '#' '#0', '&', '&anything here really'
@@ -285,6 +294,7 @@
                 self.assertEqual(f.status_code, 400)
 
     @given(sampled_from(['@verbose']), text(min_size=1))
+    @example("@verbose", "0\r#")
     @example("@verbose", "10#")
     @example("@verbose", u'Ø\U000dd990')
     @settings(max_examples=_max_examples,
@@ -298,10 +308,18 @@
         f = session.get(url, params=query)
         try:
             # test case '0#' '12345#stuff' '12345&stuff'
-            match = re.match('(^[0-9]*)[#&]', value)
+            # Normalize like a server does by breaking value at
+            # # or & as these mark a fragment or subsequent
+            # query arg and are not part of the value.
+            match = re.match(r'^(.*)[#&]', value)
             if match is not None:
                 value = match[1]
-            elif int(value) >= 0:
+                # parameter is ignored by server if empty.
+                # so set it to 0 to force 200 status code.
+                if value == "":
+                    value = "0"
+
+            if int(value) >= 0:
                 self.assertEqual(f.status_code, 200)
         except ValueError:
             # test case '#' '#0', '&', '&anything here really'

Roundup Issue Tracker: http://roundup-tracker.org/