Reference#

This page lists the fixtures and the classes of pytest-iam.

Fixtures#

pytest_iam.iam_server() → pytest_iam.Server[source]#

Session fixture that starts the IAM server in a thread, and returns a Server.

pytest_iam.iam_configuration() → dict[source]#

Session fixture that returns the settings of the IAM server.

Redefine it to change the settings, as described in Configuration.

pytest_iam.iam_server_port() → int[source]#

Session fixture that returns the port of the IAM server.

By default, it is a free port. Redefine it to use a fixed port.

pytest_iam.iam_restore_login()[source]#

Autouse fixture that logs out the users logged in during each test.

It undoes the login() calls, and the logins through the forms of test_client.

pytest_iam.iam_restore_mounts()[source]#

Autouse fixture that unmounts the applications mounted during each test.

It undoes the mount() and unmount() calls.

Server#

class pytest_iam.Server[source]#

The IAM server, returned by the iam_server() fixture.

consent(user: User, client: Client | None = None) → Consent | list[Consent] | None[source]#

Record the consent of a user for a client.

With a None client, the user consents to all the existing clients. Return the consent, the list of consents when several clients exist, or None when no client exists.

login(user: User) → None[source]#

Log a user in on the IAM server, without the login form.

The user is logged out at the end of the test, or when the user logs out on the IAM server. A login made by a module or session scoped fixture lasts until logout().

logout() → None[source]#

Log out the user logged in with login().

mount(url: str, app: Callable[[dict[str, Any], StartResponse], Iterable[bytes]]) → None[source]#

Serve the requests that the IAM server sends to a URL with a WSGI application.

The URL is a scheme, a host and an optional port, such as http://client.test. The application is unmounted at the end of the test. A mount made by a module or session scoped fixture lasts until unmount().

random_group(**kwargs: Any) → Group[source]#

Create and save a Group with random values.

Keyword arguments set some of the values. Without members, the only member is a new random user.

random_token(subject: User | None, client: Client, **kwargs: Any) → Token[source]#

Create and save an access Token for a client.

With a None subject, the token belongs to the client only. The token has the scopes of the client, and lasts 3600 seconds. Keyword arguments set some of the values.

random_user(**kwargs: Any) → User[source]#

Create and save a User with random values.

Keyword arguments set some of the values.

unmount(url: str) → None[source]#

Unmount the application mounted on a URL with mount().

app: Flask#

The Flask application of the IAM server.

backend: Backend#

The Canaille backend, to save, get and delete models.

logged_user: User | None#

The user logged in with login(), or None.

logging: bool = False#

Whether the HTTP server prints one line per request.

models: ModuleType#

The module of the Canaille models, such as models.User.

mounts: dict[str, Callable[[dict[str, Any], StartResponse], Iterable[bytes]]]#

The applications mounted with mount(), by URL.

port: int#

The port of the HTTP server.

test_client: Client#

A test client that sends requests to the IAM server without network.

property url: str#

The URL of the IAM server, ending with a slash.

Models#

Server.models gives access to the Canaille models, documented in Data models: