Esempio n. 1
0
    def respond_with_content(
        self,
        content: bytes,
        *,
        status: HTTPStatus = HTTPStatus.OK,
        content_type: str = "application/octet-stream",
        extra_headers: Sequence[Header] = [],
    ) -> Iterable[bytes]:
        """Prepare an WSGI response.

        >>> def handler(start_response, request):
        ...     return respond_with_content(start_response, b"content")

        The response will include a Content-Type and a Content-Length header.
        """
        return respond_with_content(
            self.start_response,
            content,
            status=status,
            content_type=content_type,
            extra_headers=extra_headers,
        )
Esempio n. 2
0
 def custom_content_type(self) -> None:
     sr = StubStartResponse()
     respond_with_content(sr, b"", content_type="text/plain")
     sr.assert_header_equals("Content-Type", "text/plain")
Esempio n. 3
0
 def default_content_type(self) -> None:
     sr = StubStartResponse()
     respond_with_content(sr, b"")
     sr.assert_header_equals("Content-Type", "application/octet-stream")
Esempio n. 4
0
 def custom_status(self) -> None:
     sr = StubStartResponse()
     respond_with_content(sr, b"", status=HTTPStatus.NOT_ACCEPTABLE)
     sr.assert_status(HTTPStatus.NOT_ACCEPTABLE)
Esempio n. 5
0
 def default_status(self) -> None:
     sr = StubStartResponse()
     respond_with_content(sr, b"")
     sr.assert_status(HTTPStatus.OK)
Esempio n. 6
0
 def return_value(self) -> None:
     sr = StubStartResponse()
     response = respond_with_content(sr, b"foobar")
     assert_equal(b"foobar", b"".join(response))
Esempio n. 7
0
 def extra_headers(self) -> None:
     sr = StubStartResponse()
     respond_with_content(sr,
                          b"",
                          extra_headers=[("X-Custom-Header", "Foobar")])
     sr.assert_header_equals("X-Custom-Header", "Foobar")
Esempio n. 8
0
 def content_length(self) -> None:
     sr = StubStartResponse()
     respond_with_content(sr, b"foobar")
     sr.assert_header_equals("Content-Length", "6")