Upload backend/tests/test_health.py with huggingface_hub
Browse files- backend/tests/test_health.py +36 -0
backend/tests/test_health.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from types import SimpleNamespace
|
| 3 |
+
|
| 4 |
+
import main
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_health_reports_real_index_and_model_state(monkeypatch, tmp_path):
|
| 8 |
+
index_file = tmp_path / "celeb_index.faiss"
|
| 9 |
+
index_file.write_bytes(b"placeholder")
|
| 10 |
+
|
| 11 |
+
monkeypatch.setattr(main, "resolve_path", lambda *args, **kwargs: index_file)
|
| 12 |
+
monkeypatch.setattr(main, "get_index", lambda: SimpleNamespace(ntotal=202_599))
|
| 13 |
+
monkeypatch.setattr(main, "detector_ready", lambda: True)
|
| 14 |
+
monkeypatch.setattr(main, "embedder_ready", lambda: True)
|
| 15 |
+
monkeypatch.setenv("GEMINI_MODEL", "test-model")
|
| 16 |
+
|
| 17 |
+
response = asyncio.run(main.health())
|
| 18 |
+
|
| 19 |
+
assert response.status == "ok"
|
| 20 |
+
assert response.index_ready is True
|
| 21 |
+
assert response.index_vectors == 202_599
|
| 22 |
+
assert response.detector_ready is True
|
| 23 |
+
assert response.embedder_ready is True
|
| 24 |
+
assert response.model == "test-model"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_health_marks_missing_index(monkeypatch, tmp_path):
|
| 28 |
+
missing = tmp_path / "missing.faiss"
|
| 29 |
+
monkeypatch.setattr(main, "resolve_path", lambda *args, **kwargs: missing)
|
| 30 |
+
monkeypatch.setattr(main, "detector_ready", lambda: False)
|
| 31 |
+
monkeypatch.setattr(main, "embedder_ready", lambda: False)
|
| 32 |
+
|
| 33 |
+
response = asyncio.run(main.health())
|
| 34 |
+
|
| 35 |
+
assert response.index_ready is False
|
| 36 |
+
assert response.index_vectors is None
|