mirror of https://github.com/zulip/zulip.git
test_docs: Print better error messages for failed responses.
This commit is contained in:
parent
8a02e177e3
commit
488f558d49
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue