1
0
Fork 0
forked from s3lph/matemat

Added unit test for redirection testing.

This commit is contained in:
s3lph 2018-07-07 19:24:00 +02:00
parent a531447970
commit 14f339e630
2 changed files with 21 additions and 1 deletions

View file

@ -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

View file

@ -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')