def do_not_encode_cgi_arguments(self) -> None: self.environment["SERVER_NAME"] = "www.example.com" request = Request(self.environment) temporary_redirect(request, self.start_response, "foo?bar=baz&abc=%6A;+,@:$") self.start_response.assert_header_equals( "Location", "http://www.example.com/foo?bar=baz&abc=%6A;+,@:$")
def extra_headers(self) -> None: request = Request(self.environment) temporary_redirect( request, self.start_response, "foo", extra_headers=[("X-Foo", "Bar")], ) self.start_response.assert_header_equals("X-Foo", "Bar")
def headers(self) -> None: self.environment["SERVER_NAME"] = "www.example.com" request = Request(self.environment) temporary_redirect(request, self.start_response, "/foo/bar") self.start_response.assert_status(HTTPStatus.TEMPORARY_REDIRECT) self.start_response.assert_header_equals("Content-Type", "text/html; charset=utf-8") self.start_response.assert_header_equals( "Location", "http://www.example.com/foo/bar")
def html(self) -> None: request = Request(self.environment) response = temporary_redirect(request, self.start_response, "foo/bar") html = b"".join(response).decode("utf-8") assert html.startswith("<!DOCTYPE html>") assert_in("http://www.example.com/foo/bar", html)
def umlauts_in_url(self) -> None: self.environment["SERVER_NAME"] = "www.example.com" request = Request(self.environment) temporary_redirect(request, self.start_response, "foo/bär") self.start_response.assert_header_equals( "Location", "http://www.example.com/foo/b%C3%A4r")
def url_without_leading_slash(self) -> None: self.environment["SERVER_NAME"] = "www.example.com" request = Request(self.environment) temporary_redirect(request, self.start_response, "foo/bar") self.start_response.assert_header_equals( "Location", "http://www.example.com/foo/bar")
def absolute_url(self) -> None: request = Request(self.environment) temporary_redirect(request, self.start_response, "http://example.com/foo") self.start_response.assert_header_equals("Location", "http://example.com/foo")
def temporary_redirect(self, url_part: str) -> Iterable[bytes]: return temporary_redirect(self.request, self.start_response, url_part)