adjunct.fixtureutils¶
Test utilities for creating WSGI fixtures for testing HTTP clients.
basic_response(start_response, code, body='')
¶
extract_environment(environ)
¶
Extract any CGI environment variable from a dictionary.
fixture(app, *, returns_app=False, timeout=5)
¶
Spin up a fixture application up in its own process.
Set returns_app if app is a callable that returns the actual app (such
as a class).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
_app
|
a WSGI app or a callable that returns a WSGI app |
required |
returns_app
|
bool
|
treat |
False
|
timeout
|
int
|
maximum length of time to wait for the app to start |
5
|
Yields:
| Type | Description |
|---|---|
str
|
The URL serving the WSGI application. |
json_response(start_response, body)
¶
Send a JSON document with a "200 OK" status code.
make_fake_http_response(code=200, body='', headers=None)
¶
Make a fake http.client.HTTPResponse object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
int
|
HTTP status code |
200
|
body
|
str
|
response body |
''
|
headers
|
list[tuple[str, str]] | None
|
any headers to include, if any |
None
|
Returns:
| Type | Description |
|---|---|
HTTPResponse
|
A fake response object. |
read_body(environ)
¶
Read any input from the WSGI environment.
read_json(environ)
¶
Read a JSON document from the WSGI environment.
response(start_response, code, body=b'', headers=None)
¶
Construct a WSGI response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_response
|
_start_response
|
a callable implementing the WSGI |
required |
code
|
int
|
the HTTP status code to use |
required |
body
|
bytes
|
the body of the response |
b''
|
headers
|
list[tuple[str, str]] | None
|
any additional headers to send beside |
None
|
Yields:
| Type | Description |
|---|---|
Iterable[bytes]
|
the wrapped body |