fastlife.testing.testclient

Testing your application.

Module Contents

Classes

WebResponse

Represent an http response made by the WebTestClient browser.

WebTestClient

The fake browser used for testing purpose.

API

class fastlife.testing.testclient.WebResponse(client: fastlife.testing.testclient.WebTestClient, origin: str, response: httpx.Response)

Represent an http response made by the WebTestClient browser.

Initialization

by_label_text(text: str) fastlife.testing.dom.Element | None

Search a dom element by its associated label text.

by_node_name(node_name: str, *, attrs: dict[str, str] | None = None) list[fastlife.testing.dom.Element]

List dom element having the given node name, and eventually attributes.

by_text(text: str, *, node_name: str | None = None, position: int | None = None) fastlife.testing.dom.Element | None

Search a dom element by its text.

property content_type: str

Get the content type of the response, from the header.

property form: fastlife.testing.form.WebForm

The form element of the html response.

property headers: httpx.Headers

All http headers of the response.

property html: fastlife.testing.dom.Element

Http response body as an Element.

property html_body: fastlife.testing.dom.Element

The body element of the html response.

property is_redirect: bool

True for any kind of http redirect status.

property status_code: int

Http status code.

property text: str

Http response body.

class fastlife.testing.testclient.WebTestClient(app: fastlife.domain.model.asgi.ASGIApp, *, settings: fastlife.settings.Settings | None = None, cookies: fastlife.testing.testclient.CookieTypes | None = None)

The fake browser used for testing purpose.

Initialization

property cookies: fastlife.testing.testclient.Cookies

HTTP Cookies.

delete(url: str, follow_redirects: bool = True) fastlife.testing.testclient.WebResponse

Perform http DELETE request.

get(url: str, follow_redirects: bool = True) fastlife.testing.testclient.WebResponse

Perform http GET request.

post(url: str, data: multidict.MultiDict[str], *, headers: collections.abc.Mapping[str, Any] | None = None, follow_redirects: bool = True) fastlife.testing.testclient.WebResponse

Perform http POST request in “application/x-www-form-urlencoded” format.

request(method: Literal[GET, POST, DELETE], url: str, *, content: str | None = None, headers: collections.abc.Mapping[str, str] | None = None, max_redirects: int = 0) fastlife.testing.testclient.WebResponse

Perform http requests.

property session: collections.abc.MutableMapping[str, Any]

Server session stored in a cookies.