示例#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")
示例#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")
示例#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")
示例#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()
示例#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")
示例#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()
示例#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()
示例#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)
示例#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]
         )
示例#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")
示例#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)
示例#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)
示例#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)
示例#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")
示例#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/")
示例#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")
示例#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")
示例#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")
示例#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")
示例#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")
示例#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/")
示例#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")
示例#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")
示例#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/")
示例#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")
示例#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/")
示例#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")
示例#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/")
示例#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/")
示例#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/")