- connect_frontend/order-app at /order/{site}: menu per service at that service's prices,
extras, basket (kept per tab), checkout priced by the cloud (fee, area by list or
postcode, minimum), name/phone/address/notes (remembered), as soon as possible or a time
slot, tracking page with steps, lines and totals; en/el; tokens in index.css. Logic in
src/logic.js, unit-tested; built and served by the connect image (npm test in the build).
- services/ordering.py: the venue's services, hours (past midnight), preparation, slot grid,
days ahead, ASAP; takeaway/delivery orders checked (order.service_unavailable,
order.closed, order.time_invalid) and need a phone; GET /api/orders/{site}/slots; the
public menu carries the ordering summary.
- services/ratelimit.py: per-caller limits on quote, order and track (429 rate.limited).
- online_orders.requested_for (0003, unreleased) stored as UTC; every datetime sent with its
offset (the database keeps no zone: a 12:00 Athens slot came back as 12:00 unzoned).
- Tracking returns what was ordered, the totals, the type and the time.
- Tests: test_ordering.py (5), checkout/fees updated; order-app unit (4).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
"""Cloud backend tests. Run from cloud_backend/: python -m pytest tests -q
|
|
|
|
Before anything imports config/database, DATABASE_URL points at a fresh temp file and a
|
|
throwaway LICENSE_SIGNING_KEY is set, so tests never touch a real cloud DB or key.
|
|
"""
|
|
import base64
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from cryptography.hazmat.primitives import serialization
|
|
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
|
|
|
|
_TMP = Path(tempfile.mkdtemp(prefix="xenia-cloud-tests-"))
|
|
os.environ["DATABASE_URL"] = f"sqlite:///{(_TMP / 'cloud.db').as_posix()}"
|
|
TEST_KEY = Ed25519PrivateKey.generate()
|
|
os.environ["LICENSE_SIGNING_KEY"] = base64.b64encode(
|
|
TEST_KEY.private_bytes(serialization.Encoding.Raw, serialization.PrivateFormat.Raw,
|
|
serialization.NoEncryption())).decode()
|
|
TEST_PUB = base64.b64encode(TEST_KEY.public_key().public_bytes(
|
|
serialization.Encoding.Raw, serialization.PublicFormat.Raw)).decode()
|
|
os.environ["ADMIN_USERNAME"] = "sysadmin"
|
|
os.environ["ADMIN_PASSWORD"] = "test-admin-pw"
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
import pytest # noqa: E402
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def client():
|
|
from fastapi.testclient import TestClient
|
|
import main
|
|
with TestClient(main.app) as c: # runs the lifespan: Alembic upgrade + default admin
|
|
yield c
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def admin_h(client):
|
|
r = client.post("/api/auth/login", json={"username": "sysadmin", "password": "test-admin-pw"})
|
|
assert r.status_code == 200, r.text
|
|
return {"Authorization": f"Bearer {r.json()['access_token']}"}
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _fresh_rate_limits():
|
|
"""Every test starts with empty rate-limit counters (services/ratelimit.py, S.4)."""
|
|
from services import ratelimit
|
|
ratelimit.reset()
|
|
yield
|