comparison test/test_liveserver.py @ 8214:55b0abde56ab

fix(web) issue2551382 - case 1# or 1& failing. HAndle case for integer followed by a url delimiter. e.g. 1# and 1&
author John Rouillard <rouilj@ieee.org>
date Sun, 15 Dec 2024 02:34:57 -0500
parents 14e92a595828
children 1b15f635ada1
comparison
equal deleted inserted replaced
8213:14e92a595828 8214:55b0abde56ab
24 import hypothesis 24 import hypothesis
25 skip_hypothesis = lambda func, *args, **kwargs: func 25 skip_hypothesis = lambda func, *args, **kwargs: func
26 26
27 # ruff: noqa: E402 27 # ruff: noqa: E402
28 from hypothesis import example, given, settings 28 from hypothesis import example, given, settings
29 from hypothesis.strategies import binary, characters, none, one_of, sampled_from, text 29 from hypothesis.strategies import binary, characters, emails, none, one_of, sampled_from, text
30 30
31 except ImportError: 31 except ImportError:
32 from .pytest_patcher import mark_class 32 from .pytest_patcher import mark_class
33 skip_hypothesis = mark_class(pytest.mark.skip( 33 skip_hypothesis = mark_class(pytest.mark.skip(
34 reason='Skipping hypothesis liveserver tests: hypothesis library not available')) 34 reason='Skipping hypothesis liveserver tests: hypothesis library not available'))
46 pass 46 pass
47 47
48 # define the decorator functions 48 # define the decorator functions
49 example = given = settings = noop_decorators_with_args 49 example = given = settings = noop_decorators_with_args
50 # and stratgies using in decorators 50 # and stratgies using in decorators
51 binary = characters = none = one_of = sampled_from = text = noop_strategy 51 binary = characters = emails, none = one_of = sampled_from = text = noop_strategy
52 52
53 53
54 try: 54 try:
55 import brotli 55 import brotli
56 skip_brotli = lambda func, *args, **kwargs: func 56 skip_brotli = lambda func, *args, **kwargs: func
211 211
212 _max_examples = 100 212 _max_examples = 100
213 213
214 @given(sampled_from(['@verbose', '@page_size', '@page_index']), 214 @given(sampled_from(['@verbose', '@page_size', '@page_index']),
215 one_of(characters(),text(min_size=1))) 215 one_of(characters(),text(min_size=1)))
216 @example("@verbose", "1#")
216 @settings(max_examples=_max_examples, 217 @settings(max_examples=_max_examples,
217 deadline=10000) # 10000ms 218 deadline=10000) # 10000ms
218 def test_class_url_param_accepting_integer_values(self, param, value): 219 def test_class_url_param_accepting_integer_values(self, param, value):
219 """Tests all integer args for rest url. @page_* is the 220 """Tests all integer args for rest url. @page_* is the
220 same code for all *. 221 same code for all *.
222 session, _response = self.create_login_session() 223 session, _response = self.create_login_session()
223 url = '%s/rest/data/status' % (self.url_base()) 224 url = '%s/rest/data/status' % (self.url_base())
224 query = '%s=%s' % (param, value) 225 query = '%s=%s' % (param, value)
225 f = session.get(url, params=query) 226 f = session.get(url, params=query)
226 try: 227 try:
228 # test case '0#'
229 if len(value) > 1 and value[-1] in ('#', '&'):
230 value = value[:-1]
227 if int(value) >= 0: 231 if int(value) >= 0:
228 self.assertEqual(f.status_code, 200) 232 self.assertEqual(f.status_code, 200)
229 except ValueError: 233 except ValueError:
230 if value in ['#', '&']: 234 if value in ('#', '&'):
231 self.assertEqual(f.status_code, 200) 235 self.assertEqual(f.status_code, 200)
232 else: 236 else:
233 # invalid value for param 237 # invalid value for param
234 self.assertEqual(f.status_code, 400) 238 self.assertEqual(f.status_code, 400)
235 239
236 @given(sampled_from(['@verbose']), 240 @given(sampled_from(['@verbose']),
237 one_of(characters(),text(min_size=1))) 241 one_of(characters(),text(min_size=1)))
242 @example("@verbose", "1#")
238 @settings(max_examples=_max_examples, 243 @settings(max_examples=_max_examples,
239 deadline=10000) # 10000ms 244 deadline=10000) # 10000ms
240 def test_element_url_param_accepting_integer_values(self, param, value): 245 def test_element_url_param_accepting_integer_values(self, param, value):
241 """Tests all integer args for rest url. @page_* is the 246 """Tests all integer args for rest url. @page_* is the
242 same code for all *. 247 same code for all *.
244 session, _response = self.create_login_session() 249 session, _response = self.create_login_session()
245 url = '%s/rest/data/status/1' % (self.url_base()) 250 url = '%s/rest/data/status/1' % (self.url_base())
246 query = '%s=%s' % (param, value) 251 query = '%s=%s' % (param, value)
247 f = session.get(url, params=query) 252 f = session.get(url, params=query)
248 try: 253 try:
254 # test case '0#'
255 if len(value) > 1 and value[-1] in ('#', '&'):
256 value = value[:-1]
249 if int(value) >= 0: 257 if int(value) >= 0:
250 self.assertEqual(f.status_code, 200) 258 self.assertEqual(f.status_code, 200)
251 except ValueError: 259 except ValueError:
252 if value in ['#', '&']: 260 if value in ['#', '&']:
253 self.assertEqual(f.status_code, 200) 261 self.assertEqual(f.status_code, 200)
254 else: 262 else:
255 # invalid value for param 263 # invalid value for param
256 self.assertEqual(f.status_code, 400) 264 self.assertEqual(f.status_code, 400)
257
258 265
259 @skip_requests 266 @skip_requests
260 class BaseTestCases(WsgiSetup, ClientSetup): 267 class BaseTestCases(WsgiSetup, ClientSetup):
261 """Class with all tests to run against wsgi server. Is reused when 268 """Class with all tests to run against wsgi server. Is reused when
262 wsgi server is started with various feature flags 269 wsgi server is started with various feature flags

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