mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
test_classes: Include more detail in incorrect JSON responses.
If the status code is wrong, we show the actual error message now, which often saves a bit of time when debugging.
This commit is contained in:
@@ -414,18 +414,25 @@ class ZulipTestCase(TestCase):
|
||||
Successful POSTs return a 200 and JSON of the form {"result": "success",
|
||||
"msg": ""}.
|
||||
"""
|
||||
self.assertEqual(result.status_code, 200, result)
|
||||
try:
|
||||
json = ujson.loads(result.content)
|
||||
except Exception: # nocoverage
|
||||
json = {'msg': "Error parsing JSON in response!"}
|
||||
self.assertEqual(result.status_code, 200, json['msg'])
|
||||
self.assertEqual(json.get("result"), "success")
|
||||
# We have a msg key for consistency with errors, but it typically has an
|
||||
# empty value.
|
||||
self.assertIn("msg", json)
|
||||
self.assertNotEqual(json["msg"], "Error parsing JSON in response!")
|
||||
return json
|
||||
|
||||
def get_json_error(self, result, status_code=400):
|
||||
# type: (HttpResponse, int) -> Dict[str, Any]
|
||||
self.assertEqual(result.status_code, status_code)
|
||||
try:
|
||||
json = ujson.loads(result.content)
|
||||
except Exception: # nocoverage
|
||||
json = {'msg': "Error parsing JSON in response!"}
|
||||
self.assertEqual(result.status_code, status_code, msg=json.get('msg'))
|
||||
self.assertEqual(json.get("result"), "error")
|
||||
return json['msg']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user