File size: 1,280 Bytes
2edb151 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | from __future__ import annotations
import pytest
from app.config import Settings
from app.db import (
EmbedIndexError,
VecLoadError,
connect,
delete_receipt,
init_schema,
insert_receipt,
)
from app.schemas import ReceiptExtract, ReceiptStatus
def test_schema_and_meta(settings: Settings) -> None:
try:
con = connect(settings.db_path)
init_schema(con, settings)
except VecLoadError:
pytest.skip("sqlite-vec not loadable")
tables = {
row[0]
for row in con.execute("SELECT name FROM sqlite_master WHERE type IN ('table','view')")
}
assert "receipts" in tables
assert "catalog" in tables
rid = insert_receipt(
con,
source_path="x.jpg",
sha256="abc",
status=ReceiptStatus.needs_review,
extract=ReceiptExtract(vendor="A", category="dining"),
)
assert rid == 1
other = settings.model_copy(update={"embed_dim": 3840, "embed_model": "other"})
with pytest.raises(EmbedIndexError):
init_schema(con, other)
assert delete_receipt(con, rid, unlink_file=False) is True
assert con.execute("SELECT COUNT(*) AS n FROM receipts").fetchone()["n"] == 0
assert delete_receipt(con, rid, unlink_file=False) is False
con.close()
|