Skip to content

Commit 61a1247

Browse files
committed
chore: test preflight on notfound with middlware
1 parent 34617fb commit 61a1247

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/functional/event_handler/test_api_middlewares.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
APIGatewayHttpResolver,
88
ApiGatewayResolver,
99
APIGatewayRestResolver,
10+
CORSConfig,
1011
ProxyEventType,
1112
Response,
1213
Router,
@@ -537,3 +538,29 @@ def nope() -> dict: ...
537538
# AND ensure middlewares are called
538539
assert result["statusCode"] == 404
539540
assert result["body"] == "middleware works"
541+
542+
543+
def test_global_middleware_not_found_preflight():
544+
# GIVEN global middleware is registered
545+
546+
app = ApiGatewayResolver(cors=CORSConfig(), proxy_type=ProxyEventType.APIGatewayProxyEvent)
547+
event = {**API_REST_EVENT, "httpMethod": "OPTIONS"}
548+
549+
def middleware(app: ApiGatewayResolver, next_middleware: NextMiddleware):
550+
# add additional data to Router Context
551+
ret = next_middleware(app)
552+
ret.body = "middleware works"
553+
return ret
554+
555+
app.use(middlewares=[middleware])
556+
557+
@app.get("/this/path/does/not/exist")
558+
def nope() -> dict: ...
559+
560+
# WHEN calling the event handler for an unregistered route /my/path OPTIONS
561+
result = app(event, {})
562+
563+
# THEN process event correctly as HTTP 204 (not 404)
564+
# AND ensure middlewares are called
565+
assert result["statusCode"] == 204
566+
assert result["body"] == "middleware works"

0 commit comments

Comments
 (0)