Ejemplo n.º 1
0
 def respond_with_json(
     self,
     json: str | bytes | Any,
     *,
     status: HTTPStatus = HTTPStatus.OK,
     extra_headers: Sequence[Header] = [],
 ) -> Iterable[bytes]:
     return respond_with_json(
         self.start_response,
         json,
         status=status,
         extra_headers=extra_headers,
     )
Ejemplo n.º 2
0
 def json_as_object(self) -> None:
     sr = StubStartResponse()
     response = respond_with_json(sr, {"föo": 3})
     assert_equal(b'{"f\\u00f6o": 3}', b"".join(response))
Ejemplo n.º 3
0
 def json_as_str(self) -> None:
     sr = StubStartResponse()
     response = respond_with_json(sr, '{"föo": 3}')
     assert_equal('{"föo": 3}'.encode("utf-8"), b"".join(response))
Ejemplo n.º 4
0
 def json_as_bytes(self) -> None:
     sr = StubStartResponse()
     response = respond_with_json(sr, b'{"foo": 3}')
     assert_equal(b'{"foo": 3}', b"".join(response))
Ejemplo n.º 5
0
 def extra_headers(self) -> None:
     sr = StubStartResponse()
     respond_with_json(sr, {},
                       extra_headers=[("X-Custom-Header", "Foobar")])
     sr.assert_header_equals("X-Custom-Header", "Foobar")
Ejemplo n.º 6
0
 def content_length(self) -> None:
     sr = StubStartResponse()
     respond_with_json(sr, {"foo": 33})
     sr.assert_header_equals("Content-Length", "11")
Ejemplo n.º 7
0
 def content_type(self) -> None:
     sr = StubStartResponse()
     respond_with_json(sr, {})
     sr.assert_header_equals("Content-Type",
                             "application/json; charset=utf-8")
Ejemplo n.º 8
0
 def custom_status(self) -> None:
     sr = StubStartResponse()
     respond_with_json(sr, {}, status=HTTPStatus.NOT_ACCEPTABLE)
     sr.assert_status(HTTPStatus.NOT_ACCEPTABLE)
Ejemplo n.º 9
0
 def default_status(self) -> None:
     sr = StubStartResponse()
     respond_with_json(sr, {})
     sr.assert_status(HTTPStatus.OK)