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:
@@ -57,7 +57,8 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_no_header(
|
||||
self, mock_auth_service: AsyncMock,
|
||||
self,
|
||||
mock_auth_service: AsyncMock,
|
||||
) -> None:
|
||||
"""Test API token authentication without API-TOKEN header."""
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
@@ -68,7 +69,8 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_empty_token(
|
||||
self, mock_auth_service: AsyncMock,
|
||||
self,
|
||||
mock_auth_service: AsyncMock,
|
||||
) -> None:
|
||||
"""Test API token authentication with empty token."""
|
||||
api_token_header = " "
|
||||
@@ -81,7 +83,8 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_whitespace_token(
|
||||
self, mock_auth_service: AsyncMock,
|
||||
self,
|
||||
mock_auth_service: AsyncMock,
|
||||
) -> None:
|
||||
"""Test API token authentication with whitespace-only token."""
|
||||
api_token_header = " "
|
||||
@@ -94,7 +97,8 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_invalid_token(
|
||||
self, mock_auth_service: AsyncMock,
|
||||
self,
|
||||
mock_auth_service: AsyncMock,
|
||||
) -> None:
|
||||
"""Test API token authentication with invalid token."""
|
||||
mock_auth_service.get_user_by_api_token.return_value = None
|
||||
@@ -146,7 +150,8 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_api_token_service_exception(
|
||||
self, mock_auth_service: AsyncMock,
|
||||
self,
|
||||
mock_auth_service: AsyncMock,
|
||||
) -> None:
|
||||
"""Test API token authentication with service exception."""
|
||||
mock_auth_service.get_user_by_api_token.side_effect = Exception(
|
||||
@@ -186,7 +191,8 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_flexible_falls_back_to_jwt(
|
||||
self, mock_auth_service: AsyncMock,
|
||||
self,
|
||||
mock_auth_service: AsyncMock,
|
||||
) -> None:
|
||||
"""Test flexible authentication falls back to JWT when no API token."""
|
||||
# Mock the get_current_user function (normally imported)
|
||||
@@ -197,7 +203,9 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api_token_no_expiry_never_expires(
|
||||
self, mock_auth_service: AsyncMock, test_user: User,
|
||||
self,
|
||||
mock_auth_service: AsyncMock,
|
||||
test_user: User,
|
||||
) -> None:
|
||||
"""Test API token with no expiry date never expires."""
|
||||
test_user.api_token_expires_at = None
|
||||
@@ -211,7 +219,9 @@ class TestApiTokenDependencies:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api_token_with_whitespace(
|
||||
self, mock_auth_service: AsyncMock, test_user: User,
|
||||
self,
|
||||
mock_auth_service: AsyncMock,
|
||||
test_user: User,
|
||||
) -> None:
|
||||
"""Test API token with leading/trailing whitespace is handled correctly."""
|
||||
mock_auth_service.get_user_by_api_token.return_value = test_user
|
||||
|
||||
Reference in New Issue
Block a user