Refactor test cases for improved readability and consistency
- 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:
@@ -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": ""}
|
||||
|
||||
Reference in New Issue
Block a user