Skip to content

Commit 1dafa29

Browse files
committed
Test case where there is no content-encoding.
Make sure etag header is un-suffixed.
1 parent afc5937 commit 1dafa29

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/test_liveserver.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,57 @@ def test_compression_gzipfile(self):
396396
# cleanup
397397
os.remove(gzfile)
398398

399+
def test_compression_none_etag(self):
400+
# use basic auth for rest endpoint
401+
f = requests.get(self.url_base() + '/rest/data/user/1/username',
402+
auth=('admin', 'sekrit'),
403+
headers = {'content-type': "",
404+
'Accept-Encoding': "",
405+
'Accept': '*/*'})
406+
print(f.status_code)
407+
print(f.headers)
408+
409+
self.assertEqual(f.status_code, 200)
410+
expected = { 'Content-Type': 'application/json',
411+
'Access-Control-Allow-Origin': '*',
412+
'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override',
413+
'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH',
414+
'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, POST, PUT, DELETE, PATCH'
415+
}
416+
417+
content_str = '''{ "data": {
418+
"id": "1",
419+
"link": "http://localhost:9001/rest/data/user/1/username",
420+
"data": "admin"
421+
}
422+
}'''
423+
content = json.loads(content_str)
424+
425+
426+
if (type("") == type(f.content)):
427+
json_dict = json.loads(f.content)
428+
else:
429+
json_dict = json.loads(b2s(f.content))
430+
431+
# etag wil not match, creation date different
432+
del(json_dict['data']['@etag'])
433+
434+
# type is "class 'str'" under py3, "type 'str'" py2
435+
# just skip comparing it.
436+
del(json_dict['data']['type'])
437+
438+
self.assertDictEqual(json_dict, content)
439+
440+
# verify that ETag header has no - delimiter
441+
print(f.headers['ETag'])
442+
with self.assertRaises(ValueError):
443+
f.headers['ETag'].index('-')
444+
445+
# use dict comprehension to remove fields like date,
446+
# content-length etc. from f.headers.
447+
self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
448+
449+
399450
def test_compression_gzip(self):
400451
# use basic auth for rest endpoint
401452
f = requests.get(self.url_base() + '/rest/data/user/1/username',

0 commit comments

Comments
 (0)