From a8b9ffc020ceb7da14a9ec2bca0adec6a33d6d91 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 28 Aug 2017 21:33:10 -0700 Subject: [PATCH] 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. --- zerver/lib/test_classes.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py index 6d4aae8cb8..4fd1960b04 100644 --- a/zerver/lib/test_classes.py +++ b/zerver/lib/test_classes.py @@ -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) - json = ujson.loads(result.content) + 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) - json = ujson.loads(result.content) + 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']