Skip to main content

pytest-iam

pytest-iam spawns a lightweight OAuth2 / OpenID Server in a thread to be used in your test suite. The machinery involves Canaille and Authlib.

Installation

pip install pytest-iam

Usage

pytest-iam provides a iam_server fixture that comes with several features:

  • iam_server.url returns the temporary server url
  • iam_server.models provides a modules containing different models (User, Group, Client, Token and AuthorizationCode). Read the canaille documentation to find how to handle those models.
  • iam_server.random_user() and iam_server.random_group() can generate random data for your tests

To run a full authentication process in your test, you can write something like this:

# We suppose you want to test a Flask application
def test_authentication(iam_server, testapp, client, user):
    s = requests.Session()

    # The /protected URL is protected and redirects to the identity provider
    redirect_uri = testapp.get("/protected", status=302).location

    # The IdP presents a login screen
    res = s.post(
        redirect_uri,
        data={
            "login": "user",
            "password": "password",
        },
        allow_redirects=False,
    )

    # The IdP presents a consent screen
    res = s.post(
        redirect_uri,
        data={"answer": "accept"},
        allow_redirects=False,
    )

    # The IdP redirects to the client authorization endpoint
    res = testapp.get(res.headers["Location"])

    # Then the client endpoint finnaly redirects to the initial /protected page
    res = res.follow()
    res.mustcontain("Hello World!")

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_iam-0.0.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_iam-0.0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_iam-0.0.1.tar.gz.

File metadata

  • Download URL: pytest_iam-0.0.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/6.4.10-arch1-1

File hashes

Hashes for pytest_iam-0.0.1.tar.gz
Algorithm Hash digest
SHA256 203660438236de0d5941a9c925d46df53d49754df7edd64a5509b70fc38265e7
MD5 a66b3394b067273439285d5343f97322
BLAKE2b-256 09343574f32e34bff3933b5fafe39de8025817e82c8efac12b20ce0b5d56d6bb

See more details on using hashes here.

File details

Details for the file pytest_iam-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_iam-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/6.4.10-arch1-1

File hashes

Hashes for pytest_iam-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 298addde44260e6b927efcfb199a572407fea31ee60e3188fc326fb39a0a0692
MD5 8646edc6f955392792aa879960ee9d2d
BLAKE2b-256 2d004a11a1657f131fb6f307bcef31b635c26c31ab491ac5a186c27e68fde170

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

This release

0.0.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page