fixes and improvements
This commit is contained in:
@@ -128,12 +128,14 @@ def mock_ssh():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_client(mock_jellyfin, mock_jellyseerr, mock_ssh):
|
||||
def test_client(mock_jellyfin, mock_jellyseerr, mock_ssh, tmp_path):
|
||||
"""FastAPI test client with mocked dependencies."""
|
||||
app.dependency_overrides[get_jellyfin_client] = lambda: mock_jellyfin
|
||||
app.dependency_overrides[get_jellyseerr_client] = lambda: mock_jellyseerr
|
||||
app.dependency_overrides[get_ssh_client] = lambda: mock_ssh
|
||||
app.dependency_overrides[get_user_id] = lambda: "user123"
|
||||
store = SettingsStore(tmp_path / "settings.sqlite")
|
||||
app.dependency_overrides[get_settings_store] = lambda: store
|
||||
auth_settings = SimpleNamespace(auth_enabled=False)
|
||||
with patch("media_library_viewer_api.auth.get_settings", return_value=auth_settings):
|
||||
client = TestClient(app)
|
||||
@@ -294,7 +296,7 @@ class TestSettingsReset:
|
||||
settings_module.MediaIndex = original_media_index
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_reset_local_database_wipes_state_and_reseeds_local_machine(self, test_client, tmp_path):
|
||||
def test_reset_local_database_wipes_state_and_leaves_no_machines(self, test_client, tmp_path):
|
||||
store = SettingsStore(tmp_path / "settings.sqlite")
|
||||
store.ensure_defaults()
|
||||
media_db = tmp_path / "media.sqlite"
|
||||
@@ -324,8 +326,8 @@ class TestSettingsReset:
|
||||
assert payload["status"] == "reset"
|
||||
assert not media_db.exists()
|
||||
assert not media_wal.exists()
|
||||
assert store.get_machine("local") is not None
|
||||
assert len(store.list_machines()) == 1
|
||||
assert store.get_machine("local") is None
|
||||
assert len(store.list_machines()) == 0
|
||||
|
||||
# --- Users ---
|
||||
|
||||
@@ -644,7 +646,20 @@ class TestJobs:
|
||||
# --- Monitoring ---
|
||||
|
||||
class TestMonitoring:
|
||||
def _ensure_machine(self):
|
||||
store = app.dependency_overrides[get_settings_store]()
|
||||
if not store.list_machines():
|
||||
store.upsert_machine({
|
||||
"name": "Test Machine",
|
||||
"mode": "ssh",
|
||||
"enabled": True,
|
||||
"services": ["monitoring", "files", "jellyfin"],
|
||||
"host": "test-host",
|
||||
"username": "test-user",
|
||||
})
|
||||
|
||||
def test_status(self, test_client, mock_ssh):
|
||||
self._ensure_machine()
|
||||
mock_ssh.run.return_value = CommandResult(
|
||||
command="...", exit_status=0, stdout="running pid=1234\n", stderr=""
|
||||
)
|
||||
@@ -653,6 +668,7 @@ class TestMonitoring:
|
||||
assert "running" in response.json()["status"]
|
||||
|
||||
def test_metrics_empty(self, test_client, mock_ssh):
|
||||
self._ensure_machine()
|
||||
mock_ssh.run.return_value = CommandResult(
|
||||
command="...", exit_status=0, stdout="", stderr=""
|
||||
)
|
||||
@@ -662,6 +678,7 @@ class TestMonitoring:
|
||||
assert data["samples"] == []
|
||||
|
||||
def test_disk(self, test_client, mock_ssh):
|
||||
self._ensure_machine()
|
||||
mock_ssh.run.return_value = CommandResult(
|
||||
command="df ...",
|
||||
exit_status=0,
|
||||
@@ -674,6 +691,7 @@ class TestMonitoring:
|
||||
assert data["used_pct"] == "50%"
|
||||
|
||||
def test_start(self, test_client, mock_ssh):
|
||||
self._ensure_machine()
|
||||
mock_ssh.run.return_value = CommandResult(
|
||||
command="...", exit_status=0, stdout="started pid=5678\n", stderr=""
|
||||
)
|
||||
@@ -682,6 +700,7 @@ class TestMonitoring:
|
||||
assert "started" in response.json()["message"]
|
||||
|
||||
def test_stop(self, test_client, mock_ssh):
|
||||
self._ensure_machine()
|
||||
mock_ssh.run.return_value = CommandResult(
|
||||
command="...", exit_status=0, stdout="stopped pid=5678\n", stderr=""
|
||||
)
|
||||
@@ -689,6 +708,7 @@ class TestMonitoring:
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_restart(self, test_client, mock_ssh):
|
||||
self._ensure_machine()
|
||||
mock_ssh.run.return_value = CommandResult(
|
||||
command="...", exit_status=0, stdout="stopped pid=5678\nstarted pid=9999\n", stderr=""
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user