fix: Lint fixes of core and repositories tests
All checks were successful
Backend CI / lint (push) Successful in 9m26s
Backend CI / test (push) Successful in 4m24s

This commit is contained in:
JSC
2025-08-01 09:17:20 +02:00
parent 389cfe2d6a
commit dc29915fbc
8 changed files with 135 additions and 88 deletions

View File

@@ -1,6 +1,8 @@
"""Tests for playlist repository."""
# ruff: noqa: PLR2004, ANN401
from collections.abc import AsyncGenerator
from typing import Any
import pytest
import pytest_asyncio
@@ -10,6 +12,16 @@ from app.models.playlist import Playlist
from app.models.sound import Sound
from app.models.user import User
from app.repositories.playlist import PlaylistRepository
from app.utils.auth import PasswordUtils
# Constants
TEST_POSITION = 5
TEST_TOTAL_SOUNDS = 3
ONE_PLAYLIST = 1
ZERO_SOUNDS = 0
ONE_SOUND = 1
TWO_SOUNDS = 2
DEFAULT_POSITION = 0
class TestPlaylistRepository:
@@ -134,11 +146,10 @@ class TestPlaylistRepository:
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test getting playlists by user ID."""
# Create test user within this test
from app.utils.auth import PasswordUtils
user = User(
email="test@example.com",
name="Test User",
@@ -172,7 +183,7 @@ class TestPlaylistRepository:
playlists = await playlist_repository.get_by_user_id(user_id)
# Should only return user's playlists, not the main playlist (user_id=None)
assert len(playlists) == 1
assert len(playlists) == ONE_PLAYLIST
assert playlists[0].name == "Test Playlist"
@pytest.mark.asyncio
@@ -210,11 +221,10 @@ class TestPlaylistRepository:
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test getting current playlist when none is set."""
# Create test user within this test
from app.utils.auth import PasswordUtils
user = User(
email="test2@example.com",
name="Test User 2",
@@ -302,11 +312,10 @@ class TestPlaylistRepository:
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test searching playlists by name."""
# Create test user within this test
from app.utils.auth import PasswordUtils
user = User(
email="test3@example.com",
name="Test User 3",
@@ -353,11 +362,12 @@ class TestPlaylistRepository:
# Search with user filter
user_results = await playlist_repository.search_by_name("playlist", user_id)
assert len(user_results) == 1 # Only user's playlists, not main playlist
# Only user's playlists, not main playlist
assert len(user_results) == ONE_PLAYLIST
# Search for specific playlist
test_results = await playlist_repository.search_by_name("test", user_id)
assert len(test_results) == 1
assert len(test_results) == ONE_PLAYLIST
assert test_results[0].name == "Test Playlist"
@pytest.mark.asyncio
@@ -365,11 +375,10 @@ class TestPlaylistRepository:
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test adding a sound to a playlist."""
# Create test user within this test
from app.utils.auth import PasswordUtils
user = User(
email="test4@example.com",
name="Test User 4",
@@ -421,18 +430,17 @@ class TestPlaylistRepository:
assert playlist_sound.playlist_id == playlist_id
assert playlist_sound.sound_id == sound_id
assert playlist_sound.position == 0
assert playlist_sound.position == DEFAULT_POSITION
@pytest.mark.asyncio
async def test_add_sound_to_playlist_with_position(
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test adding a sound to a playlist with specific position."""
# Create test user within this test
from app.utils.auth import PasswordUtils
user = User(
email="test5@example.com",
name="Test User 5",
@@ -485,18 +493,17 @@ class TestPlaylistRepository:
playlist_id, sound_id, position=5,
)
assert playlist_sound.position == 5
assert playlist_sound.position == TEST_POSITION
@pytest.mark.asyncio
async def test_remove_sound_from_playlist(
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test removing a sound from a playlist."""
# Create objects within this test
from app.utils.auth import PasswordUtils
user = User(
email="test@example.com",
name="Test User",
@@ -564,11 +571,10 @@ class TestPlaylistRepository:
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test getting sounds in a playlist."""
# Create objects within this test
from app.utils.auth import PasswordUtils
user = User(
email="test@example.com",
name="Test User",
@@ -615,14 +621,14 @@ class TestPlaylistRepository:
# Initially empty
sounds = await playlist_repository.get_playlist_sounds(playlist_id)
assert len(sounds) == 0
assert len(sounds) == ZERO_SOUNDS
# Add sound
await playlist_repository.add_sound_to_playlist(playlist_id, sound_id)
# Check sounds
sounds = await playlist_repository.get_playlist_sounds(playlist_id)
assert len(sounds) == 1
assert len(sounds) == ONE_SOUND
assert sounds[0].id == sound_id
@pytest.mark.asyncio
@@ -630,11 +636,10 @@ class TestPlaylistRepository:
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test getting sound count in a playlist."""
# Create objects within this test
from app.utils.auth import PasswordUtils
user = User(
email="test@example.com",
name="Test User",
@@ -695,11 +700,10 @@ class TestPlaylistRepository:
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test checking if sound is in playlist."""
# Create objects within this test
from app.utils.auth import PasswordUtils
user = User(
email="test@example.com",
name="Test User",
@@ -762,11 +766,10 @@ class TestPlaylistRepository:
self,
playlist_repository: PlaylistRepository,
test_session: AsyncSession,
ensure_plans,
ensure_plans: Any,
) -> None:
"""Test reordering sounds in a playlist."""
# Create objects within this test
from app.utils.auth import PasswordUtils
user = User(
email="test@example.com",
name="Test User",
@@ -823,6 +826,6 @@ class TestPlaylistRepository:
# Verify new order
sounds = await playlist_repository.get_playlist_sounds(playlist_id)
assert len(sounds) == 2
assert len(sounds) == TWO_SOUNDS
assert sounds[0].id == sound2_id # sound2 now at position 5
assert sounds[1].id == sound1_id # sound1 now at position 10