Refactor test files for improved readability and consistency
- Removed unnecessary blank lines and adjusted formatting in test files. - Ensured consistent use of commas in function calls and assertions across various test cases. - Updated import statements for better organization and clarity. - Enhanced mock setups in tests for better isolation and reliability. - Improved assertions to follow a consistent style for better readability.
This commit is contained in:
@@ -66,7 +66,7 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory"
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory",
|
||||
) as mock_scan:
|
||||
mock_scan.return_value = mock_results
|
||||
|
||||
@@ -167,7 +167,7 @@ class TestSoundEndpoints:
|
||||
headers = {"API-TOKEN": "admin_api_token"}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory"
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory",
|
||||
) as mock_scan:
|
||||
mock_scan.return_value = mock_results
|
||||
|
||||
@@ -192,7 +192,7 @@ class TestSoundEndpoints:
|
||||
):
|
||||
"""Test scanning sounds when service raises an error."""
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory"
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory",
|
||||
) as mock_scan:
|
||||
mock_scan.side_effect = Exception("Directory not found")
|
||||
|
||||
@@ -244,7 +244,7 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory"
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory",
|
||||
) as mock_scan:
|
||||
mock_scan.return_value = mock_results
|
||||
|
||||
@@ -285,7 +285,7 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory"
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory",
|
||||
) as mock_scan:
|
||||
mock_scan.return_value = mock_results
|
||||
|
||||
@@ -307,14 +307,14 @@ class TestSoundEndpoints:
|
||||
):
|
||||
"""Test custom directory scanning with invalid path."""
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory"
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory",
|
||||
) as mock_scan:
|
||||
mock_scan.side_effect = ValueError(
|
||||
"Directory does not exist: /invalid/path"
|
||||
"Directory does not exist: /invalid/path",
|
||||
)
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/scan/custom", params={"directory": "/invalid/path"}
|
||||
"/api/v1/sounds/scan/custom", params={"directory": "/invalid/path"},
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
@@ -325,7 +325,7 @@ class TestSoundEndpoints:
|
||||
async def test_scan_custom_directory_unauthenticated(self, client: AsyncClient):
|
||||
"""Test custom directory scanning without authentication."""
|
||||
response = await client.post(
|
||||
"/api/v1/sounds/scan/custom", params={"directory": "/some/path"}
|
||||
"/api/v1/sounds/scan/custom", params={"directory": "/some/path"},
|
||||
)
|
||||
|
||||
assert response.status_code == 401
|
||||
@@ -377,12 +377,12 @@ class TestSoundEndpoints:
|
||||
):
|
||||
"""Test custom directory scanning when service raises an error."""
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory"
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory",
|
||||
) as mock_scan:
|
||||
mock_scan.side_effect = Exception("Permission denied")
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/scan/custom", params={"directory": "/restricted/path"}
|
||||
"/api/v1/sounds/scan/custom", params={"directory": "/restricted/path"},
|
||||
)
|
||||
|
||||
assert response.status_code == 500
|
||||
@@ -442,7 +442,7 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory"
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory",
|
||||
) as mock_scan:
|
||||
mock_scan.return_value = mock_results
|
||||
|
||||
@@ -480,7 +480,7 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory"
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory",
|
||||
) as mock_scan:
|
||||
mock_scan.return_value = mock_results
|
||||
|
||||
@@ -570,12 +570,12 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_all_sounds"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_all_sounds",
|
||||
) as mock_normalize:
|
||||
mock_normalize.return_value = mock_results
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/all"
|
||||
"/api/v1/sounds/normalize/all",
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -608,12 +608,12 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_all_sounds"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_all_sounds",
|
||||
) as mock_normalize:
|
||||
mock_normalize.return_value = mock_results
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/all", params={"force": True}
|
||||
"/api/v1/sounds/normalize/all", params={"force": True},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -637,12 +637,12 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_all_sounds"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_all_sounds",
|
||||
) as mock_normalize:
|
||||
mock_normalize.return_value = mock_results
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/all", params={"one_pass": True}
|
||||
"/api/v1/sounds/normalize/all", params={"one_pass": True},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -684,7 +684,7 @@ class TestSoundEndpoints:
|
||||
base_url="http://test",
|
||||
) as client:
|
||||
response = await client.post(
|
||||
"/api/v1/sounds/normalize/all", headers=headers
|
||||
"/api/v1/sounds/normalize/all", headers=headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 403
|
||||
@@ -702,12 +702,12 @@ class TestSoundEndpoints:
|
||||
):
|
||||
"""Test normalization when service raises an error."""
|
||||
with patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_all_sounds"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_all_sounds",
|
||||
) as mock_normalize:
|
||||
mock_normalize.side_effect = Exception("Normalization service failed")
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/all"
|
||||
"/api/v1/sounds/normalize/all",
|
||||
)
|
||||
|
||||
assert response.status_code == 500
|
||||
@@ -758,12 +758,12 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sounds_by_type"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sounds_by_type",
|
||||
) as mock_normalize:
|
||||
mock_normalize.return_value = mock_results
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/type/SDB"
|
||||
"/api/v1/sounds/normalize/type/SDB",
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -779,7 +779,7 @@ class TestSoundEndpoints:
|
||||
|
||||
# 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
|
||||
@@ -790,7 +790,7 @@ class TestSoundEndpoints:
|
||||
):
|
||||
"""Test normalization with invalid sound type."""
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/type/INVALID"
|
||||
"/api/v1/sounds/normalize/type/INVALID",
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
@@ -814,7 +814,7 @@ class TestSoundEndpoints:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sounds_by_type"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sounds_by_type",
|
||||
) as mock_normalize:
|
||||
mock_normalize.return_value = mock_results
|
||||
|
||||
@@ -827,7 +827,7 @@ class TestSoundEndpoints:
|
||||
|
||||
# Verify parameters were passed correctly
|
||||
mock_normalize.assert_called_once_with(
|
||||
sound_type="TTS", force=True, one_pass=False
|
||||
sound_type="TTS", force=True, one_pass=False,
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -866,7 +866,7 @@ class TestSoundEndpoints:
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sound"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sound",
|
||||
) as mock_normalize_sound,
|
||||
patch("app.repositories.sound.SoundRepository.get_by_id") as mock_get_sound,
|
||||
):
|
||||
@@ -874,7 +874,7 @@ class TestSoundEndpoints:
|
||||
mock_normalize_sound.return_value = mock_result
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/42"
|
||||
"/api/v1/sounds/normalize/42",
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -897,12 +897,12 @@ class TestSoundEndpoints:
|
||||
):
|
||||
"""Test normalization of non-existent sound."""
|
||||
with patch(
|
||||
"app.repositories.sound.SoundRepository.get_by_id"
|
||||
"app.repositories.sound.SoundRepository.get_by_id",
|
||||
) as mock_get_sound:
|
||||
mock_get_sound.return_value = None
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/999"
|
||||
"/api/v1/sounds/normalize/999",
|
||||
)
|
||||
|
||||
assert response.status_code == 404
|
||||
@@ -945,7 +945,7 @@ class TestSoundEndpoints:
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sound"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sound",
|
||||
) as mock_normalize_sound,
|
||||
patch("app.repositories.sound.SoundRepository.get_by_id") as mock_get_sound,
|
||||
):
|
||||
@@ -953,7 +953,7 @@ class TestSoundEndpoints:
|
||||
mock_normalize_sound.return_value = mock_result
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/42"
|
||||
"/api/v1/sounds/normalize/42",
|
||||
)
|
||||
|
||||
assert response.status_code == 500
|
||||
@@ -997,7 +997,7 @@ class TestSoundEndpoints:
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sound"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sound",
|
||||
) as mock_normalize_sound,
|
||||
patch("app.repositories.sound.SoundRepository.get_by_id") as mock_get_sound,
|
||||
):
|
||||
@@ -1052,7 +1052,7 @@ class TestSoundEndpoints:
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sound"
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_sound",
|
||||
) as mock_normalize_sound,
|
||||
patch("app.repositories.sound.SoundRepository.get_by_id") as mock_get_sound,
|
||||
):
|
||||
@@ -1060,7 +1060,7 @@ class TestSoundEndpoints:
|
||||
mock_normalize_sound.return_value = mock_result
|
||||
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/42"
|
||||
"/api/v1/sounds/normalize/42",
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user