Skip to main content

pytest-iam

pytest-iam spawns a lightweight OAuth2 / OpenID Server (OIDC) 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 tools to test your application authentication mechanism agaist a OAuth2/OIDC server:

  • It launches a Canaille instance
  • It provides a iam_server fixture that comes with several features:
    • the URL of the IAM server to configure your application
    • IAM models (Users, groups, clients, tokens etc.) to prepare your tests and check the side effects. More details on the reference
    • utilities to log-in users and give their consent to your application
    • utilities to generate random users and groups

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

def test_authentication(iam_server, testapp, client):
    # create a random user on the IAM server
    user = iam_server.random_user()

    # logs the user in give its consent to your application
    iam_server.login(user)
    iam_server.consent(user)

    # simulate an attempt to access a protected page of your app
    response = testapp.get("/protected", status=302)

    # get an authorization code request at the IAM
    res = requests.get(res.location, allow_redirects=False)

    # access to the redirection URI
    res = testclient.get(res.headers["Location"])
    res.mustcontain("Hello World!")

Check the client application or resource server tutorials for more usecases.

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.4.tar.gz (4.6 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.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_iam-0.0.4.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/6.6.7-arch1-1

File hashes

Hashes for pytest_iam-0.0.4.tar.gz
Algorithm Hash digest
SHA256 5ddd40e674eb5a8ef0de064f272aa423fd5060559c305c01886672486baa544e
MD5 8d5127a66f930715bf02a3f1c0af743a
BLAKE2b-256 2fce9e88fd9d58e2e5d2c2bf2995bf918d35ede036b8523934f8a19a567e6be9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_iam-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/6.6.7-arch1-1

File hashes

Hashes for pytest_iam-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 da7efaccae67d138d7af4c5414c6a431fbddfd1f744140f61a9d2d69f30caf2e
MD5 5469082f2b3c9f44785633fc2907c3e5
BLAKE2b-256 1b63f9632dd0e28256335621aa768df96a2555d35829123b3524a22573c80cfd

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

This release

0.0.4 This release

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

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