fix: Lint fixes of last tests
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
"""Tests for sound API endpoints."""
|
||||
# ruff: noqa: ARG002, PLR2004, E501, PLC0415, ANN001, ANN202
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
from app.models.user import User
|
||||
from app.services.sound_normalizer import NormalizationResults
|
||||
from app.services.sound_scanner import ScanResults
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.services.sound_normalizer import NormalizationResults
|
||||
from app.services.sound_scanner import ScanResults
|
||||
|
||||
|
||||
class TestSoundEndpoints:
|
||||
@@ -18,7 +22,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test successful sound scanning."""
|
||||
# Mock the scanner service to return successful results
|
||||
mock_results: ScanResults = {
|
||||
@@ -95,7 +99,7 @@ class TestSoundEndpoints:
|
||||
assert results["files"][2]["status"] == "deleted"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_scan_sounds_unauthenticated(self, client: AsyncClient):
|
||||
async def test_scan_sounds_unauthenticated(self, client: AsyncClient) -> None:
|
||||
"""Test scanning sounds without authentication."""
|
||||
response = await client.post("/api/v1/sounds/scan")
|
||||
|
||||
@@ -108,7 +112,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
test_app,
|
||||
test_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test scanning sounds with non-admin user."""
|
||||
from app.core.dependencies import get_current_active_user_flexible
|
||||
|
||||
@@ -142,7 +146,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
test_app,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test scanning sounds with admin user."""
|
||||
from app.core.dependencies import get_current_active_user_flexible
|
||||
|
||||
@@ -189,7 +193,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test scanning sounds when service raises an error."""
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_soundboard_directory",
|
||||
@@ -208,7 +212,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test successful custom directory scanning."""
|
||||
mock_results: ScanResults = {
|
||||
"scanned": 2,
|
||||
@@ -272,7 +276,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test custom directory scanning with default sound type."""
|
||||
mock_results: ScanResults = {
|
||||
"scanned": 1,
|
||||
@@ -304,7 +308,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test custom directory scanning with invalid path."""
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory",
|
||||
@@ -322,7 +326,7 @@ class TestSoundEndpoints:
|
||||
assert "Directory does not exist" in data["detail"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_scan_custom_directory_unauthenticated(self, client: AsyncClient):
|
||||
async def test_scan_custom_directory_unauthenticated(self, client: AsyncClient) -> None:
|
||||
"""Test custom directory scanning without authentication."""
|
||||
response = await client.post(
|
||||
"/api/v1/sounds/scan/custom", params={"directory": "/some/path"},
|
||||
@@ -337,7 +341,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
test_app,
|
||||
test_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test custom directory scanning with non-admin user."""
|
||||
from app.core.dependencies import get_current_active_user_flexible
|
||||
|
||||
@@ -374,7 +378,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test custom directory scanning when service raises an error."""
|
||||
with patch(
|
||||
"app.services.sound_scanner.SoundScannerService.scan_directory",
|
||||
@@ -395,7 +399,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test scanning with some errors in results."""
|
||||
mock_results: ScanResults = {
|
||||
"scanned": 3,
|
||||
@@ -467,7 +471,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test that endpoint response has correct structure."""
|
||||
mock_results: ScanResults = {
|
||||
"scanned": 0,
|
||||
@@ -519,7 +523,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test successful normalization of all sounds."""
|
||||
mock_results: NormalizationResults = {
|
||||
"processed": 3,
|
||||
@@ -597,7 +601,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalization with force parameter."""
|
||||
mock_results: NormalizationResults = {
|
||||
"processed": 1,
|
||||
@@ -626,7 +630,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalization with one_pass parameter."""
|
||||
mock_results: NormalizationResults = {
|
||||
"processed": 1,
|
||||
@@ -651,7 +655,7 @@ class TestSoundEndpoints:
|
||||
mock_normalize.assert_called_once_with(force=False, one_pass=True)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_normalize_all_sounds_unauthenticated(self, client: AsyncClient):
|
||||
async def test_normalize_all_sounds_unauthenticated(self, client: AsyncClient) -> None:
|
||||
"""Test normalizing sounds without authentication."""
|
||||
response = await client.post("/api/v1/sounds/normalize/all")
|
||||
|
||||
@@ -664,7 +668,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
test_app,
|
||||
test_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalizing sounds with non-admin user."""
|
||||
from app.core.dependencies import get_current_active_user_flexible
|
||||
|
||||
@@ -699,7 +703,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalization when service raises an error."""
|
||||
with patch(
|
||||
"app.services.sound_normalizer.SoundNormalizerService.normalize_all_sounds",
|
||||
@@ -720,7 +724,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test successful normalization by sound type."""
|
||||
mock_results: NormalizationResults = {
|
||||
"processed": 2,
|
||||
@@ -787,7 +791,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalization with invalid sound type."""
|
||||
response = await authenticated_admin_client.post(
|
||||
"/api/v1/sounds/normalize/type/INVALID",
|
||||
@@ -803,7 +807,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalization by type with force and one_pass parameters."""
|
||||
mock_results: NormalizationResults = {
|
||||
"processed": 1,
|
||||
@@ -835,7 +839,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test successful normalization of a specific sound."""
|
||||
# Mock the sound
|
||||
mock_sound = type(
|
||||
@@ -894,7 +898,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalization of non-existent sound."""
|
||||
with patch(
|
||||
"app.repositories.sound.SoundRepository.get_by_id",
|
||||
@@ -914,7 +918,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalization when the sound normalization fails."""
|
||||
# Mock the sound
|
||||
mock_sound = type(
|
||||
@@ -966,7 +970,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test sound normalization with force and one_pass parameters."""
|
||||
# Mock the sound
|
||||
mock_sound = type(
|
||||
@@ -1013,15 +1017,15 @@ class TestSoundEndpoints:
|
||||
|
||||
# Verify parameters were passed to normalize_sound
|
||||
call_args = mock_normalize_sound.call_args
|
||||
assert call_args[1]["force"] == True
|
||||
assert call_args[1]["one_pass"] == True
|
||||
assert call_args[1]["force"]
|
||||
assert call_args[1]["one_pass"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_normalize_sound_by_id_skipped(
|
||||
self,
|
||||
authenticated_admin_client: AsyncClient,
|
||||
admin_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalization when sound is already normalized and not forced."""
|
||||
# Mock the sound
|
||||
mock_sound = type(
|
||||
@@ -1071,7 +1075,7 @@ class TestSoundEndpoints:
|
||||
assert data["reason"] == "already normalized"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_normalize_sound_by_id_unauthenticated(self, client: AsyncClient):
|
||||
async def test_normalize_sound_by_id_unauthenticated(self, client: AsyncClient) -> None:
|
||||
"""Test normalizing a specific sound without authentication."""
|
||||
response = await client.post("/api/v1/sounds/normalize/42")
|
||||
|
||||
@@ -1084,7 +1088,7 @@ class TestSoundEndpoints:
|
||||
self,
|
||||
test_app,
|
||||
test_user: User,
|
||||
):
|
||||
) -> None:
|
||||
"""Test normalizing a specific sound with non-admin user."""
|
||||
from app.core.dependencies import get_current_active_user_flexible
|
||||
|
||||
|
||||
Reference in New Issue
Block a user