def assert_see_other__keep_query_string(self) -> None: response = FakeResponse( "303 See Other", [("Location", "http://example.com/foo?abc=def#frag")], ) with assert_succeeds(AssertionError): response.assert_see_other("/foo?abc=def#frag")
def assert_temporary_redirect__keep_query_string(self) -> None: response = FakeResponse( "307 Temporary Redirect", [("Location", "http://example.com/foo?abc=def#frag")], ) with assert_succeeds(AssertionError): response.assert_temporary_redirect("/foo?abc=def#frag")
def assert_temporary_redirect__relative_location(self) -> None: response = FakeResponse( "307 Temporary Redirect", [("Location", "http://example.com/foo/bar")], ) with assert_succeeds(AssertionError): response.assert_temporary_redirect("/foo/bar")
def parse_json_body__invalid_encoding(self) -> None: response = FakeResponse( "200 OK", [("Content-Type", "application/json; charset=utf-8")] ) response.body = '{"föo": 5}'.encode("iso-8859-1") with assert_raises(AssertionError): response.parse_json_body()
def assert_created_at__keep_query_string(self) -> None: response = FakeResponse( "201 Created", [("Location", "http://example.com/foo?abc=def#frag")], ) with assert_succeeds(AssertionError): response.assert_created_at("/foo?abc=def#frag")
def parse_json_body__invalid_json(self) -> None: response = FakeResponse( "200 OK", [("Content-Type", "application/json")] ) response.body = b'{"foo":' with assert_raises(AssertionError): response.parse_json_body()
def parse_json_body__wrong_content_encoding(self) -> None: response = FakeResponse( "200 OK", [("Content-Type", "application/json; charset=latin1")] ) response.body = b"{}" with assert_raises(AssertionError): response.parse_json_body()
def parse_json_body(self) -> None: response = FakeResponse( "200 OK", [("Content-Type", "application/json")] ) response.body = b'{"foo": 5}' json = response.parse_json_body() assert_equal({"foo": 5}, json)
def assert_content_type__charset_list_matches(self) -> None: response = FakeResponse( "200 OK", [("Content-Type", "text/html; charset=us-ascii")] ) with assert_succeeds(AssertionError): response.assert_content_type( "text/html", charset=["us-ascii", "utf-8", None] )
def assert_set_cookie__has_secure(self) -> None: response = FakeResponse("200 OK", [("Set-Cookie", "Foo=Bar; Secure")]) with assert_succeeds(AssertionError): response.assert_set_cookie("Foo", "Bar") with assert_succeeds(AssertionError): response.assert_set_cookie("Foo", "Bar", secure=True) with assert_raises(AssertionError): response.assert_set_cookie("Foo", "Bar", secure=False)
def assert_set_cookie__no_http_only(self) -> None: response = FakeResponse("200 OK", [("Set-Cookie", "Foo=Bar")]) with assert_succeeds(AssertionError): response.assert_set_cookie("Foo", "Bar") with assert_raises(AssertionError): response.assert_set_cookie("Foo", "Bar", http_only=True) with assert_succeeds(AssertionError): response.assert_set_cookie("Foo", "Bar", http_only=False)
def assert_set_cookie__invalid_max_age(self) -> None: response = FakeResponse( "200 OK", [("Set-Cookie", "Foo=Bar; Max-Age=INVALID")] ) with assert_succeeds(AssertionError): response.assert_set_cookie("Foo", "Bar") with assert_raises(AssertionError): response.assert_set_cookie("Foo", "Bar", max_age=1234)
def get_header_value(self) -> None: response = FakeResponse( "200 OK", [ ("X-Header", "Foobar"), ("Content-Type", "image/png"), ("Allow", "GET"), ], ) assert_equal("image/png", response.get_header_value("Content-Type")) assert_equal("image/png", response.get_header_value("content-TYPE")) with assert_raises(ValueError): response.get_header_value("X-Unknown")
def assert_set_cookie__wrong_value(self) -> None: response = FakeResponse("200 OK", [("Set-Cookie", "Foo=Wrong")]) with assert_raises(AssertionError): response.assert_set_cookie("Foo", "Bar")
def assert_see_other__wrong_status(self) -> None: response = FakeResponse( "200 OK", [("Location", "http://example.com/")] ) with assert_raises(AssertionError): response.assert_see_other("http://example.com/")
def assert_set_cookie__simple_match(self) -> None: response = FakeResponse( "200 OK", [("Set-Cookie", "Foo=Bar; Secure; Max-Age=1234")] ) with assert_succeeds(AssertionError): response.assert_set_cookie("Foo", "Bar")
def assert_set_cookie__no_cookie_header(self) -> None: response = FakeResponse("200 OK", []) with assert_raises(AssertionError): response.assert_set_cookie("Foo", "Bar")
def assert_content_type__charset_not_checked(self) -> None: response = FakeResponse( "200 OK", [("Content-Type", "text/html; charset=utf-8")] ) with assert_succeeds(AssertionError): response.assert_content_type("text/html")
def assert_content_type__wrong_charset(self) -> None: response = FakeResponse( "200 OK", [("Content-Type", "text/html; charset=utf-8")] ) with assert_raises(AssertionError): response.assert_content_type("text/html", charset="us-ascii")
def assert_content_type__different(self) -> None: response = FakeResponse("200 OK", [("Content-Type", "image/png")]) with assert_raises(AssertionError): response.assert_content_type("image/jpeg")
def assert_temporary_redirect__no_location_header(self) -> None: response = FakeResponse("307 Temporary Redirect", []) with assert_raises(AssertionError): response.assert_temporary_redirect("http://example.org/")
def assert_content_type__no_such_header(self) -> None: response = FakeResponse("200 OK", []) with assert_raises(AssertionError): response.assert_content_type("image/png")
def assert_content_type__equal(self) -> None: response = FakeResponse("200 OK", [("Content-Type", "image/png")]) with assert_succeeds(AssertionError): response.assert_content_type("image/png")
def assert_see_other__wrong_location(self) -> None: response = FakeResponse( "303 See Other", [("Location", "http://example.com/")] ) with assert_raises(AssertionError): response.assert_see_other("http://example.org/")
def assert_see_other__relative_location(self) -> None: response = FakeResponse( "303 See Other", [("Location", "http://example.com/foo/bar")] ) with assert_succeeds(AssertionError): response.assert_see_other("/foo/bar")
def assert_temporary_redirect__ok(self) -> None: response = FakeResponse( "307 Temporary Redirect", [("Location", "http://example.com/")] ) with assert_succeeds(AssertionError): response.assert_temporary_redirect("http://example.com/")
def assert_created_at__relative_location(self) -> None: response = FakeResponse( "201 Created", [("Location", "http://example.com/foo/bar")] ) with assert_succeeds(AssertionError): response.assert_created_at("/foo/bar")
def assert_see_other__no_location_header(self) -> None: response = FakeResponse("303 See Other", []) with assert_raises(AssertionError): response.assert_see_other("http://example.org/")
def assert_temporary_redirect__wrong_location(self) -> None: response = FakeResponse( "307 Temporary Redirect", [("Location", "http://example.com/")] ) with assert_raises(AssertionError): response.assert_temporary_redirect("http://example.org/")
def assert_temporary_redirect__wrong_status(self) -> None: response = FakeResponse( "200 OK", [("Location", "http://example.com/")] ) with assert_raises(AssertionError): response.assert_temporary_redirect("http://example.com/")