MCPcopy Create free account
hub / github.com/fastapi-users/fastapi-users / test_active_user

Method test_active_user

tests/test_router_oauth.py:224–253  ·  view source on GitHub ↗
(
        self,
        async_method_mocker: AsyncMethodMocker,
        test_app_client: httpx.AsyncClient,
        oauth_client: BaseOAuth2,
        user_oauth: UserOAuthModel,
        user_manager_oauth: UserManagerMock,
        access_token: str,
    )

Source from the content-addressed store, hash-verified

222 assert user_manager_oauth.on_after_login.called is False
223
224 async def test_active_user(
225 self,
226 async_method_mocker: AsyncMethodMocker,
227 test_app_client: httpx.AsyncClient,
228 oauth_client: BaseOAuth2,
229 user_oauth: UserOAuthModel,
230 user_manager_oauth: UserManagerMock,
231 access_token: str,
232 ):
233 state_jwt = generate_state_token({"csrftoken": "CSRFTOKEN"}, JWT_SECRET)
234 async_method_mocker(oauth_client, "get_access_token", return_value=access_token)
235 async_method_mocker(
236 oauth_client, "get_id_email", return_value=("user_oauth1", user_oauth.email)
237 )
238 async_method_mocker(
239 user_manager_oauth, "oauth_callback", return_value=user_oauth
240 )
241
242 test_app_client.cookies.set("fastapiusersoauthcsrf", "CSRFTOKEN")
243 response = await test_app_client.get(
244 "/oauth/callback",
245 params={"code": "CODE", "state": state_jwt},
246 )
247
248 assert response.status_code == status.HTTP_200_OK
249
250 data = cast(dict[str, Any], response.json())
251 assert data["access_token"] == str(user_oauth.id)
252
253 assert user_manager_oauth.on_after_login.called is True
254
255 async def test_inactive_user(
256 self,

Callers

nothing calls this directly

Calls 4

generate_state_tokenFunction · 0.90
async_method_mockerFunction · 0.85
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected