From a74925e313dc61121ddd374ae89f1d4d976072a2 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 11 Jan 2018 22:03:38 +0000 Subject: [PATCH] Add http.error_handler(). --- tests/helpers/http.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/helpers/http.py b/tests/helpers/http.py index e7ded9f8..435bf414 100644 --- a/tests/helpers/http.py +++ b/tests/helpers/http.py @@ -59,3 +59,16 @@ def json_file_handler(data): pass return HTTPHandler + + +def error_handler(code, msg): + """Return an HTTP handler that always returns the given error code.""" + + class HTTPHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + self.send_error(code, msg) + + def log_message(self, *args, **kwargs): + pass + + return HTTPHandler