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:
@@ -73,7 +73,9 @@ class TestAdminSoundEndpoints:
|
||||
) as mock_scan:
|
||||
mock_scan.return_value = mock_results
|
||||
|
||||
response = await authenticated_admin_client.post("/api/v1/admin/sounds/scan")
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/admin/sounds/scan",
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
@@ -114,6 +116,7 @@ class TestAdminSoundEndpoints:
|
||||
) -> None:
|
||||
"""Test scanning sounds with non-admin user."""
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.core.dependencies import get_admin_user
|
||||
|
||||
# Override the admin dependency to raise 403 for non-admin users
|
||||
@@ -150,7 +153,9 @@ class TestAdminSoundEndpoints:
|
||||
) as mock_scan:
|
||||
mock_scan.side_effect = Exception("Directory not found")
|
||||
|
||||
response = await authenticated_admin_client.post("/api/v1/admin/sounds/scan")
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/admin/sounds/scan",
|
||||
)
|
||||
|
||||
assert response.status_code == 500
|
||||
data = response.json()
|
||||
@@ -300,7 +305,9 @@ class TestAdminSoundEndpoints:
|
||||
assert len(results["files"]) == 3
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_normalize_all_sounds_unauthenticated(self, client: AsyncClient) -> None:
|
||||
async def test_normalize_all_sounds_unauthenticated(
|
||||
self, client: AsyncClient,
|
||||
) -> None:
|
||||
"""Test normalizing sounds without authentication."""
|
||||
response = await client.post("/api/v1/admin/sounds/normalize/all")
|
||||
|
||||
@@ -316,6 +323,7 @@ class TestAdminSoundEndpoints:
|
||||
) -> None:
|
||||
"""Test normalizing sounds with non-admin user."""
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.core.dependencies import get_admin_user
|
||||
|
||||
# Override the admin dependency to raise 403 for non-admin users
|
||||
@@ -331,7 +339,8 @@ class TestAdminSoundEndpoints:
|
||||
base_url="http://test",
|
||||
) as client:
|
||||
response = await client.post(
|
||||
"/api/v1/admin/sounds/normalize/all", headers=headers,
|
||||
"/api/v1/admin/sounds/normalize/all",
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 403
|
||||
@@ -405,7 +414,9 @@ class TestAdminSoundEndpoints:
|
||||
|
||||
# Verify the service was called with correct type
|
||||
mock_normalize.assert_called_once_with(
|
||||
sound_type="SDB", force=False, one_pass=None,
|
||||
sound_type="SDB",
|
||||
force=False,
|
||||
one_pass=None,
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -491,7 +502,7 @@ class TestAdminSoundEndpoints:
|
||||
) -> None:
|
||||
"""Test getting extraction processor status."""
|
||||
with patch(
|
||||
"app.services.extraction_processor.extraction_processor.get_status"
|
||||
"app.services.extraction_processor.extraction_processor.get_status",
|
||||
) as mock_get_status:
|
||||
mock_status = {
|
||||
"is_running": True,
|
||||
@@ -502,7 +513,7 @@ class TestAdminSoundEndpoints:
|
||||
mock_get_status.return_value = mock_status
|
||||
|
||||
response = await authenticated_admin_client.get(
|
||||
"/api/v1/admin/sounds/extract/status"
|
||||
"/api/v1/admin/sounds/extract/status",
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -511,7 +522,8 @@ class TestAdminSoundEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_extraction_processor_status_unauthenticated(
|
||||
self, client: AsyncClient
|
||||
self,
|
||||
client: AsyncClient,
|
||||
) -> None:
|
||||
"""Test getting extraction processor status without authentication."""
|
||||
response = await client.get("/api/v1/admin/sounds/extract/status")
|
||||
@@ -528,6 +540,7 @@ class TestAdminSoundEndpoints:
|
||||
) -> None:
|
||||
"""Test getting extraction processor status with non-admin user."""
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.core.dependencies import get_admin_user
|
||||
|
||||
# Override the admin dependency to raise 403 for non-admin users
|
||||
@@ -543,7 +556,8 @@ class TestAdminSoundEndpoints:
|
||||
base_url="http://test",
|
||||
) as client:
|
||||
response = await client.get(
|
||||
"/api/v1/admin/sounds/extract/status", headers=headers
|
||||
"/api/v1/admin/sounds/extract/status",
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 403
|
||||
@@ -551,4 +565,4 @@ class TestAdminSoundEndpoints:
|
||||
assert "Not enough permissions" in data["detail"]
|
||||
|
||||
# Clean up override
|
||||
test_app.dependency_overrides.pop(get_admin_user, None)
|
||||
test_app.dependency_overrides.pop(get_admin_user, None)
|
||||
|
||||
Reference in New Issue
Block a user