Skip to content

Commit 7353cb3

Browse files
committed
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..
1 parent 0a8823e commit 7353cb3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/test_cgi.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,7 @@ def wh(s):
13481348

13491349

13501350
def testRestOptionsBadAttribute(self):
1351+
import json
13511352
out = []
13521353
def wh(s):
13531354
out.append(s)
@@ -1378,6 +1379,8 @@ def wh(s):
13781379
cl.write = wh # capture output
13791380
cl.handle_rest()
13801381

1382+
_py3 = sys.version_info[0] > 2
1383+
13811384
expected_headers = {
13821385
'Access-Control-Allow-Credentials': 'true',
13831386
'Access-Control-Allow-Headers': 'Content-Type, Authorization, '
@@ -1386,15 +1389,17 @@ def wh(s):
13861389
'Access-Control-Allow-Origin': 'http://whoami.com',
13871390
'Access-Control-Max-Age': '86400',
13881391
'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH',
1389-
'Content-Length': '104',
1392+
# string representation under python2 has an extra space.
1393+
'Content-Length': '104' if _py3 else '105',
13901394
'Content-Type': 'application/json',
13911395
'Vary': 'Origin'
13921396
}
13931397

13941398
expected_body = b'{\n "error": {\n "status": 404,\n "msg": "Attribute zot not valid for Class user"\n }\n}\n'
13951399

13961400
self.assertEqual(cl.response_code, 404)
1397-
self.assertEqual(out[0], expected_body)
1401+
# json payload string representation differs. Compare as objects.
1402+
self.assertEqual(json.loads(b2s(out[0])), json.loads(expected_body))
13981403
self.assertEqual(cl.additional_headers, expected_headers)
13991404

14001405
del(out[0])

0 commit comments

Comments
 (0)