Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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")
Ejemplo n.º 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")
Ejemplo n.º 6
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")
Ejemplo n.º 7
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")
Ejemplo n.º 8
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]
         )
Ejemplo n.º 9
0
 def exhaustive_check__succeeds(self) -> None:
     self.add_path_argument("foo", "v")
     with assert_succeeds(ArgumentsError):
         parse_args(
             self.env,
             [("foo", str, Multiplicity.OPTIONAL)],
             exhaustive=True,
         )
Ejemplo n.º 10
0
 def _successful_arg_test(
     self,
     app_args: Sequence[ArgumentTemplate],
     expected_args: Iterable[ArgumentToTest],
 ) -> None:
     app = self._create_app(app_args)
     request = create_request("GET", "/")
     with assert_succeeds(AssertionError):
         run_wsgi_arguments_test(app, request, expected_args)
Ejemplo n.º 11
0
 def exhaustive_with_previous_calls(self) -> None:
     environ = {
         "wsgi.input": BytesIO(b"foo=bar&abc=def"),
         "REQUEST_METHOD": "POST",
         "CONTENT_LENGTH": "15",
         "CONTENT_TYPE": "application/x-www-form-urlencoded",
     }
     parser = ArgumentParser(environ)
     parser.parse_args([("foo", str, Multiplicity.REQUIRED)],
                       exhaustive=False)
     with assert_succeeds(ArgumentsError):
         parser.parse_args([("abc", str, Multiplicity.REQUIRED)],
                           exhaustive=True)
Ejemplo n.º 12
0
 def post_request__no_args(self) -> None:
     app = self._create_app([("arg", int, Multiplicity.OPTIONAL)])
     request = create_request("POST", "/")
     with assert_succeeds(AssertionError):
         run_wsgi_arguments_test(app, request, [])
Ejemplo n.º 13
0
 def no_exhaustive_check(self) -> None:
     self.add_path_argument("foo", "v")
     self.add_path_argument("unknown", "v")
     with assert_succeeds(ArgumentsError):
         parse_args(self.env, [("foo", str, Multiplicity.OPTIONAL)])
Ejemplo n.º 14
0
 def assert_status__ok(self) -> None:
     response = FakeResponse("404 Not Found", [])
     with assert_succeeds(AssertionError):
         response.assert_status(HTTPStatus.NOT_FOUND)
Ejemplo n.º 15
0
 def assert_header_equal__ok(self) -> None:
     response = FakeResponse("200 OK", [("X-Header", "value")])
     with assert_succeeds(AssertionError):
         response.assert_header_equal("X-Header", "value")
Ejemplo n.º 16
0
 def assert_header_not_set__not_set(self) -> None:
     response = FakeResponse("200 OK", [])
     with assert_succeeds(AssertionError):
         response.assert_header_not_set("X-Foo")
Ejemplo n.º 17
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")
Ejemplo n.º 18
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")
Ejemplo n.º 19
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")
Ejemplo n.º 20
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")
Ejemplo n.º 21
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/")
Ejemplo n.º 22
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")
Ejemplo n.º 23
0
 def set_body_in_get_request(self) -> None:
     request = create_request("GET", "/")
     with assert_succeeds(ValueError):
         request.body = b""
     with assert_raises(ValueError):
         request.body = b"Test Body"