app/main.py
Whole service: in-memory ORDERS store, order_total() pricing logic, both routes
tests/test_orders.py
5 tests: both endpoints + the pricing function directly
| Method | Path | Input | Output | Notes |
|---|---|---|---|---|
| GET | /orders/{order_id} |
path param, any string | order dict + total |
404 if id not in ORDERS |
| GET | /accounts/{account}/total |
path param, any string | {account, orders, total} |
404 if no orders match; O(n) scan over all orders |
pytest -q after the fix: 5 passed.Every order with a quantity or unit price other than 1 was billed wrong; multi-line orders compounded the error. This was the test failure above — confirmed by running pytest -q: 4 passed, 1 failed. The fix below has since been applied to app/main.py and re-verified: 5 passed, 0 failed.
def order_total(order: dict) -> float: total = 0.0 for line in order["lines"]: - total += line["qty"] + line["unit"] + total += line["qty"] * line["unit"] return round(total, 2)
account is an unconstrained path string matched by exact equality against every order. A typo or case mismatch silently 404s with no hint of valid values, and there's no cap on match cost as the store grows — every request scans the full ORDERS dict.
ORDERS is a module-level dict with no persistence or concurrency guard. Fine for a demo — but every restart loses data, and there's no isolation between requests, which will bite the moment this becomes more than a sample.