Skip to content

Commit 7f61079

Browse files
committed
Update routes in end2end test
1 parent 1731580 commit 7f61079

2 files changed

Lines changed: 24 additions & 25 deletions

File tree

end2end/fastapi_postgres_uvicorn_test.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,22 @@ def test_routes_discovered_in_heartbeat():
8686
heartbeat_events = filter_on_event_type(events, "heartbeat")
8787
assert len(heartbeat_events) >= 1
8888

89-
validate_heartbeat(
90-
heartbeat_events[0],
91-
routes=[{
92-
"apispec": {
93-
"body": {
94-
"type": "form-urlencoded",
95-
"schema": {
96-
"type": "object",
97-
"properties": {
98-
"dog_name": {
99-
"items": {"type": "string"},
100-
"type": "array",
101-
}
102-
},
103-
},
104-
},
105-
"query": None,
106-
"auth": None,
89+
routes = heartbeat_events[0]["routes"]
90+
route_map = {(r["method"], r["path"]): r for r in routes}
91+
92+
assert ("POST", "/create") in route_map
93+
create_route = route_map[("POST", "/create")]
94+
assert create_route["apispec"] == {
95+
"auth": None,
96+
"body": {
97+
"schema": {
98+
"properties": {"dog_name": {"type": "string"}},
99+
"type": "object",
107100
},
108-
"hits": 1,
109-
"hits_delta_since_sync": 0,
110-
"method": "POST",
111-
"path": "/create",
112-
}],
113-
)
101+
"type": "form-urlencoded",
102+
},
103+
"query": None,
104+
}
105+
assert create_route["hits"] == 1
106+
107+
assert ("GET", "/sync_route") in route_map

sample-apps/fastapi-postgres-uvicorn/app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
allow_methods=["*"],
2222
allow_headers=["*"],
2323
)
24+
@app.middleware("http")
25+
async def set_user_middleware(request: Request, call_next):
26+
aikido_zen.set_user({"id": "user123", "name": "John Doe"})
27+
return await call_next(request)
28+
2429
app.add_middleware(AikidoFastAPIMiddleware)
2530

2631
async def get_db_connection():
@@ -61,7 +66,7 @@ async def create_dog(request: Request):
6166

6267
conn = await get_db_connection()
6368
try:
64-
await conn.execute("INSERT INTO dogs (dog_name, isAdmin) VALUES ($1, FALSE)", dog_name)
69+
await conn.execute(f"INSERT INTO dogs (dog_name, isAdmin) VALUES ('%s', FALSE)" % (dog_name))
6570
finally:
6671
await conn.close()
6772

0 commit comments

Comments
 (0)