pytest-iam
==========
pytest-iam spawns a lightweight OAuth2 / OpenID Server (OIDC) / SCIM in a thread to be used in your test suite.
The machinery involves [Canaille](https://canaille.readthedocs.io) and [Authlib](https://authlib.org).
- [Repository](https://github.com/pytest-dev/pytest-iam)
- [Package](https://pypi.org/project/pytest-iam)
- [Documentation](https://pytest-iam.readthedocs.io)
Installation
------------
```console
uv add pytest-iam
```
Usage
-----
pytest-iam provides tools to test your application authentication mechanism against a OAuth2/OIDC server, with SCIM support:
- It launches a [Canaille](https://canaille.readthedocs.io) instance on a random port;
- 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](https://pytest-iam.readthedocs.io/en/latest/reference.html)
- 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:
```python
def test_authentication(iam_server, test_client):
# create a random user on the IAM server
user = iam_server.random_user()
# log the user in and make it consent all the clients
iam_server.login(user)
iam_server.consent(user)
# 1. attempt to access a protected page, returns a redirection to the IAM
res = test_client.get("/protected")
# 2. authorization code request
res = iam_server.test_client.get(res.location)
# 3. load your application authorization endpoint
res = test_client.get(res.location)
# 4. now you have access to the protected page
res = test_client.get("/protected")
assert "Hello, world!" in res.text
```
Check the [client application](https://pytest-iam.readthedocs.io/en/latest/client-applications.html) or
[resource server](https://pytest-iam.readthedocs.io/en/latest/resource-servers.html) tutorials
for more usecases.
Raw data
{
"_id": null,
"home_page": null,
"name": "pytest-iam",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "iam, identity, oauth, oauth2, oidc, openid, pytest, scim, unit tests",
"author": null,
"author_email": "Yaal Coop <contact@yaal.coop>",
"download_url": "https://files.pythonhosted.org/packages/98/a3/5303e9a002ce02f1269c31a65090b9a00c35065a4298f7cfdb3afcc73746/pytest_iam-0.2.3.tar.gz",
"platform": null,
"description": "pytest-iam\n==========\n\npytest-iam spawns a lightweight OAuth2 / OpenID Server (OIDC) / SCIM in a thread to be used in your test suite.\nThe machinery involves [Canaille](https://canaille.readthedocs.io) and [Authlib](https://authlib.org).\n\n- [Repository](https://github.com/pytest-dev/pytest-iam)\n- [Package](https://pypi.org/project/pytest-iam)\n- [Documentation](https://pytest-iam.readthedocs.io)\n\nInstallation\n------------\n\n```console\nuv add pytest-iam\n```\n\nUsage\n-----\n\npytest-iam provides tools to test your application authentication mechanism against a OAuth2/OIDC server, with SCIM support:\n\n- It launches a [Canaille](https://canaille.readthedocs.io) instance on a random port;\n- It provides a ``iam_server`` fixture that comes with several features:\n - the URL of the IAM server to configure your application\n - IAM models (Users, groups, clients, tokens etc.) to prepare your tests and check the side effects.\n More details on [the reference](https://pytest-iam.readthedocs.io/en/latest/reference.html)\n - utilities to log-in users and give their consent to your application\n - utilities to generate random users and groups\n\nTo run a full authentication process for a client application in your test,\nyou can write something like this:\n\n```python\ndef test_authentication(iam_server, test_client):\n # create a random user on the IAM server\n user = iam_server.random_user()\n\n # log the user in and make it consent all the clients\n iam_server.login(user)\n iam_server.consent(user)\n\n # 1. attempt to access a protected page, returns a redirection to the IAM\n res = test_client.get(\"/protected\")\n\n # 2. authorization code request\n res = iam_server.test_client.get(res.location)\n\n # 3. load your application authorization endpoint\n res = test_client.get(res.location)\n\n # 4. now you have access to the protected page\n res = test_client.get(\"/protected\")\n\n assert \"Hello, world!\" in res.text\n```\n\nCheck the [client application](https://pytest-iam.readthedocs.io/en/latest/client-applications.html) or\n[resource server](https://pytest-iam.readthedocs.io/en/latest/resource-servers.html) tutorials\nfor more usecases.\n",
"bugtrack_url": null,
"license": null,
"summary": "A fully functional OAUTH2 / OpenID Connect (OIDC) / SCIM server to be used in your testsuite",
"version": "0.2.3",
"project_urls": null,
"split_keywords": [
"iam",
" identity",
" oauth",
" oauth2",
" oidc",
" openid",
" pytest",
" scim",
" unit tests"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "e24968be66189f96ccf1400e83ca22c7c92f950a766bed5fa8de2a89d1399de2",
"md5": "53d3a2f03b46a35b2498ebc616c51407",
"sha256": "c4bed97de2e5857e4019d2ac6ef9516a8c69ccc04adf631bd15a0b8b767b65d4"
},
"downloads": -1,
"filename": "pytest_iam-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "53d3a2f03b46a35b2498ebc616c51407",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 5717,
"upload_time": "2025-07-09T16:11:36",
"upload_time_iso_8601": "2025-07-09T16:11:36.565181Z",
"url": "https://files.pythonhosted.org/packages/e2/49/68be66189f96ccf1400e83ca22c7c92f950a766bed5fa8de2a89d1399de2/pytest_iam-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "98a35303e9a002ce02f1269c31a65090b9a00c35065a4298f7cfdb3afcc73746",
"md5": "77d96678136796ad883154636f1f43dd",
"sha256": "ab199b6b26b0e5309fe0193165d1f0daf5f691d0ce4630db27c85c8f349996f5"
},
"downloads": -1,
"filename": "pytest_iam-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "77d96678136796ad883154636f1f43dd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 74153,
"upload_time": "2025-07-09T16:11:37",
"upload_time_iso_8601": "2025-07-09T16:11:37.646199Z",
"url": "https://files.pythonhosted.org/packages/98/a3/5303e9a002ce02f1269c31a65090b9a00c35065a4298f7cfdb3afcc73746/pytest_iam-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-09 16:11:37",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "pytest-iam"
}