From b951a187a7fade0813652f64ce2c39c3e3d87138 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Mon, 14 Oct 2013 18:38:13 +0000 Subject: [PATCH] If we have a diff with a known-good master in a testurl.list file, save the failed file for inspection. - Legacy-Id: 6447 --- ietf/utils/test_utils.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ietf/utils/test_utils.py b/ietf/utils/test_utils.py index 6ac43031e..8512e39fe 100644 --- a/ietf/utils/test_utils.py +++ b/ietf/utils/test_utils.py @@ -135,12 +135,25 @@ class SimpleUrlTestCase(django.test.TestCase,RealDatabaseTest): failures = failures + 1 self.assertEqual(failures, 0, "%d URLs failed" % failures) + def saveBadResponse(self, url, response): + msg = "The %s page changed\n" % url + url = url.lstrip('/') + path = settings.TEST_DIFF_FAILURE_DIR + path = os.path.join(path, url) + if not os.path.exist(os.path.dirname(path)): + os.mkdir(os.path.dirname(path)) + with open(path) as file: + file.write(response) + msg += "The newly generated page has been saved at:\n %s" % path + return msg + def doTestUrl(self, tuple): (codes, url, master) = tuple baseurl, args = split_url(url) failed = False #enable this to see query counts #settings.DEBUG = True + msg = None try: if "heavy" in codes and self.skip_heavy_tests: if self.verbosity > 1: @@ -173,12 +186,14 @@ class SimpleUrlTestCase(django.test.TestCase,RealDatabaseTest): if code in codes and code == "200": diff_result = self.doDiff(tuple, response) if diff_result == False: + msg = self.saveBadResponse(url, response) failed = True except: failed = True - print "Exception for URL '%s'" % url + msg = "Exception for URL '%s'" % url + print msg traceback.print_exc() - self.assertEqual(failed, False) + self.assertEqual(failed, False, msg) # Override this in subclasses if needed def doCanonicalize(self, url, content):