Mercurial > p > roundup > code
diff test/test_cgi.py @ 7154:f614176903d0
fix test; string for json object has extra space under python2.
So compensate by comparing json parsed into objects and compensate
with a different content-length between py2 and py3..
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 21 Feb 2023 23:06:15 -0500 |
| parents | 1181157d7cec |
| children | 89a59e46b3af |
line wrap: on
line diff
--- a/test/test_cgi.py Tue Feb 21 22:35:58 2023 -0500 +++ b/test/test_cgi.py Tue Feb 21 23:06:15 2023 -0500 @@ -1348,6 +1348,7 @@ def testRestOptionsBadAttribute(self): + import json out = [] def wh(s): out.append(s) @@ -1378,6 +1379,8 @@ cl.write = wh # capture output cl.handle_rest() + _py3 = sys.version_info[0] > 2 + expected_headers = { 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Allow-Headers': 'Content-Type, Authorization, ' @@ -1386,7 +1389,8 @@ 'Access-Control-Allow-Origin': 'http://whoami.com', 'Access-Control-Max-Age': '86400', 'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH', - 'Content-Length': '104', + # string representation under python2 has an extra space. + 'Content-Length': '104' if _py3 else '105', 'Content-Type': 'application/json', 'Vary': 'Origin' } @@ -1394,7 +1398,8 @@ expected_body = b'{\n "error": {\n "status": 404,\n "msg": "Attribute zot not valid for Class user"\n }\n}\n' self.assertEqual(cl.response_code, 404) - self.assertEqual(out[0], expected_body) + # json payload string representation differs. Compare as objects. + self.assertEqual(json.loads(b2s(out[0])), json.loads(expected_body)) self.assertEqual(cl.additional_headers, expected_headers) del(out[0])
