Feature Elimination backend

This commit is contained in:
sriram
2026-08-31 16:31:43 +05:30
parent 164ef90b31
commit a6e78fee95
7 changed files with 25 additions and 350 deletions

View File

@@ -2,8 +2,15 @@
Follows the pattern established by test_user_products_upload.py: monkeypatch
the storage/network boundary *on the pipeline module object* (it imports those
names directly), build real .xlsx fixtures in memory, and assert on what was
captured rather than on the HTTP status alone.
names directly), build real .xlsx fixtures in memory, and assert on the rows
that were written rather than on a status code.
This file covers the PIPELINE only, and deliberately so. It once ended with a
section of HTTP tests against /api/admin/store-catalog/*; that router was
deleted along with the Store Catalog Ingestion admin tab, and the same eleven
stages are now driven from POST /api/uploads/catalog and the admin batch routes
- whose HTTP surfaces are covered in test_uploads_autorun.py, test_uploads_api.py
and test_batch_catalog_ingest.py.
Every test runs with use_llm=False and fetch_images=False so nothing here
touches Ollama or the open web.
@@ -323,64 +330,3 @@ def test_the_same_pack_listed_twice_is_written_once(store):
)
_run(content)
assert len(store) == 1
# ---------------------------------------------------------------------------
# HTTP surface
# ---------------------------------------------------------------------------
def test_preview_reports_how_the_columns_were_understood(client, admin_headers):
content = _sheet(["Item Name", "Segment", "Mystery"], [["Britannia 50-50", "Biscuits", "?"]])
resp = client.post(
"/api/admin/store-catalog/preview",
files={"file": ("store.xlsx", content)},
headers=admin_headers,
)
assert resp.status_code == 200
body = resp.json()
assert body["recognised_columns"]["product_name"] == "Item Name"
assert body["unrecognised_columns"] == ["Mystery"]
assert body["brand_column_present"] is False
assert len(body["stages"]) == 11
def test_preview_requires_admin(client):
content = _sheet(["Item Name"], [["Britannia 50-50"]])
resp = client.post("/api/admin/store-catalog/preview", files={"file": ("s.xlsx", content)})
assert resp.status_code == 401
def test_an_unparseable_file_is_rejected_before_a_job_is_created(client, admin_headers):
resp = client.post(
"/api/admin/store-catalog/ingest",
files={"file": ("notes.txt", b"this is not a spreadsheet")},
headers=admin_headers,
)
assert resp.status_code == 400
def test_ingest_returns_a_job_id_that_can_be_polled(client, admin_headers, monkeypatch):
# Keep the worker off the network and out of the database.
monkeypatch.setattr(pipeline, "upsert_brand_products", lambda b, r, cleanup=False: len(r))
monkeypatch.setattr(pipeline, "get_products_by_brand", lambda b, **kw: [])
monkeypatch.setattr(pipeline, "embed_texts", lambda texts: [[0.0] * 384 for _ in texts])
content = _sheet(["Item Name", "Segment"], [["Britannia 50-50", "Biscuits"]])
resp = client.post(
"/api/admin/store-catalog/ingest",
files={"file": ("store.xlsx", content)},
headers=admin_headers,
)
assert resp.status_code == 202
job_id = resp.json()["job_id"]
assert resp.json()["rows_total"] == 1
poll = client.get(f"/api/admin/store-catalog/jobs/{job_id}", headers=admin_headers)
assert poll.status_code == 200
body = poll.json()
assert body["status"] in {"pending", "running", "done", "failed"}
assert body["total_stages"] == 11
def test_polling_an_unknown_job_is_a_404(client, admin_headers):
resp = client.get("/api/admin/store-catalog/jobs/does-not-exist", headers=admin_headers)
assert resp.status_code == 404

View File

@@ -303,7 +303,6 @@ def test_uploader_key_is_refused_on_every_admin_route(client, upload_headers):
("get", "/api/admin/catalog-batch/batches/anything"),
("post", "/api/admin/catalog-batch/batches/anything/resume"),
("post", "/api/admin/catalog-batch/batches/anything/cancel"),
("post", "/api/admin/store-catalog/ingest"),
("post", "/api/system/init"),
]
for method, path in admin_routes: