Exemple #1
0
 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")
Exemple #2
0
 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")
Exemple #3
0
 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")
Exemple #4
0
 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()
Exemple #5
0
 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")
Exemple #6
0
 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()
Exemple #7
0
 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()
Exemple #8
0
 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)
Exemple #9
0
 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]
         )
Exemple #10
0
 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")
Exemple #11
0
 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)
Exemple #12
0
 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)
Exemple #13
0
 def assert_set_cookie__has_max_age(self) -> None:
     response = FakeResponse(
         "200 OK", [("Set-Cookie", "Foo=Bar; Max-Age=1234")]
     )
     with assert_succeeds(AssertionError):
         response.assert_set_cookie("Foo", "Bar")
     with assert_succeeds(AssertionError):
         response.assert_set_cookie("Foo", "Bar", max_age=1234)
     with assert_raises(AssertionError):
         response.assert_set_cookie("Foo", "Bar", max_age=9999)
Exemple #14
0
 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")
Exemple #15
0
 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/")
Exemple #16
0
 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")
Exemple #17
0
 def assert_set_cookie__no_cookie_header(self) -> None:
     response = FakeResponse("200 OK", [])
     with assert_raises(AssertionError):
         response.assert_set_cookie("Foo", "Bar")
Exemple #18
0
 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")
Exemple #19
0
 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")
Exemple #20
0
 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")
Exemple #21
0
 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/")
Exemple #22
0
 def assert_content_type__no_such_header(self) -> None:
     response = FakeResponse("200 OK", [])
     with assert_raises(AssertionError):
         response.assert_content_type("image/png")
Exemple #23
0
 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")
Exemple #24
0
 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/")
Exemple #25
0
 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")
Exemple #26
0
 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/")
Exemple #27
0
 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")
Exemple #28
0
 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/")
Exemple #29
0
 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/")
Exemple #30
0
 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/")