Smoke Test Generator
A structured pattern for API smoke testing with categorised test suites and summary reporting. Adapted from a production test suite that verified 34 endpoints across auth, CRUD, cached audio, story generation, ElevenLabs, and Mistral agent APIs.
Test Categories
| Category |
What It Tests |
Fail = |
| Auth |
Login, token validation, protected routes |
Nothing else works |
| CRUD |
Create, read, update, delete operations |
Data layer broken |
| Cached |
Pre-cached content serves correctly |
Demo will fail |
| Live |
Real API calls complete successfully |
External dependency down |
| Integration |
End-to-end workflows across services |
Pipeline broken |
Pattern
import httpx
import asyncio
BASE_URL = "http://localhost:8000"
results = {"pass": 0, "fail": 0, "skip": 0}
async def test(name: str, category: str, fn):
try:
await fn()
results["pass"] += 1
print(f" ✅ [{category}] {name}")
except Exception as e:
results["fail"] += 1
print(f" ❌ [{category}] {name}: {e}")
async def run_smoke_tests():
async with httpx.AsyncClient(base_url=BASE_URL, timeout=30) as client:
# Auth
await test("Login with valid creds", "auth",
lambda: assert_status(client.post("/login", json={"email": "test@test.com", "password": "test"}), 200))
# CRUD
await test("Create item", "crud",
lambda: assert_status(client.post("/api/items", json={"name": "test"}), 201))
# Cached
await test("Cached content returns 200", "cached",
lambda: assert_status(client.get("/api/cached/1"), 200))
# Integration
await test("Full pipeline completes", "integration",
lambda: assert_status(client.post("/api/pipeline", json={...}), 200))
total = results["pass"] + results["fail"]
print(f"\n{'='*40}")
print(f"Results: {results['pass']}/{total} passed")
if results["fail"] > 0:
print(f"⚠️ {results['fail']} failures — do not demo!")
Files
scripts/smoke_test.py — Example smoke test suite with all categories
1---
2name: smoke-test-generator
3description: Generate comprehensive API smoke test suites — categorised tests for auth, CRUD, integrations, cached vs live endpoints, with summary reporting. Use when validating API deployments, CI smoke checks, or pre-demo verification. Works with any HTTP API.
4version: 1.0.0
5metadata:
6 {
7 "openclaw": {
8 "emoji": "\ud83e\uddea",
9 "requires": {
10 "bins": [],
11 "env": []
12 },
13 "primaryEnv": null,
14 "network": {
15 "outbound": true,
16 "reason": "Sends HTTP requests to the API under test (typically localhost). No external service calls."
17 }
18 }
19}
20---
21
22# Smoke Test Generator
23
24A structured pattern for API smoke testing with categorised test suites and summary reporting. Adapted from a production test suite that verified 34 endpoints across auth, CRUD, cached audio, story generation, ElevenLabs, and Mistral agent APIs.
25
26## Test Categories
27
28| Category | What It Tests | Fail = |
29|---|---|---|
30| Auth | Login, token validation, protected routes | Nothing else works |
31| CRUD | Create, read, update, delete operations | Data layer broken |
32| Cached | Pre-cached content serves correctly | Demo will fail |
33| Live | Real API calls complete successfully | External dependency down |
34| Integration | End-to-end workflows across services | Pipeline broken |
35
36## Pattern
37
38```python
39import httpx
40import asyncio
41
42BASE_URL = "http://localhost:8000"
43results = {"pass": 0, "fail": 0, "skip": 0}
44
45async def test(name: str, category: str, fn):
46 try:
47 await fn()
48 results["pass"] += 1
49 print(f" ✅ [{category}] {name}")
50 except Exception as e:
51 results["fail"] += 1
52 print(f" ❌ [{category}] {name}: {e}")
53
54async def run_smoke_tests():
55 async with httpx.AsyncClient(base_url=BASE_URL, timeout=30) as client:
56 # Auth
57 await test("Login with valid creds", "auth",
58 lambda: assert_status(client.post("/login", json={"email": "test@test.com", "password": "test"}), 200))
59
60 # CRUD
61 await test("Create item", "crud",
62 lambda: assert_status(client.post("/api/items", json={"name": "test"}), 201))
63
64 # Cached
65 await test("Cached content returns 200", "cached",
66 lambda: assert_status(client.get("/api/cached/1"), 200))
67
68 # Integration
69 await test("Full pipeline completes", "integration",
70 lambda: assert_status(client.post("/api/pipeline", json={...}), 200))
71
72 total = results["pass"] + results["fail"]
73 print(f"\n{'='*40}")
74 print(f"Results: {results['pass']}/{total} passed")
75 if results["fail"] > 0:
76 print(f"⚠️ {results['fail']} failures — do not demo!")
77```
78
79## Files
80
81- `scripts/smoke_test.py` — Example smoke test suite with all categories