-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathexample_app.py
More file actions
51 lines (32 loc) · 1.41 KB
/
example_app.py
File metadata and controls
51 lines (32 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Quick smoke test — verifies turboapi-core extraction didn't break anything."""
from turboapi import TurboAPI
app = TurboAPI(title="Core Extraction Test")
@app.get("/")
def root():
return {"status": "ok", "message": "turboapi-core extraction works!"}
@app.get("/hello/{name}")
def hello(name: str):
return {"hello": name}
@app.get("/add/{a}/{b}")
def add(a: int, b: int):
return {"result": a + b}
@app.get("/search")
def search(q: str = "default", page: int = 1):
return {"query": q, "page": page}
if __name__ == "__main__":
from turboapi.testclient import TestClient
client = TestClient(app)
print("Testing routes via turboapi-core radix trie router...")
r = client.get("/")
assert r.status_code == 200 and r.json()["status"] == "ok"
print(f" GET / -> {r.status_code} {r.json()}")
r = client.get("/hello/rach")
assert r.status_code == 200 and r.json()["hello"] == "rach"
print(f" GET /hello/rach -> {r.status_code} {r.json()}")
r = client.get("/add/3/4")
assert r.status_code == 200 and r.json()["result"] == 7
print(f" GET /add/3/4 -> {r.status_code} {r.json()}")
r = client.get("/search?q=zig&page=2")
assert r.status_code == 200 and r.json()["query"] == "zig" and r.json()["page"] == 2
print(f" GET /search?q=zig -> {r.status_code} {r.json()}")
print("\nAll routes working! turboapi-core extraction is clean.")