aefrss / tests /test_vector_search.py
mohamedkh001
Deploy AEFRS complete system with models and services
ea93121
raw
history blame contribute delete
931 Bytes
from pathlib import Path
import pytest
pytest.importorskip("fastapi")
from fastapi.testclient import TestClient
import services.vector_search_service.main as vector_mod
from services.vector_search_service.main import app
def test_upsert_query_delete_snapshot(tmp_path: Path) -> None:
vector_mod.INDEX_PATH = tmp_path / "index.json"
client = TestClient(app)
emb = [0.1] * 512
r1 = client.post('/upsert', json={'identity_id': 'u1', 'embedding': emb})
assert r1.status_code == 200
r2 = client.post('/query', json={'embedding': emb, 'top_k': 1})
assert r2.status_code == 200
payload = r2.json()
assert payload['matches'][0]['identity_id'] == 'u1'
r3 = client.post('/snapshot')
assert r3.status_code == 200
assert vector_mod.INDEX_PATH.exists()
r4 = client.post('/delete', json={'identity_id': 'u1'})
assert r4.status_code == 200
assert r4.json()['removed'] is True