Skip to content

Commit e742acf

Browse files
committed
l'api retourne un UserSchema
1 parent 8e357ef commit e742acf

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

core/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class AuthController(ControllerBase):
176176
@route.post(
177177
"/login",
178178
auth=None,
179-
response={200: dict[Literal["id"], int], 401: dict[str, list[str]]},
179+
response={200: UserSchema, 401: dict[str, list[str]]},
180180
)
181181
def login(self, body: LoginSchema):
182182
"""Authenticate a user by username, email or AE account id.
@@ -195,4 +195,4 @@ def login(self, body: LoginSchema):
195195

196196
user = login_form.get_user()
197197
login(self.context.request, user)
198-
return {"id": user.id}
198+
return user

core/tests/test_auth_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from model_bakery import baker
88

99
from core.models import User
10+
from core.schemas import UserSchema
1011
from counter.models import Customer
1112

1213

@@ -17,6 +18,7 @@ def post_login(client: Client, identifier: str, password: str):
1718
content_type="application/json",
1819
)
1920

21+
2022
@pytest.fixture()
2123
def user(db) -> User:
2224
return baker.make(User, password=make_password("plop"))
@@ -35,7 +37,7 @@ def test_api_login_success(client: Client, user: User, identifier_getter):
3537
response = post_login(client, identifier_getter(user), "plop")
3638

3739
assert response.status_code == 200
38-
assert response.json() == {"id": user.id}
40+
assert response.json() == UserSchema.model_validate(user).model_dump(mode="json")
3941
assert int(client.session["_auth_user_id"]) == user.id
4042

4143

@@ -55,4 +57,4 @@ def test_api_login_fail_if_already_authenticated(client: Client, user: User):
5557
response = post_login(client, user.username, "plop")
5658

5759
assert response.status_code == 403
58-
assert int(client.session["_auth_user_id"]) == already_logged_user.id
60+
assert int(client.session["_auth_user_id"]) == already_logged_user.id

0 commit comments

Comments
 (0)