Mercurial > p > roundup > code
comparison test/test_liveserver.py @ 7816:1b5daee24dc7
test: fix test for invalid etag in if-range.
The broken etag was missing the initial ", so the wrong code path was
duplicated. Also add test that correct size of file was returned and
fix comment(s).
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 17 Mar 2024 00:55:29 -0400 |
| parents | ec59729b3b7e |
| children | 0fe2b9f6e19f |
comparison
equal
deleted
inserted
replaced
| 7815:f11c982f01c8 | 7816:1b5daee24dc7 |
|---|---|
| 238 # compression disabled for length < 100, so we can use 11 here | 238 # compression disabled for length < 100, so we can use 11 here |
| 239 self.assertEqual(f.headers['content-length'], '11') | 239 self.assertEqual(f.headers['content-length'], '11') |
| 240 self.assertEqual(f.headers['content-range'], | 240 self.assertEqual(f.headers['content-range'], |
| 241 "bytes 10-20/%s"%expected_length) | 241 "bytes 10-20/%s"%expected_length) |
| 242 | 242 |
| 243 # get all bytest starting from 11 | 243 # get all bytes starting from 11 |
| 244 hdrs = {"Range": "bytes=11-"} | 244 hdrs = {"Range": "bytes=11-"} |
| 245 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 245 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 246 self.assertEqual(f.status_code, 206) | 246 self.assertEqual(f.status_code, 206) |
| 247 self.assertEqual(f.headers['content-range'], | 247 self.assertEqual(f.headers['content-range'], |
| 248 "bytes 11-%s/%s"%(int(expected_length) - 1, | 248 "bytes 11-%s/%s"%(int(expected_length) - 1, |
| 267 # not checking content length since it could be compressed | 267 # not checking content length since it could be compressed |
| 268 self.assertNotIn('content-range', f.headers, 'content-range should not be present') | 268 self.assertNotIn('content-range', f.headers, 'content-range should not be present') |
| 269 | 269 |
| 270 # range is too large, but etag is bad also, return whole file 200 code | 270 # range is too large, but etag is bad also, return whole file 200 code |
| 271 hdrs['Range'] = "0-99999" # too large | 271 hdrs['Range'] = "0-99999" # too large |
| 272 hdrs['If-Range'] = etag[2:] # bad tag | 272 hdrs['If-Range'] = '"' + etag[2:] # start bad tag with " |
| 273 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) | 273 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs) |
| 274 self.assertEqual(f.status_code, 200) | 274 self.assertEqual(f.status_code, 200) |
| 275 # not checking content length since it could be compressed | 275 # note f.content has content-encoding (compression) undone. |
| 276 self.assertEqual(len(f.content), int(expected_length)) | |
| 276 self.assertNotIn('content-range', f.headers, 'content-range should not be present') | 277 self.assertNotIn('content-range', f.headers, 'content-range should not be present') |
| 277 | 278 |
| 278 # range is too large, but etag is specified so return whole file | 279 # range is too large, but etag is specified so return whole file |
| 279 # 200 code | 280 # 200 code |
| 280 hdrs['Range'] = "bytes=0-99999" # too large | 281 hdrs['Range'] = "bytes=0-99999" # too large |
