Add regression corpus and opt-in catalog test route
This commit is contained in:
1 parent
476cbb0116
commit
c7b19d1310
7 files changed
+491
-13
No files matched your search
@@ -0,0 +1,39 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from app.matcher import CatalogMatcher
|
||||
|
||||
|
||||
class CatalogItemInfo(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
sku: str
|
||||
name: str
|
||||
unit: str
|
||||
price: Decimal
|
||||
|
||||
|
||||
def register_test_info_route(
|
||||
application: FastAPI, matcher: CatalogMatcher
|
||||
) -> None:
|
||||
items_by_sku = {item.sku: item for item in matcher.items}
|
||||
|
||||
@application.get(
|
||||
"/get_info_by/{sku}",
|
||||
response_model=CatalogItemInfo,
|
||||
include_in_schema=False,
|
||||
)
|
||||
def get_info_by(sku: str) -> CatalogItemInfo:
|
||||
item = items_by_sku.get(sku.strip().upper())
|
||||
if item is None:
|
||||
raise HTTPException(status_code=404, detail="SKU not found")
|
||||
return CatalogItemInfo(
|
||||
sku=item.sku,
|
||||
name=item.name,
|
||||
unit=item.unit,
|
||||
price=item.price,
|
||||
)
|
||||
Reference in new issue
Block a user