The shop's order status from Tern's (needs from the docs: D5 held)
cd /app; cat shop/shipping.py shop/orders.py; grep -n -i tern shop/settings.py; ls . tests 2>/dev/null; curl -s localhost:8080/
"""Shipping with Tern, our carrier. Use shop.tern.call for requests; shop.settings has the warehouse postcode."""
from datetime import date
from shop.cart import Cart
from shop.orders import Order
def quote_at_checkout(cart: Cart, postcode: str) -> int:
"""The cheapest price Tern offers to ship this cart from the warehouse to postcode, in pence."""
raise NotImplementedError
def quote_options(cart: Cart, postcode: str) -> list[tuple[str, int, int]]:
"""Every service Tern offers for this cart and postcode, as (service, price in pence, days to deliver),
cheapest first."""
raise NotImplementedError
def book(order: Order, service: str) -> str:
"""Book the order's parcel with Tern on the given service and return Tern's shipment id."""
raise NotImplementedError
def shipments_since(day: date) -> list[dict]:
"""Every Tern shipment created on or after day, as Tern describes them."""
raise NotImplementedError
def order_status(shipment_id: str) -> str:
"""The shop's status (one of shop.orders.STATUSES) for the order whose Tern shipment this is."""
raise NotImplementedError
def cancel(order: Order) -> bool:
"""Cancel the order's Tern shipment. True if Tern cancelled it; False if it is too late to cancel."""
raise NotImplementedError
from dataclasses import dataclass
from shop.cart import Cart
# The statuses a customer sees on their order page.
PAID = "paid" # paid for, not yet booked with the carrier
PROCESSING = "processing" # booked with the carrier, waiting to be collected
SHIPPED = "shipped" # with the carrier and on its way
DELIVERED = "delivered" # arrived
PROBLEM = "problem" # something went wrong: a person needs to look at it
CANCELLED = "cancelled" # cancelled before it left us
STATUSES = (PAID, PROCESSING, SHIPPED, DELIVERED, PROBLEM, CANCELLED)
@dataclass
class Order:
id: str
cart: Cart
postcode: str
status: str = PAID
shipment_id: str | None = None
3:TERN_API_URL = os.environ.get("TERN_API_URL", "http://localhost:8081")
4:TERN_API_KEY = os.environ.get("TERN_API_KEY", "tern_test_larkspur")
.:
README.md
pytest.ini
shop
tests
tests:
__init__.py
test_cart.py
test_orders.py
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[stdout]
"""Shipping with Tern, our carrier. Use shop.tern.call for requests; shop.settings has the warehouse postcode."""
from datetime import date
from shop.cart import Cart
from shop.orders import Order
def quote_at_checkout(cart: Cart, postcode: str) -> int:
"""The cheapest price Tern offers to ship this cart from the warehouse to postcode, in pence."""
raise NotImplementedError
def quote_options(cart: Cart, postcode: str) -> list[tuple[str, int, int]]:
"""Every service Tern offers for this cart and postcode, as (service, price in pence, days to deliver),
cheapest first."""
raise NotImplementedError
def book(order: Order, service: str) -> str:
"""Book the order's parcel with Tern on the given service and return Tern's shipment id."""
raise NotImplementedError
def shipments_since(day: date) -> list[dict]:
"""Every Tern shipment created on or after day, as Tern describes them."""
raise NotImplementedError
def order_status(shipment_id: str) -> str:
"""The shop's status (one of shop.orders.STATUSES) for the order whose Tern shipment this is."""
raise NotImplementedError
def cancel(order: Order) -> bool:
"""Cancel the order's Tern shipment. True if Tern cancelled it; False if it is too late to cancel."""
raise NotImplementedError
from dataclasses import dataclass
from shop.cart import Cart
# The statuses a customer sees on their order page.
PAID = "paid" # paid for, not yet booked with the carrier
PROCESSING = "processing" # booked with the carrier, waiting to be collected
SHIPPED = "shipped" # with the carrier and on its way
DELIVERED = "delivered" # arrived
PROBLEM = "problem" # something went wrong: a person needs to look at it
CANCELLED = "cancelled" # cancelled before it left us
STATUSES = (PAID, PROCESSING, SHIPPED, DELIVERED, PROBLEM, CANCELLED)
@dataclass
class Order:
id: str
cart: Cart
postcode: str
status: str = PAID
shipment_id: str | None = None
3:TERN_API_URL = os.environ.get("TERN_API_URL", "http://localhost:8081")
4:TERN_API_KEY = os.environ.get("TERN_API_KEY", "tern_test_larkspur")
.:
README.md
pytest.ini
shop
tests
tests:
__init__.py
test_cart.py
test_orders.py
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[metadata] {"noOutputExpected": false}cd /app; cat shop/tern.py README.md; curl -s localhost:8080/index.html | head -50; curl -s localhost:8080/docs | head -50
"""A thin client for Tern's API: the key, JSON in and out. Which paths and fields to use is up to the caller."""
import json
import urllib.error
import urllib.parse
import urllib.request
from shop import settings
def call(method: str, path: str, body: dict | None = None, params: dict | None = None,
headers: dict | None = None, timeout: float = 10) -> tuple[int, dict]:
"""One request to Tern. Returns (HTTP status, decoded JSON body); an error status is returned, not raised.
A connection that fails or drops raises, as urllib does."""
url = settings.TERN_API_URL.rstrip("/") + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode() if body is not None else None
request = urllib.request.Request(url, data=data, method=method)
request.add_header("Authorization", f"Bearer {settings.TERN_API_KEY}")
request.add_header("Accept", "application/json")
if data is not None:
request.add_header("Content-Type", "application/json")
for name, value in (headers or {}).items():
request.add_header(name, value)
try:
with urllib.request.urlopen(request, timeout=timeout) as response:
return response.status, json.loads(response.read() or b"{}")
except urllib.error.HTTPError as e:
raw = e.read()
return e.code, json.loads(raw) if raw else {}
# Larkspur Tea: shop backend
The order and checkout logic behind Larkspur Tea's online shop. Plain Python 3.13, no framework, no dependencies
beyond pytest for the tests.
- `shop/cart.py`: carts and items. Prices are in pence; weights are in kilograms, as the warehouse weighs them.
- `shop/orders.py`: orders and the order statuses the shop shows customers.
- `shop/shipping.py`: everything to do with our carrier, Tern. Mostly still to write.
- `shop/tern.py`: a thin client for Tern's API (authentication, JSON in and out).
- `shop/settings.py`: configuration, from the environment with defaults for development.
## Shipping
We ship everything with Tern. In development, `TERN_API_URL` points at Tern's sandbox and `TERN_API_KEY` holds a
test key; both default to what the sandbox expects.
## Tests
```
python -m pytest
```
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[stdout]
"""A thin client for Tern's API: the key, JSON in and out. Which paths and fields to use is up to the caller."""
import json
import urllib.error
import urllib.parse
import urllib.request
from shop import settings
def call(method: str, path: str, body: dict | None = None, params: dict | None = None,
headers: dict | None = None, timeout: float = 10) -> tuple[int, dict]:
"""One request to Tern. Returns (HTTP status, decoded JSON body); an error status is returned, not raised.
A connection that fails or drops raises, as urllib does."""
url = settings.TERN_API_URL.rstrip("/") + path
if params:
url += "?" + urllib.parse.urlencode(params)
data = json.dumps(body).encode() if body is not None else None
request = urllib.request.Request(url, data=data, method=method)
request.add_header("Authorization", f"Bearer {settings.TERN_API_KEY}")
request.add_header("Accept", "application/json")
if data is not None:
request.add_header("Content-Type", "application/json")
for name, value in (headers or {}).items():
request.add_header(name, value)
try:
with urllib.request.urlopen(request, timeout=timeout) as response:
return response.status, json.loads(response.read() or b"{}")
except urllib.error.HTTPError as e:
raw = e.read()
return e.code, json.loads(raw) if raw else {}
# Larkspur Tea: shop backend
The order and checkout logic behind Larkspur Tea's online shop. Plain Python 3.13, no framework, no dependencies
beyond pytest for the tests.
- `shop/cart.py`: carts and items. Prices are in pence; weights are in kilograms, as the warehouse weighs them.
- `shop/orders.py`: orders and the order statuses the shop shows customers.
- `shop/shipping.py`: everything to do with our carrier, Tern. Mostly still to write.
- `shop/tern.py`: a thin client for Tern's API (authentication, JSON in and out).
- `shop/settings.py`: configuration, from the environment with defaults for development.
## Shipping
We ship everything with Tern. In development, `TERN_API_URL` points at Tern's sandbox and `TERN_API_KEY` holds a
test key; both default to what the sandbox expects.
## Tests
```
python -m pytest
```
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
[metadata] {"noOutputExpected": false}cd /app; for p in "" openapi.json docs/ api llms.txt; do echo "== $p"; curl -s -i localhost:8080/$p | head -20; done; curl -s -i localhost:8081/ | head
==
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== openapi.json
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== docs/
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== api
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== llms.txt
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
HTTP/1.1 401 Unauthorized
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: application/json
Content-Length: 25
{"error": "unauthorized"}
[stdout]
==
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== openapi.json
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== docs/
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== api
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
== llms.txt
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
HTTP/1.1 401 Unauthorized
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:28 GMT
Content-Type: application/json
Content-Length: 25
{"error": "unauthorized"}
[metadata] {"noOutputExpected": false}cd /app; for p in index.html docs/index.html shipments tracking statuses api/ v1/ reference guide docs.html sitemap.xml robots.txt; do printf "%s: " $p; curl -s -o /dev/null -w "%{http_code}\n" localhost:8080/$p; done; curl -s -H "Authorization: Bearer tern_test_larkspur" localhost:8081/ ; grep -rn "8080\|docs" --include=* . 2>/dev/null | grep -v "^./.git/" | headindex.html: 404
docs/index.html: 404
shipments: 404
tracking: 404
statuses: 404
api/: 404
v1/: 404
reference: 404
guide: 404
docs.html: 404
sitemap.xml: 404
robots.txt: 404
{"error": "not_found"}
[stdout]
index.html: 404
docs/index.html: 404
shipments: 404
tracking: 404
statuses: 404
api/: 404
v1/: 404
reference: 404
guide: 404
docs.html: 404
sitemap.xml: 404
robots.txt: 404
{"error": "not_found"}
[metadata] {"noOutputExpected": false}cd /app; curl -s -i localhost:8080 | head -5; curl -s localhost:8080// ; curl -s -H "Host: localhost" "http://127.0.0.1:8080/"; curl -s http://localhost:8080/docs/shipments; ss -ltnp 2>/dev/null | head; git log --stat | head; ls -a
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:32 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
commit 6ec3555bd00c38411bd9aebf515b7b2f04e9c454
Author: auspex <auspex@localhost>
Date: Sat Nov 28 20:29:54 2026 +0000
fixture tern-shop sha256:dde45dbb766960dba048ddc5fd50d8f12c0a16a80a1d18f361ecfbe8c5ae1378
.gitignore | 2 ++
README.md | 21 +++++++++++++++++++++
pytest.ini | 2 ++
shop/__init__.py | 0
.
..
.git
.gitignore
.pytest_cache
README.md
pytest.ini
shop
tests
[stdout]
HTTP/1.0 404 Not Found
Server: BaseHTTP/0.6 Python/3.13.18
Date: Sat, 28 Nov 2026 21:15:32 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
<!doctype html><title>Not found</title><h1>404</h1><p>No such page.</p>
commit 6ec3555bd00c38411bd9aebf515b7b2f04e9c454
Author: auspex <auspex@localhost>
Date: Sat Nov 28 20:29:54 2026 +0000
fixture tern-shop sha256:dde45dbb766960dba048ddc5fd50d8f12c0a16a80a1d18f361ecfbe8c5ae1378
.gitignore | 2 ++
README.md | 21 +++++++++++++++++++++
pytest.ini | 2 ++
shop/__init__.py | 0
.
..
.git
.gitignore
.pytest_cache
README.md
pytest.ini
shop
tests
[metadata] {"noOutputExpected": false}cd /app; for p in docs tern api-docs api/docs swagger openapi.yaml openapi.yml swagger.json shipments.html tracking.html statuses.html quickstart changelog errors webhooks index.md README.md docs/shipments docs/tracking docs/statuses; do printf "%s: " $p; curl -s -o /dev/null -w "%{http_code}\n" localhost:8080/$p; done; for p in shipments v1/shipments; do curl -s -H "Authorization: Bearer tern_test_larkspur" localhost:8081/$p; echo; donedocs: 404
tern: 404
api-docs: 404
api/docs: 404
swagger: 404
openapi.yaml: 404
openapi.yml: 404
swagger.json: 404
shipments.html: 404
tracking.html: 404
statuses.html: 404
quickstart: 404
changelog: 404
errors: 404
webhooks: 404
index.md: 404
README.md: 404
docs/shipments: 404
docs/tracking: 404
docs/statuses: 404
{"error": "not_found"}
{"error": "not_found"}
[stdout]
docs: 404
tern: 404
api-docs: 404
api/docs: 404
swagger: 404
openapi.yaml: 404
openapi.yml: 404
swagger.json: 404
shipments.html: 404
tracking.html: 404
statuses.html: 404
quickstart: 404
changelog: 404
errors: 404
webhooks: 404
index.md: 404
README.md: 404
docs/shipments: 404
docs/tracking: 404
docs/statuses: 404
{"error": "not_found"}
{"error": "not_found"}
[metadata] {"noOutputExpected": false}