Refactor sound and extraction services to include user and timestamp fields
All checks were successful
Backend CI / lint (push) Successful in 18m8s
Backend CI / test (push) Successful in 53m35s

- Updated ExtractionInfo to include user_id, created_at, and updated_at fields.
- Modified ExtractionService to return user and timestamp information in extraction responses.
- Enhanced sound serialization in PlayerState to include extraction URL if available.
- Adjusted PlaylistRepository to load sound extractions when retrieving playlist sounds.
- Added tests for new fields in extraction and sound endpoints, ensuring proper response structure.
- Created new test file endpoints for sound downloads and thumbnail retrievals, including success and error cases.
- Refactored various test cases for consistency and clarity, ensuring proper mocking and assertions.
This commit is contained in:
JSC
2025-08-03 20:54:14 +02:00
parent 77446cb5a8
commit b4f0f54516
20 changed files with 780 additions and 73 deletions

View File

@@ -185,7 +185,9 @@ class TestVLCPlayerService:
@pytest.mark.asyncio
@patch("app.services.vlc_player.asyncio.create_subprocess_exec")
async def test_stop_all_vlc_instances_success(
self, mock_subprocess, vlc_service,
self,
mock_subprocess,
vlc_service,
) -> None:
"""Test successful stopping of all VLC instances."""
# Mock pgrep process (find VLC processes)
@@ -281,7 +283,9 @@ class TestVLCPlayerService:
@pytest.mark.asyncio
@patch("app.services.vlc_player.asyncio.create_subprocess_exec")
async def test_stop_all_vlc_instances_error(
self, mock_subprocess, vlc_service,
self,
mock_subprocess,
vlc_service,
) -> None:
"""Test stopping VLC instances when an error occurs."""
# Mock subprocess exception
@@ -341,10 +345,12 @@ class TestVLCPlayerService:
mock_user_repo = AsyncMock()
with patch(
"app.services.vlc_player.SoundRepository", return_value=mock_sound_repo,
"app.services.vlc_player.SoundRepository",
return_value=mock_sound_repo,
):
with patch(
"app.services.vlc_player.UserRepository", return_value=mock_user_repo,
"app.services.vlc_player.UserRepository",
return_value=mock_user_repo,
):
with patch("app.services.vlc_player.socket_manager") as mock_socket:
# Mock the file path utility
@@ -424,10 +430,12 @@ class TestVLCPlayerService:
)
with patch(
"app.services.vlc_player.SoundRepository", return_value=mock_sound_repo,
"app.services.vlc_player.SoundRepository",
return_value=mock_sound_repo,
):
with patch(
"app.services.vlc_player.UserRepository", return_value=mock_user_repo,
"app.services.vlc_player.UserRepository",
return_value=mock_user_repo,
):
with patch("app.services.vlc_player.socket_manager") as mock_socket:
# Setup mocks
@@ -461,6 +469,7 @@ class TestVLCPlayerService:
"sound_id": 1,
"sound_name": "Test Sound",
"user_id": 1,
"user_name": "Admin User",
"play_count": 1,
},
)
@@ -474,7 +483,8 @@ class TestVLCPlayerService:
@pytest.mark.asyncio
async def test_record_play_count_always_creates_record(
self, vlc_service_with_db,
self,
vlc_service_with_db,
) -> None:
"""Test play count recording always creates a new SoundPlayed record."""
# Mock session and repositories
@@ -503,10 +513,12 @@ class TestVLCPlayerService:
)
with patch(
"app.services.vlc_player.SoundRepository", return_value=mock_sound_repo,
"app.services.vlc_player.SoundRepository",
return_value=mock_sound_repo,
):
with patch(
"app.services.vlc_player.UserRepository", return_value=mock_user_repo,
"app.services.vlc_player.UserRepository",
return_value=mock_user_repo,
):
with patch("app.services.vlc_player.socket_manager") as mock_socket:
# Setup mocks