Refactor scheduled task repository and schemas for improved type hints and consistency

- Updated type hints from List/Optional to list/None for better readability and consistency across the codebase.
- Refactored import statements for better organization and clarity.
- Enhanced the ScheduledTaskBase schema to use modern type hints.
- Cleaned up unnecessary comments and whitespace in various files.
- Improved error handling and logging in task execution handlers.
- Updated test cases to reflect changes in type hints and ensure compatibility with the new structure.
This commit is contained in:
JSC
2025-08-28 23:38:47 +02:00
parent 96801dc4d6
commit dc89e45675
19 changed files with 292 additions and 291 deletions

View File

@@ -133,8 +133,8 @@ class TestTaskHandlerRegistry:
mock_sound.id = test_sound_id
mock_sound.filename = "test_sound.mp3"
with patch.object(task_registry.sound_repository, 'get_by_id', return_value=mock_sound):
with patch('app.services.vlc_player.VLCPlayerService') as mock_vlc_class:
with patch.object(task_registry.sound_repository, "get_by_id", return_value=mock_sound):
with patch("app.services.vlc_player.VLCPlayerService") as mock_vlc_class:
mock_vlc_service = AsyncMock()
mock_vlc_class.return_value = mock_vlc_service
@@ -186,7 +186,7 @@ class TestTaskHandlerRegistry:
parameters={"sound_id": str(test_sound_id)},
)
with patch.object(task_registry.sound_repository, 'get_by_id', return_value=None):
with patch.object(task_registry.sound_repository, "get_by_id", return_value=None):
with pytest.raises(TaskExecutionError, match="Sound not found"):
await task_registry.execute_task(task)
@@ -206,8 +206,8 @@ class TestTaskHandlerRegistry:
mock_sound = MagicMock()
mock_sound.filename = "test_sound.mp3"
with patch.object(task_registry.sound_repository, 'get_by_id', return_value=mock_sound):
with patch('app.services.vlc_player.VLCPlayerService') as mock_vlc_class:
with patch.object(task_registry.sound_repository, "get_by_id", return_value=mock_sound):
with patch("app.services.vlc_player.VLCPlayerService") as mock_vlc_class:
mock_vlc_service = AsyncMock()
mock_vlc_class.return_value = mock_vlc_service
@@ -238,7 +238,7 @@ class TestTaskHandlerRegistry:
mock_playlist.id = test_playlist_id
mock_playlist.name = "Test Playlist"
with patch.object(task_registry.playlist_repository, 'get_by_id', return_value=mock_playlist):
with patch.object(task_registry.playlist_repository, "get_by_id", return_value=mock_playlist):
await task_registry.execute_task(task)
task_registry.playlist_repository.get_by_id.assert_called_once_with(test_playlist_id)
@@ -264,7 +264,7 @@ class TestTaskHandlerRegistry:
mock_playlist = MagicMock()
mock_playlist.name = "Test Playlist"
with patch.object(task_registry.playlist_repository, 'get_by_id', return_value=mock_playlist):
with patch.object(task_registry.playlist_repository, "get_by_id", return_value=mock_playlist):
await task_registry.execute_task(task)
# Should use default values
@@ -314,7 +314,7 @@ class TestTaskHandlerRegistry:
parameters={"playlist_id": str(test_playlist_id)},
)
with patch.object(task_registry.playlist_repository, 'get_by_id', return_value=None):
with patch.object(task_registry.playlist_repository, "get_by_id", return_value=None):
with pytest.raises(TaskExecutionError, match="Playlist not found"):
await task_registry.execute_task(task)
@@ -327,7 +327,7 @@ class TestTaskHandlerRegistry:
"""Test play playlist task with various valid play modes."""
mock_playlist = MagicMock()
mock_playlist.name = "Test Playlist"
valid_modes = ["continuous", "loop", "loop_one", "random", "single"]
for mode in valid_modes:
@@ -341,7 +341,7 @@ class TestTaskHandlerRegistry:
},
)
with patch.object(task_registry.playlist_repository, 'get_by_id', return_value=mock_playlist):
with patch.object(task_registry.playlist_repository, "get_by_id", return_value=mock_playlist):
await task_registry.execute_task(task)
mock_player_service.set_mode.assert_called_with(mode)
@@ -368,7 +368,7 @@ class TestTaskHandlerRegistry:
mock_playlist = MagicMock()
mock_playlist.name = "Test Playlist"
with patch.object(task_registry.playlist_repository, 'get_by_id', return_value=mock_playlist):
with patch.object(task_registry.playlist_repository, "get_by_id", return_value=mock_playlist):
await task_registry.execute_task(task)
# Should not call set_mode for invalid mode
@@ -421,4 +421,4 @@ class TestTaskHandlerRegistry:
TaskType.PLAY_SOUND,
TaskType.PLAY_PLAYLIST,
}
assert set(registry._handlers.keys()) == expected_handlers
assert set(registry._handlers.keys()) == expected_handlers