From 14f339e63052e8d05c53741b7493327aef648542 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 7 Jul 2018 19:24:00 +0200 Subject: [PATCH] Added unit test for redirection testing. --- matemat/webserver/httpd.py | 1 - matemat/webserver/test/test_serve.py | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/matemat/webserver/httpd.py b/matemat/webserver/httpd.py index a161d42..3892ac8 100644 --- a/matemat/webserver/httpd.py +++ b/matemat/webserver/httpd.py @@ -324,7 +324,6 @@ class HttpHandler(BaseHTTPRequestHandler): # Generic error handling self.send_error(500, 'Internal Server Error') print(e) - traceback.print_tb(e.__traceback__) # noinspection PyPep8Naming diff --git a/matemat/webserver/test/test_serve.py b/matemat/webserver/test/test_serve.py index b507df7..5bcdd4d 100644 --- a/matemat/webserver/test/test_serve.py +++ b/matemat/webserver/test/test_serve.py @@ -18,6 +18,15 @@ def serve_test_pagelet_ok(method: str, return 'serve test pagelet ok' +@test_pagelet('/just/testing/serve_pagelet_redirect') +def serve_test_pagelet_redirect(method: str, + path: str, + args: RequestArguments, + session_vars: Dict[str, Any], + headers: Dict[str, str]): + return 301, '/foo/bar' + + @test_pagelet('/just/testing/serve_pagelet_fail') def serve_test_pagelet_fail(method: str, path: str, @@ -66,6 +75,18 @@ class TestServe(AbstractHttpdTest): # Make sure an error is raised self.assertEqual(500, packet.statuscode) + def test_serve_pagelet_redirect(self): + # Call the test pagelet that redirects to another path + self.client_sock.set_request(b'GET /just/testing/serve_pagelet_redirect HTTP/1.1\r\n\r\n') + HttpHandler(self.client_sock, ('::1', 45678), self.server) + packet = self.client_sock.get_response() + + # Make sure the correct redirect is issued + self.assertEqual(301, packet.statuscode) + self.assertEqual('/foo/bar', packet.headers['Location']) + # Make sure the response body is empty + self.assertEqual(0, len(packet.body)) + def test_serve_static_ok(self): # Request a static resource self.client_sock.set_request(b'GET /static_resource.txt HTTP/1.1\r\n\r\n')