Mercurial > p > roundup > code
comparison test/test_liveserver.py @ 6978:3c4047cdc77a
cange type or arg to assertIn from string to byte.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 14 Sep 2022 18:08:27 -0400 |
| parents | ff2c8b430738 |
| children | 72a54826ff4f |
comparison
equal
deleted
inserted
replaced
| 6977:ff2c8b430738 | 6978:3c4047cdc77a |
|---|---|
| 243 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 243 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 244 self.assertEqual(f.status_code, 206) | 244 self.assertEqual(f.status_code, 206) |
| 245 self.assertEqual(f.headers['content-range'], | 245 self.assertEqual(f.headers['content-range'], |
| 246 "bytes 11-%s/%s"%(int(expected_length) - 1, | 246 "bytes 11-%s/%s"%(int(expected_length) - 1, |
| 247 expected_length)) | 247 expected_length)) |
| 248 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 248 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 249 | 249 |
| 250 # conditional request 11 bytes since etag matches 206 code | 250 # conditional request 11 bytes since etag matches 206 code |
| 251 hdrs = {"Range": "bytes=0-10"} | 251 hdrs = {"Range": "bytes=0-10"} |
| 252 hdrs['If-Range'] = etag | 252 hdrs['If-Range'] = etag |
| 253 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 253 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 296 print(hdrs) | 296 print(hdrs) |
| 297 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 297 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 298 self.assertEqual(f.status_code, 200) | 298 self.assertEqual(f.status_code, 200) |
| 299 self.assertNotIn('content-range', f.headers, | 299 self.assertNotIn('content-range', f.headers, |
| 300 'content-range should not be present') | 300 'content-range should not be present') |
| 301 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 301 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 302 | 302 |
| 303 # invalid range is single number not number followed by - | 303 # invalid range is single number not number followed by - |
| 304 hdrs['Range'] = "bytes=1" | 304 hdrs['Range'] = "bytes=1" |
| 305 print(hdrs) | 305 print(hdrs) |
| 306 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 306 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 307 self.assertEqual(f.status_code, 200) | 307 self.assertEqual(f.status_code, 200) |
| 308 self.assertNotIn('content-range', f.headers, | 308 self.assertNotIn('content-range', f.headers, |
| 309 'content-range should not be present') | 309 'content-range should not be present') |
| 310 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 310 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 311 | 311 |
| 312 # range is invalid first number not a number | 312 # range is invalid first number not a number |
| 313 hdrs['Range'] = "bytes=boom-99" # bad first value | 313 hdrs['Range'] = "bytes=boom-99" # bad first value |
| 314 print(hdrs) | 314 print(hdrs) |
| 315 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 315 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 316 self.assertEqual(f.status_code, 200) | 316 self.assertEqual(f.status_code, 200) |
| 317 self.assertNotIn('content-range', f.headers, | 317 self.assertNotIn('content-range', f.headers, |
| 318 'content-range should not be present') | 318 'content-range should not be present') |
| 319 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 319 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 320 | 320 |
| 321 # range is invalid last number not a number | 321 # range is invalid last number not a number |
| 322 hdrs['Range'] = "bytes=1-boom" # bad last value | 322 hdrs['Range'] = "bytes=1-boom" # bad last value |
| 323 print(hdrs) | 323 print(hdrs) |
| 324 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 324 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 325 self.assertEqual(f.status_code, 200) | 325 self.assertEqual(f.status_code, 200) |
| 326 self.assertNotIn('content-range', f.headers, | 326 self.assertNotIn('content-range', f.headers, |
| 327 'content-range should not be present') | 327 'content-range should not be present') |
| 328 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 328 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 329 | 329 |
| 330 # range is invalid first position empty | 330 # range is invalid first position empty |
| 331 hdrs['Range'] = "bytes=-11" # missing first value | 331 hdrs['Range'] = "bytes=-11" # missing first value |
| 332 print(hdrs) | 332 print(hdrs) |
| 333 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 333 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 334 self.assertEqual(f.status_code, 200) | 334 self.assertEqual(f.status_code, 200) |
| 335 self.assertNotIn('content-range', f.headers, | 335 self.assertNotIn('content-range', f.headers, |
| 336 'content-range should not be present') | 336 'content-range should not be present') |
| 337 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 337 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 338 | 338 |
| 339 # range is invalid #2 < #1 | 339 # range is invalid #2 < #1 |
| 340 hdrs['Range'] = "bytes=11-1" # inverted range | 340 hdrs['Range'] = "bytes=11-1" # inverted range |
| 341 print(hdrs) | 341 print(hdrs) |
| 342 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 342 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 343 self.assertEqual(f.status_code, 200) | 343 self.assertEqual(f.status_code, 200) |
| 344 self.assertNotIn('content-range', f.headers, | 344 self.assertNotIn('content-range', f.headers, |
| 345 'content-range should not be present') | 345 'content-range should not be present') |
| 346 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 346 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 347 | 347 |
| 348 # range is invalid negative first number | 348 # range is invalid negative first number |
| 349 hdrs['Range'] = "bytes=-1-11" # negative first number | 349 hdrs['Range'] = "bytes=-1-11" # negative first number |
| 350 print(hdrs) | 350 print(hdrs) |
| 351 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 351 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 352 self.assertEqual(f.status_code, 200) | 352 self.assertEqual(f.status_code, 200) |
| 353 self.assertNotIn('content-range', f.headers, | 353 self.assertNotIn('content-range', f.headers, |
| 354 'content-range should not be present') | 354 'content-range should not be present') |
| 355 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 355 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 356 | 356 |
| 357 # range is invalid negative second number | 357 # range is invalid negative second number |
| 358 hdrs['Range'] = "bytes=1--11" # negative second number | 358 hdrs['Range'] = "bytes=1--11" # negative second number |
| 359 print(hdrs) | 359 print(hdrs) |
| 360 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 360 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 361 self.assertEqual(f.status_code, 200) | 361 self.assertEqual(f.status_code, 200) |
| 362 self.assertNotIn('content-range', f.headers, | 362 self.assertNotIn('content-range', f.headers, |
| 363 'content-range should not be present') | 363 'content-range should not be present') |
| 364 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 364 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 365 | 365 |
| 366 # range is unsupported units | 366 # range is unsupported units |
| 367 hdrs['Range'] = "badunits=1-11" | 367 hdrs['Range'] = "badunits=1-11" |
| 368 print(hdrs) | 368 print(hdrs) |
| 369 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 369 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 370 self.assertEqual(f.status_code, 200) | 370 self.assertEqual(f.status_code, 200) |
| 371 self.assertNotIn('content-range', f.headers, | 371 self.assertNotIn('content-range', f.headers, |
| 372 'content-range should not be present') | 372 'content-range should not be present') |
| 373 self.assertIn("SHA:", f.content) # detect sha sum at end of file | 373 self.assertIn(b"SHA:", f.content) # detect sha sum at end of file |
| 374 | 374 |
| 375 | 375 |
| 376 # valid range, invalid file | 376 # valid range, invalid file |
| 377 hdrs['Range'] = "bytes=0-11" | 377 hdrs['Range'] = "bytes=0-11" |
| 378 print(hdrs) | 378 print(hdrs) |
| 679 # etc. from f.headers. | 679 # etc. from f.headers. |
| 680 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected) | 680 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected) |
| 681 | 681 |
| 682 | 682 |
| 683 def test_load_issue1(self): | 683 def test_load_issue1(self): |
| 684 import pdb; pdb.set_trace() | |
| 685 for tail in [ | 684 for tail in [ |
| 686 '/issue1', # normal url | 685 '/issue1', # normal url |
| 687 '/issue00001', # leading 0's should be stripped from id | 686 '/issue00001', # leading 0's should be stripped from id |
| 688 '/issue1>' # surprise this works too, should it?? | 687 '/issue1>' # surprise this works too, should it?? |
| 689 ]: | 688 ]: |
