From 488f558d494709179b7a6a4b30b97710fee8c5a1 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Sat, 22 Dec 2018 21:07:27 -0330 Subject: [PATCH] test_docs: Print better error messages for failed responses. --- zerver/tests/test_docs.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index 382fc73827..1b0c654be9 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -3,6 +3,7 @@ import mock import os import subprocess +import ujson from django.conf import settings from django.test import TestCase, override_settings @@ -27,12 +28,22 @@ class DocPageTest(ZulipTestCase): return self.client_get(url, subdomain=subdomain, HTTP_X_REQUESTED_WITH='XMLHttpRequest') return self.client_get(url, subdomain=subdomain) + def print_msg_if_error(self, response: HttpResponse) -> None: # nocoverage + if response.status_code != 200 and response.get('Content-Type') == 'application/json': + content = ujson.loads(response.content) + print() + print("======================================================================") + print("ERROR: {}".format(content.get('msg'))) + print() + def _test(self, url: str, expected_content: str, extra_strings: List[str]=[], landing_missing_strings: List[str]=[], landing_page: bool=True, doc_html_str: bool=False) -> None: # Test the URL on the "zephyr" subdomain result = self.get_doc(url, subdomain="zephyr") + self.print_msg_if_error(result) + self.assertEqual(result.status_code, 200) self.assertIn(expected_content, str(result.content)) for s in extra_strings: @@ -42,6 +53,8 @@ class DocPageTest(ZulipTestCase): # Test the URL on the root subdomain result = self.get_doc(url, subdomain="") + self.print_msg_if_error(result) + self.assertEqual(result.status_code, 200) self.assertIn(expected_content, str(result.content)) if not doc_html_str: @@ -55,6 +68,8 @@ class DocPageTest(ZulipTestCase): with self.settings(ROOT_DOMAIN_LANDING_PAGE=True): # Test the URL on the root subdomain with the landing page setting result = self.get_doc(url, subdomain="") + self.print_msg_if_error(result) + self.assertEqual(result.status_code, 200) self.assertIn(expected_content, str(result.content)) for s in extra_strings: @@ -67,6 +82,8 @@ class DocPageTest(ZulipTestCase): # Test the URL on the "zephyr" subdomain with the landing page setting result = self.get_doc(url, subdomain="zephyr") + self.print_msg_if_error(result) + self.assertEqual(result.status_code, 200) self.assertIn(expected_content, str(result.content)) for s in extra_strings: