Add comprehensive test suite for backend (133 tests)
Test coverage: - test_utils.py: formatting helpers (human_size, ticks_to_minutes, format_duration, format_bitrate, ffprobe summaries, stream parsing) - test_path_utils.py: path resolution (prefix, media root mapping, edge cases with spaces/special chars) - test_domain_media.py: Jellyfin item normalization (HDR detection, media sources, stream extraction, display formatting) - test_jobs.py: job template rendering and shell quoting safety - test_media_index.py: SQLite index CRUD, querying, filtering, sorting, pagination - test_config.py: pydantic-settings env loading - test_api.py: full FastAPI integration tests with mocked SSH/Jellyfin (all endpoints: dashboard, monitoring, media, files, jobs) All tests run without network/SSH dependencies using mocks.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""Unit tests for config.py settings loading."""
|
||||
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
from media_library_viewer_api.config import Settings
|
||||
|
||||
|
||||
class TestSettings:
|
||||
def test_defaults(self):
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
settings = Settings(_env_file=None)
|
||||
assert settings.ssh_host == ""
|
||||
assert settings.ssh_port == 22
|
||||
assert settings.jellyfin_url == ""
|
||||
assert settings.remote_media_root == ""
|
||||
|
||||
def test_from_env(self):
|
||||
env = {
|
||||
"JELLYFIN_URL": "https://test.example.com",
|
||||
"JELLYFIN_API_KEY": "key123",
|
||||
"SSH_HOST": "192.168.1.1",
|
||||
"SSH_USERNAME": "testuser",
|
||||
"SSH_PORT": "2222",
|
||||
"REMOTE_MEDIA_ROOT": "/srv/media",
|
||||
}
|
||||
with patch.dict(os.environ, env, clear=True):
|
||||
settings = Settings(_env_file=None)
|
||||
assert settings.jellyfin_url == "https://test.example.com"
|
||||
assert settings.jellyfin_api_key == "key123"
|
||||
assert settings.ssh_host == "192.168.1.1"
|
||||
assert settings.ssh_username == "testuser"
|
||||
assert settings.ssh_port == 2222
|
||||
assert settings.remote_media_root == "/srv/media"
|
||||
|
||||
def test_media_root_property(self):
|
||||
env = {"REMOTE_MEDIA_ROOT": "/mnt/data"}
|
||||
with patch.dict(os.environ, env, clear=True):
|
||||
settings = Settings(_env_file=None)
|
||||
assert settings.media_root == "/mnt/data"
|
||||
|
||||
def test_path_prefix_property(self):
|
||||
env = {"REMOTE_PATH_PREFIX": "/srv"}
|
||||
with patch.dict(os.environ, env, clear=True):
|
||||
settings = Settings(_env_file=None)
|
||||
assert settings.path_prefix == "/srv"
|
||||
Reference in New Issue
Block a user