Skip to content

Commit 59a0a94

Browse files
committed
chore: bump to canaille 0.0.54
1 parent a5f4a0e commit 59a0a94

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

poetry.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ documentation = "https://pytest-iam.readthedocs.io/en/latest/"
3131

3232
[tool.poetry.dependencies]
3333
python = "^3.9"
34-
canaille = {version = ">=0.0.53,<1", extras = ["oidc"] }
34+
canaille = {version = ">=0.0.54,<1", extras = ["oidc"] }
3535
portpicker = ">=1.6.0"
3636
pytest = ">=7.0.0"
3737
faker = ">=21.0.0"

pytest_iam/__init__.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pytest
1010
from canaille import create_app
1111
from canaille.app import models
12+
from canaille.backends import Backend
1213
from canaille.core.models import Group
1314
from canaille.core.models import User
1415
from canaille.core.populate import fake_groups
@@ -22,17 +23,21 @@
2223
class Server:
2324
"""A proxy object that is returned by the pytest fixture."""
2425

25-
#: The port on which the local http server listens
2626
port: int
27+
"""The port on which the local http server listens."""
2728

28-
#: The authorization server flask app
2929
app: Flask
30+
"""The authorization server flask app."""
3031

31-
#: The module containing the available model classes
3232
models: ModuleType
33+
"""The module containing the available model classes."""
3334

34-
def __init__(self, app, port: int):
35+
backend: Backend
36+
"""The backend used to manage models."""
37+
38+
def __init__(self, app, port: int, backend: Backend):
3539
self.app = app
40+
self.backend = backend
3641
self.port = port
3742
self.httpd = wsgiref.simple_server.make_server("localhost", port, app)
3843
self.models = models
@@ -92,8 +97,8 @@ def random_token(self, subject, client, **kwargs) -> Token:
9297
lifetime=3600,
9398
audience=[client],
9499
)
95-
token.update(**kwargs)
96-
token.save()
100+
self.backend.update(token, **kwargs)
101+
self.backend.save(token)
97102

98103
return token
99104

@@ -111,7 +116,7 @@ def consent(self, user, client=None):
111116
"""
112117

113118
with self.app.app_context():
114-
clients = [client] if client else models.Client.query()
119+
clients = [client] if client else self.backend.query(models.Client)
115120

116121
consents = [
117122
self.models.Consent(
@@ -125,7 +130,7 @@ def consent(self, user, client=None):
125130
]
126131

127132
for consent in consents:
128-
consent.save()
133+
self.backend.save(consent)
129134

130135
if len(consents) > 1:
131136
return consents
@@ -187,7 +192,7 @@ def iam_server(iam_configuration) -> Server:
187192
app = create_app(
188193
config=iam_configuration, env_file=".pytest-iam.env", env_prefix="PYTEST_IAM_"
189194
)
190-
server = Server(app, port)
195+
server = Server(app, port, Backend.instance)
191196

192197
server_thread = threading.Thread(target=server.httpd.serve_forever)
193198
server_thread.start()

tests/conftest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def client(iam_server):
1414
token_endpoint_auth_method="client_secret_basic",
1515
scope=["openid", "profile", "groups"],
1616
)
17-
inst.save()
17+
iam_server.backend.save(inst)
1818
yield inst
19-
inst.delete()
19+
iam_server.backend.delete(inst)
2020

2121

2222
@pytest.fixture
@@ -27,6 +27,6 @@ def user(iam_server):
2727
emails=["[email protected]"],
2828
password="password",
2929
)
30-
inst.save()
30+
iam_server.backend.save(inst)
3131
yield inst
32-
inst.delete()
32+
iam_server.backend.delete(inst)

tests/test_client_application.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_client_dynamic_registration(iam_server):
2929
client_id = response.json()["client_id"]
3030
client_secret = response.json()["client_secret"]
3131

32-
client = iam_server.models.Client.get(client_id=client_id)
32+
client = iam_server.backend.get(iam_server.models.Client, client_id=client_id)
3333
assert client.client_secret == client_secret
3434
client.delete()
3535

@@ -51,7 +51,7 @@ def test_logs(iam_server, caplog):
5151
assert caplog.records[0].msg == "client registration endpoint request: POST: %s"
5252

5353
client_id = response.json()["client_id"]
54-
client = iam_server.models.Client.get(client_id=client_id)
54+
client = iam_server.backend.get(iam_server.models.Client, client_id=client_id)
5555
client.delete()
5656

5757

@@ -101,12 +101,12 @@ def test_login_and_consent(iam_server, client, user, testclient):
101101
# authorization code request (already logged in an consented)
102102
res = requests.get(res.location, allow_redirects=False)
103103

104-
authorization = iam_server.models.AuthorizationCode.get()
104+
authorization = iam_server.backend.get(iam_server.models.AuthorizationCode)
105105
assert authorization.client == client
106106

107107
res = testclient.get(res.headers["Location"])
108108

109-
token = iam_server.models.Token.get()
109+
token = iam_server.backend.get(iam_server.models.Token)
110110
assert token.client == client
111111

112112
assert res.json["userinfo"]["sub"] == "user"

0 commit comments

Comments
 (0)