from __future__ import annotations import os from backend.tests.support import BackendTestCase class LocalLibraryConfigSourceEnvFallbackTests(BackendTestCase): def test_config_reports_env_source_when_settings_path_empty(self): os.environ['MUSIC_LIBRARY_PATH'] = '/library/music' clear = self.client.patch('/api/settings', json={'music_library_path': ''}) self.assertEqual(clear.status_code, 200) response = self.client.get('/api/local-library/config') self.assertEqual(response.status_code, 200) payload = response.json() self.assertEqual(payload.get('source'), 'env') self.assertEqual(payload.get('path'), '/library/music') class LocalLibraryConfigSourceSettingsOverrideTests(BackendTestCase): env_overrides = {"MUSIC_LIBRARY_PATH": "/library/music"} def test_config_prefers_settings_source_over_env(self): updated = self.client.patch('/api/settings', json={'music_library_path': '/custom/library'}) self.assertEqual(updated.status_code, 200) response = self.client.get('/api/local-library/config') self.assertEqual(response.status_code, 200) payload = response.json() self.assertEqual(payload.get('source'), 'settings') self.assertEqual(payload.get('path'), '/custom/library')