diff --git a/src/api/v1/auth.py b/src/api/v1/auth.py index 0e3934d..0a24366 100644 --- a/src/api/v1/auth.py +++ b/src/api/v1/auth.py @@ -27,7 +27,7 @@ async def login( session: sessionDep, credential: Annotated[OAuth2PasswordRequestForm, Depends()], response: Response, - fingerprint: str = Form(), + fingerprint: str = Form(min_length=5), ): result = await AuthService(session).login( credential.username, credential.password, fingerprint=fingerprint diff --git a/tests/integration_tests/test_auth_api.py b/tests/integration_tests/test_auth_api.py index a42545a..28d59c8 100644 --- a/tests/integration_tests/test_auth_api.py +++ b/tests/integration_tests/test_auth_api.py @@ -1,5 +1,5 @@ from httpx import AsyncClient - +import pytest from src.core.settings import settings from src.schemas.users import User @@ -15,14 +15,30 @@ async def test_registration(ac): assert result.json()["is_active"] -async def test_login(ac: AsyncClient): +@pytest.mark.parametrize( + "fingerprint, username,password,expected_status", + [("string", "kot", "P@ssw0rd", 200), ("", "kot", "P@ssw0rd", 422)], +) +async def test_login( + ac: AsyncClient, + fingerprint: str, + username: str, + password: str, + expected_status: int, +): result = await ac.post( f"{settings.api.v1_login_url}/login", data={ + "fingerprint": fingerprint, "grant_type": "password", - "username": "kot", - "password": "P@ssw0rd", + "username": username, + "password": password, }, ) - assert result.status_code == 200 - assert result.json().get("access_token") + assert result.status_code == expected_status + if expected_status == 200: + assert result.json().get("access_token") is not None + else: + json_response = result.json() + if expected_status == 422: + assert "detail" in json_response