feat: Add VLC player API endpoints and associated tests
- Implemented VLC player API endpoints for playing and stopping sounds. - Added tests for successful playback, error handling, and authentication scenarios. - Created utility function to get sound file paths based on sound properties. - Refactored player service to utilize shared sound path utility. - Enhanced test coverage for sound file path utility with various sound types. - Introduced tests for VLC player service, including subprocess handling and play count tracking.
This commit is contained in:
@@ -7,7 +7,8 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.utils.audio import get_audio_duration, get_file_hash, get_file_size
|
||||
from app.models.sound import Sound
|
||||
from app.utils.audio import get_audio_duration, get_file_hash, get_file_size, get_sound_file_path
|
||||
|
||||
|
||||
class TestAudioUtils:
|
||||
@@ -290,3 +291,120 @@ class TestAudioUtils:
|
||||
# Should raise FileNotFoundError for nonexistent file
|
||||
with pytest.raises(FileNotFoundError):
|
||||
get_file_size(nonexistent_path)
|
||||
|
||||
def test_get_sound_file_path_sdb_original(self):
|
||||
"""Test getting sound file path for SDB type original file."""
|
||||
sound = Sound(
|
||||
id=1,
|
||||
name="Test Sound",
|
||||
filename="test.mp3",
|
||||
type="SDB",
|
||||
is_normalized=False,
|
||||
)
|
||||
|
||||
result = get_sound_file_path(sound)
|
||||
expected = Path("sounds/originals/soundboard/test.mp3")
|
||||
assert result == expected
|
||||
|
||||
def test_get_sound_file_path_sdb_normalized(self):
|
||||
"""Test getting sound file path for SDB type normalized file."""
|
||||
sound = Sound(
|
||||
id=1,
|
||||
name="Test Sound",
|
||||
filename="original.mp3",
|
||||
normalized_filename="normalized.mp3",
|
||||
type="SDB",
|
||||
is_normalized=True,
|
||||
)
|
||||
|
||||
result = get_sound_file_path(sound)
|
||||
expected = Path("sounds/normalized/soundboard/normalized.mp3")
|
||||
assert result == expected
|
||||
|
||||
def test_get_sound_file_path_tts_original(self):
|
||||
"""Test getting sound file path for TTS type original file."""
|
||||
sound = Sound(
|
||||
id=2,
|
||||
name="TTS Sound",
|
||||
filename="tts_file.wav",
|
||||
type="TTS",
|
||||
is_normalized=False,
|
||||
)
|
||||
|
||||
result = get_sound_file_path(sound)
|
||||
expected = Path("sounds/originals/text_to_speech/tts_file.wav")
|
||||
assert result == expected
|
||||
|
||||
def test_get_sound_file_path_tts_normalized(self):
|
||||
"""Test getting sound file path for TTS type normalized file."""
|
||||
sound = Sound(
|
||||
id=2,
|
||||
name="TTS Sound",
|
||||
filename="original.wav",
|
||||
normalized_filename="normalized.mp3",
|
||||
type="TTS",
|
||||
is_normalized=True,
|
||||
)
|
||||
|
||||
result = get_sound_file_path(sound)
|
||||
expected = Path("sounds/normalized/text_to_speech/normalized.mp3")
|
||||
assert result == expected
|
||||
|
||||
def test_get_sound_file_path_ext_original(self):
|
||||
"""Test getting sound file path for EXT type original file."""
|
||||
sound = Sound(
|
||||
id=3,
|
||||
name="Extracted Sound",
|
||||
filename="extracted.mp3",
|
||||
type="EXT",
|
||||
is_normalized=False,
|
||||
)
|
||||
|
||||
result = get_sound_file_path(sound)
|
||||
expected = Path("sounds/originals/extracted/extracted.mp3")
|
||||
assert result == expected
|
||||
|
||||
def test_get_sound_file_path_ext_normalized(self):
|
||||
"""Test getting sound file path for EXT type normalized file."""
|
||||
sound = Sound(
|
||||
id=3,
|
||||
name="Extracted Sound",
|
||||
filename="original.mp3",
|
||||
normalized_filename="normalized.mp3",
|
||||
type="EXT",
|
||||
is_normalized=True,
|
||||
)
|
||||
|
||||
result = get_sound_file_path(sound)
|
||||
expected = Path("sounds/normalized/extracted/normalized.mp3")
|
||||
assert result == expected
|
||||
|
||||
def test_get_sound_file_path_unknown_type_fallback(self):
|
||||
"""Test getting sound file path for unknown type falls back to lowercase."""
|
||||
sound = Sound(
|
||||
id=4,
|
||||
name="Unknown Type Sound",
|
||||
filename="unknown.mp3",
|
||||
type="CUSTOM",
|
||||
is_normalized=False,
|
||||
)
|
||||
|
||||
result = get_sound_file_path(sound)
|
||||
expected = Path("sounds/originals/custom/unknown.mp3")
|
||||
assert result == expected
|
||||
|
||||
def test_get_sound_file_path_normalized_without_filename(self):
|
||||
"""Test getting sound file path when normalized but no normalized_filename."""
|
||||
sound = Sound(
|
||||
id=5,
|
||||
name="Test Sound",
|
||||
filename="original.mp3",
|
||||
normalized_filename=None,
|
||||
type="SDB",
|
||||
is_normalized=True, # True but no normalized_filename
|
||||
)
|
||||
|
||||
result = get_sound_file_path(sound)
|
||||
# Should fall back to original file
|
||||
expected = Path("sounds/originals/soundboard/original.mp3")
|
||||
assert result == expected
|
||||
|
||||
Reference in New Issue
Block a user