From e91c2edf7e0719f3aefd435dcdfe37ae61f31733 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Tue, 13 Nov 2012 18:11:25 +0100 Subject: [PATCH] Test all http response codes. --- tests/checker/httpserver.py | 22 ++++++++++++++++++++-- tests/checker/test_http.py | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/tests/checker/httpserver.py b/tests/checker/httpserver.py index 1e03d9ba..a617150f 100644 --- a/tests/checker/httpserver.py +++ b/tests/checker/httpserver.py @@ -82,19 +82,37 @@ class NoQueryHttpRequestHandler (StoppableHttpRequestHandler): if i != -1: self.path = self.path[:i] + def get_status(self): + dummy, status = self.path.rsplit('/', 1) + status = int(status) + if status in self.responses: + return status + return 500 + def do_GET (self): """ Removes query part of GET request. """ self.remove_path_query() - super(NoQueryHttpRequestHandler, self).do_GET() + if "status/" in self.path: + status = self.get_status() + self.send_response(status) + self.end_headers() + if status >= 200 and status not in (204, 304): + self.wfile.write("testcontent") + else: + super(NoQueryHttpRequestHandler, self).do_GET() def do_HEAD (self): """ Removes query part of HEAD request. """ self.remove_path_query() - super(NoQueryHttpRequestHandler, self).do_HEAD() + if "status/" in self.path: + self.send_response(self.get_status()) + self.end_headers() + else: + super(NoQueryHttpRequestHandler, self).do_HEAD() def list_directory(self, path): """Helper to produce a directory listing (absent index.html). diff --git a/tests/checker/test_http.py b/tests/checker/test_http.py index 45218ab8..6d07dadd 100644 --- a/tests/checker/test_http.py +++ b/tests/checker/test_http.py @@ -35,3 +35,27 @@ class TestHttp (HttpServerTest): self.file_test("http.xhtml", confargs=confargs) self.file_test("http_file.html", confargs=confargs) + def test_status(self): + for status in sorted(self.handler.responses.keys()): + self._test_status(status) + + def _test_status(self, status): + url = u"http://localhost:%d/status/%d" % (self.port, status) + resultlines = [ + u"url %s" % url, + u"cache key %s" % url, + u"real url %s" % url, + ] + if status in (204,): + resultlines.append(u"warning No Content") + elif status == 401: + resultlines.append(u"warning Unauthorized access without HTTP authentication.") + elif status in (301, 302): + resultlines.append(u"info Redirected to `%s'." % url) + if (status != 101 and status < 200) or status >= 400 or status in (301, 302, 305): + result = u"error" + else: + result = u"valid" + resultlines.append(result) + self.direct(url, resultlines, recursionlevel=0) +