Verified catalogue of mobiles and laptops sold in India, collected from real retail listings (FastAPI backend, React frontend, Postgres/pgvector). - REST API under /api/elec (read-only catalogue; admin endpoints need login) - MCP server (FastMCP) at /mcp/ with list_categories, search_products, get_product and price_history tools - Real ratings and reviews read from product pages and search results - Production Dockerfile (requirements-api.txt, no PyTorch) and .env.production.example; remote database only via an explicit ELEC_ALLOW_REMOTE_DB host/name allowlist - docs/API.md: endpoint and MCP reference with live examples Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
40 lines
1.7 KiB
Python
40 lines
1.7 KiB
Python
"""Smoke tests for the FastAPI layer (no database needed)."""
|
|
from __future__ import annotations
|
|
|
|
|
|
def test_root(client) -> None:
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
|
|
|
|
def test_health_reports_database_and_search(client) -> None:
|
|
resp = client.get("/api/health")
|
|
assert resp.status_code == 200
|
|
body = resp.json()
|
|
assert body["status"] in {"ok", "degraded"}
|
|
assert body["database_name"] == "electronics_catalog_test"
|
|
assert body["search"] == {"ddg": False, "google_cse": False}
|
|
|
|
|
|
def test_openapi_lists_only_electronics_routes(client) -> None:
|
|
paths = client.get("/openapi.json").json()["paths"]
|
|
for expected in ("/api/health", "/api/auth/login", "/api/elec/categories", "/api/elec/brands",
|
|
"/api/elec/products", "/api/elec/products/{product_id}", "/api/elec/sites",
|
|
"/api/elec/admin/runs"):
|
|
assert expected in paths, f"missing route: {expected}"
|
|
grocery = [p for p in paths if any(w in p for w in ("nutrition", "catalog/generate", "stores", "discounts",
|
|
"trending", "uploads", "brand-discovery"))]
|
|
assert grocery == []
|
|
|
|
|
|
def test_admin_run_requires_admin(client, user_headers) -> None:
|
|
assert client.post("/api/elec/admin/runs", json={"category": "mobiles"}).status_code == 401
|
|
assert client.post("/api/elec/admin/runs", json={"category": "mobiles"},
|
|
headers=user_headers).status_code == 403
|
|
|
|
|
|
def test_admin_run_rejects_brand_outside_allow_list(client, admin_headers) -> None:
|
|
resp = client.post("/api/elec/admin/runs", json={"category": "mobiles", "brands": ["nokia"]},
|
|
headers=admin_headers)
|
|
assert resp.status_code == 400
|