Add regression corpus and opt-in catalog test route

This commit is contained in:
Fiden
2026-08-07 17:44:17 +03:00
parent 11e1a4c4a2
commit e23fdcfc0d
6 changed files with 475 additions and 12 deletions
+45 -1
View File
@@ -2,7 +2,7 @@ from __future__ import annotations
from fastapi.testclient import TestClient
from app.main import app
from app.main import app, create_app
client = TestClient(app)
@@ -47,3 +47,47 @@ def test_empty_message_list_is_valid() -> None:
def test_unknown_request_fields_are_rejected() -> None:
response = client.post("/match", json={"messages": [], "debug": True})
assert response.status_code == 422
def test_opt_in_info_route_returns_catalog_item() -> None:
test_app = create_app(enable_test_info_route=True)
test_client = TestClient(test_app)
assert [route.path for route in test_app.routes] == [
"/match",
"/get_info_by/{sku}",
]
response = test_client.get("/get_info_by/bit-0073")
assert response.status_code == 200
assert set(response.json()) == {"sku", "name", "unit", "price"}
assert response.json()["sku"] == "BIT-0073"
assert response.json()["name"]
assert response.json()["unit"]
assert float(response.json()["price"]) > 0
def test_opt_in_info_route_returns_404_for_unknown_sku() -> None:
test_client = TestClient(create_app(enable_test_info_route=True))
response = test_client.get("/get_info_by/UNKNOWN-0000")
assert response.status_code == 404
assert response.json() == {"detail": "SKU not found"}
def test_opt_in_routes_allow_requests_from_local_html_page() -> None:
test_client = TestClient(create_app(enable_test_info_route=True))
response = test_client.options(
"/match",
headers={
"Origin": "null",
"Access-Control-Request-Method": "POST",
"Access-Control-Request-Headers": "content-type",
},
)
assert response.status_code == 200
assert response.headers["access-control-allow-origin"] == "*"
assert "POST" in response.headers["access-control-allow-methods"]
assert "GET" in response.headers["access-control-allow-methods"]