22from httpx import ASGITransport
33from httpx import AsyncClient
44
5+ from fractal_server .app .models import UserOAuth
56from fractal_server .app .routes .auth import current_user_act
67from fractal_server .app .routes .auth import current_user_act_ver_prof
78from fractal_server .app .security import _create_first_user
1011_PWD = "12345"
1112
1213
13- async def test_current_user_act_ver_prof (app : FastAPI , client ):
14+ async def test_current_user_act_ver_prof (
15+ app : FastAPI ,
16+ client ,
17+ local_resource_profile_db ,
18+ db ,
19+ ):
1420 await _create_first_user (
1521 email = _EMAIL ,
1622 password = _PWD ,
@@ -33,16 +39,30 @@ async def test_current_user_act_ver_prof(app: FastAPI, client):
3339 # Success in GET-current-user (which depends on `current_user_act`)
3440 res = await client .get ("/auth/current-user/" )
3541 assert res .status_code == 200
42+ user_id = res .json ()["id" ]
3643 assert res .json ()["email" ] == _EMAIL
3744 assert res .json ()["profile_id" ] is None
3845
39- # Failure in GET-current-user, if it provisionally depends on
40- # `current_user_act_ver_prof`
4146 assert app .dependency_overrides == {}
4247 app .dependency_overrides [current_user_act ] = current_user_act_ver_prof
48+
49+ # Failure in GET-current-user, if it provisionally depends on
50+ # `current_user_act_ver_prof`
4351 res = await client .get ("/auth/current-user/" )
4452 assert res .status_code == 403
4553 assert res .json ()["detail" ] == (
4654 "Forbidden access (user.is_verified=True user.profile_id=None)."
4755 )
56+
57+ # Set user.profile_id
58+ _ , profile = local_resource_profile_db
59+ user = await db .get (UserOAuth , user_id )
60+ user .profile_id = profile .id
61+ db .add (user )
62+ await db .commit ()
63+ await db .close ()
64+
65+ res = await client .get ("/auth/current-user/" )
66+ assert res .status_code == 200
67+
4868 app .dependency_overrides = {}
0 commit comments