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__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)
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_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 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 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_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 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, )
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)
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)
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, [])
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)])
def assert_status__ok(self) -> None: response = FakeResponse("404 Not Found", []) with assert_succeeds(AssertionError): response.assert_status(HTTPStatus.NOT_FOUND)
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")
def assert_header_not_set__not_set(self) -> None: response = FakeResponse("200 OK", []) with assert_succeeds(AssertionError): response.assert_header_not_set("X-Foo")
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_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_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_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_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_content_type__equal(self) -> None: response = FakeResponse("200 OK", [("Content-Type", "image/png")]) with assert_succeeds(AssertionError): response.assert_content_type("image/png")
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"