Skip to content

Commit e7e6df5

Browse files
committed
feat: implement iam_configuration fixture
1 parent 60a6647 commit e7e6df5

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
Versions follow [Semantic Versioning](https://semver.org/>) (<major>.<minor>.<patch>).
99

10+
### Added
11+
12+
- `iam_configuration` fixture
13+
1014
## [0.0.4] - 2023-12-15
1115

1216
### Fixed

doc/configuration.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Configuration
2+
#############
3+
4+
pytest-iam can be configured by redefining or expanding the :meth:`~pytest_iam.iam_configuration` fixture.
5+
This returns a :const:`dict` containing the canaille :doc:`canaille:configuration`.
6+
7+
.. code:: python
8+
9+
@pytest.fixture(scope="session")
10+
def iam_configuration(iam_configuration):
11+
iam_configuration["ACL"]["DEFAULT"]["WRITE"].append("groups")
12+
return iam_configuration

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Table of contents
1010

1111
client-applications
1212
resource-servers
13+
configuration
1314
reference
1415
changelog
1516

doc/reference.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Reference
22
#########
33

4+
.. autofunction:: pytest_iam.iam_server
5+
6+
.. autofunction:: pytest_iam.iam_configuration
7+
48
.. autoclass:: pytest_iam.Server
59
:members:
610
:show-inheritance:

pytest_iam/__init__.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
import uuid
44
import wsgiref.simple_server
55
from types import ModuleType
6+
from typing import Any
7+
from typing import Dict
8+
from typing import List
69

710
import portpicker
811
import pytest
912
from canaille import create_app
1013
from canaille.app import models
14+
from canaille.core.models import Group
15+
from canaille.core.models import User
1116
from canaille.core.populate import fake_groups
1217
from canaille.core.populate import fake_users
18+
from canaille.oidc.basemodels import Consent
19+
from canaille.oidc.basemodels import Token
1320
from canaille.oidc.installation import generate_keypair
1421
from flask import Flask
1522
from flask import g
@@ -48,7 +55,7 @@ def url(self) -> str:
4855
"""
4956
return f"http://localhost:{self.port}/"
5057

51-
def random_user(self, **kwargs):
58+
def random_user(self, **kwargs) -> User:
5259
"""
5360
Generates a :class:`~canaille.core.models.User` with random values.
5461
Any parameter will be used instead of a random value.
@@ -60,7 +67,7 @@ def random_user(self, **kwargs):
6067

6168
return user
6269

63-
def random_group(self, **kwargs):
70+
def random_group(self, **kwargs) -> Group:
6471
"""
6572
Generates a :class:`~canaille.core.models.Group` with random values.
6673
Any parameter will be used instead of a random value.
@@ -72,7 +79,7 @@ def random_group(self, **kwargs):
7279

7380
return group
7481

75-
def random_token(self, subject, client, **kwargs):
82+
def random_token(self, subject, client, **kwargs) -> Token:
7683
"""
7784
Generates a test :class:`~canaille.oidc.basemodels.Token` with random values.
7885
Any parameter will be used instead of a random value.
@@ -103,7 +110,7 @@ def login(self, user):
103110
"""
104111
self.logged_user = user
105112

106-
def consent(self, user, client=None):
113+
def consent(self, user, client=None) -> Consent | List[Consent]:
107114
"""
108115
Make a user consent to share data with OIDC clients.
109116
@@ -135,10 +142,13 @@ def consent(self, user, client=None):
135142

136143

137144
@pytest.fixture(scope="session")
138-
def iam_server():
139-
port = portpicker.pick_unused_port()
145+
def iam_configuration() -> Dict[str, Any]:
146+
"""
147+
Fixture for editing the configuration of :meth:`~pytest_iam.iam_server`.
148+
"""
149+
140150
private_key, public_key = generate_keypair()
141-
config = {
151+
return {
142152
"TESTING": True,
143153
"JAVASCRIPT": False,
144154
"WTF_CSRF_ENABLED": False,
@@ -156,7 +166,16 @@ def iam_server():
156166
}
157167
},
158168
}
159-
app = create_app(config=config)
169+
170+
171+
@pytest.fixture(scope="session")
172+
def iam_server(iam_configuration) -> Server:
173+
"""
174+
Fixture that creates a Canaille server listening a random port in a thread.
175+
"""
176+
177+
port = portpicker.pick_unused_port()
178+
app = create_app(config=iam_configuration)
160179
server = Server(app, port)
161180

162181
server_thread = threading.Thread(target=server.httpd.serve_forever)

0 commit comments

Comments
 (0)