Refactor test cases for improved readability and consistency
All checks were successful
Backend CI / lint (push) Successful in 9m49s
Backend CI / test (push) Successful in 6m15s

- Adjusted function signatures in various test files to enhance clarity by aligning parameters.
- Updated patching syntax for better readability across test cases.
- Improved formatting and spacing in test assertions and mock setups.
- Ensured consistent use of async/await patterns in async test functions.
- Enhanced comments for better understanding of test intentions.
This commit is contained in:
JSC
2025-08-01 20:53:30 +02:00
parent d926779fe4
commit 6068599a47
39 changed files with 691 additions and 286 deletions

View File

@@ -54,7 +54,11 @@ class TestApiTokenEndpoints:
expires_at_str = data["expires_at"]
# Handle both ISO format with/without timezone info
if expires_at_str.endswith("Z") or "+" in expires_at_str or expires_at_str.count("-") > 2:
if (
expires_at_str.endswith("Z")
or "+" in expires_at_str
or expires_at_str.count("-") > 2
):
expires_at = datetime.fromisoformat(expires_at_str)
else:
# Naive datetime, assume UTC
@@ -84,7 +88,11 @@ class TestApiTokenEndpoints:
expires_at_str = data["expires_at"]
# Handle both ISO format with/without timezone info
if expires_at_str.endswith("Z") or "+" in expires_at_str or expires_at_str.count("-") > 2:
if (
expires_at_str.endswith("Z")
or "+" in expires_at_str
or expires_at_str.count("-") > 2
):
expires_at = datetime.fromisoformat(expires_at_str)
else:
# Naive datetime, assume UTC
@@ -116,7 +124,9 @@ class TestApiTokenEndpoints:
assert response.status_code == 422
@pytest.mark.asyncio
async def test_generate_api_token_unauthenticated(self, client: AsyncClient) -> None:
async def test_generate_api_token_unauthenticated(
self, client: AsyncClient,
) -> None:
"""Test API token generation without authentication."""
response = await client.post(
"/api/v1/auth/api-token",
@@ -186,7 +196,9 @@ class TestApiTokenEndpoints:
assert data["is_expired"] is True
@pytest.mark.asyncio
async def test_get_api_token_status_unauthenticated(self, client: AsyncClient) -> None:
async def test_get_api_token_status_unauthenticated(
self, client: AsyncClient,
) -> None:
"""Test getting API token status without authentication."""
response = await client.get("/api/v1/auth/api-token/status")
assert response.status_code == 401
@@ -264,7 +276,9 @@ class TestApiTokenEndpoints:
assert "email" in data
@pytest.mark.asyncio
async def test_api_token_authentication_invalid_token(self, client: AsyncClient) -> None:
async def test_api_token_authentication_invalid_token(
self, client: AsyncClient,
) -> None:
"""Test authentication with invalid API token."""
headers = {"API-TOKEN": "invalid_token"}
response = await client.get("/api/v1/auth/me", headers=headers)
@@ -297,7 +311,9 @@ class TestApiTokenEndpoints:
assert "API token has expired" in data["detail"]
@pytest.mark.asyncio
async def test_api_token_authentication_empty_token(self, client: AsyncClient) -> None:
async def test_api_token_authentication_empty_token(
self, client: AsyncClient,
) -> None:
"""Test authentication with empty API-TOKEN header."""
# Empty token
headers = {"API-TOKEN": ""}