diff --git a/fastapi_users/router/common.py b/fastapi_users/router/common.py index 7200b9f5..0e37c85f 100644 --- a/fastapi_users/router/common.py +++ b/fastapi_users/router/common.py @@ -27,4 +27,3 @@ class ErrorCode(str, Enum): UPDATE_USER_INVALID_PASSWORD = "UPDATE_USER_INVALID_PASSWORD" ACCESS_TOKEN_ALREADY_EXPIRED = "ACCESS_TOKEN_ALREADY_EXPIRED" ACCESS_TOKEN_DECODE_ERROR = "ACCESS_TOKEN_DECODE_ERROR" - diff --git a/fastapi_users/router/oauth.py b/fastapi_users/router/oauth.py index a4deb0db..087ecdca 100644 --- a/fastapi_users/router/oauth.py +++ b/fastapi_users/router/oauth.py @@ -92,11 +92,15 @@ def get_oauth_router( }, ErrorCode.ACCESS_TOKEN_DECODE_ERROR: { "summary": "Access token is error.", - "value": {"detail": ErrorCode.ACCESS_TOKEN_DECODE_ERROR}, + "value": { + "detail": ErrorCode.ACCESS_TOKEN_DECODE_ERROR + }, }, ErrorCode.ACCESS_TOKEN_ALREADY_EXPIRED: { "summary": "Access token is already expired.", - "value": {"detail": ErrorCode.ACCESS_TOKEN_ALREADY_EXPIRED}, + "value": { + "detail": ErrorCode.ACCESS_TOKEN_ALREADY_EXPIRED + }, }, } } @@ -239,11 +243,15 @@ def get_oauth_associate_router( }, ErrorCode.ACCESS_TOKEN_DECODE_ERROR: { "summary": "Access token is error.", - "value": {"detail": ErrorCode.ACCESS_TOKEN_DECODE_ERROR}, + "value": { + "detail": ErrorCode.ACCESS_TOKEN_DECODE_ERROR + }, }, ErrorCode.ACCESS_TOKEN_ALREADY_EXPIRED: { "summary": "Access token is already expired.", - "value": {"detail": ErrorCode.ACCESS_TOKEN_ALREADY_EXPIRED}, + "value": { + "detail": ErrorCode.ACCESS_TOKEN_ALREADY_EXPIRED + }, }, } } diff --git a/tests/test_router_oauth.py b/tests/test_router_oauth.py index d5d95bb7..54d80dae 100644 --- a/tests/test_router_oauth.py +++ b/tests/test_router_oauth.py @@ -309,7 +309,6 @@ class TestCallback: json = response.json() assert json["detail"] == ErrorCode.OAUTH_NOT_AVAILABLE_EMAIL - async def test_callback_token_expired( self, async_method_mocker: AsyncMethodMocker, @@ -361,6 +360,7 @@ class TestCallback: assert response.status_code == status.HTTP_400_BAD_REQUEST assert user_manager_oauth.on_after_login.called is False + @pytest.mark.router @pytest.mark.oauth @pytest.mark.asyncio @@ -602,7 +602,7 @@ class TestAssociateCallback: assert response.status_code == status.HTTP_400_BAD_REQUEST json = response.json() assert json["detail"] == ErrorCode.OAUTH_NOT_AVAILABLE_EMAIL - + async def test_callback_token_expired( self, async_method_mocker: AsyncMethodMocker, @@ -612,10 +612,10 @@ class TestAssociateCallback: user_manager_oauth: UserManagerMock, access_token: str, ): - state_jwt = generate_state_token({"sub": str(user_oauth.id)}, "SECRET", lifetime_seconds=-1) - async_method_mocker( - oauth_client, "get_access_token", return_value=access_token + state_jwt = generate_state_token( + {"sub": str(user_oauth.id)}, "SECRET", lifetime_seconds=-1 ) + async_method_mocker(oauth_client, "get_access_token", return_value=access_token) async_method_mocker( oauth_client, "get_id_email", return_value=("user_oauth1", user_oauth.email) ) @@ -643,9 +643,7 @@ class TestAssociateCallback: access_token: str, ): state_jwt = generate_state_token({"sub": str(user_oauth.id)}, "RANDOM") - async_method_mocker( - oauth_client, "get_access_token", return_value=access_token - ) + async_method_mocker(oauth_client, "get_access_token", return_value=access_token) async_method_mocker( oauth_client, "get_id_email", return_value=("user_oauth1", user_oauth.email) ) @@ -663,6 +661,7 @@ class TestAssociateCallback: assert response.status_code == status.HTTP_400_BAD_REQUEST + @pytest.mark.asyncio @pytest.mark.oauth @pytest.mark.router