File tree 1 file changed +27
-0
lines changed
tests/functional/event_handler
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 7
7
APIGatewayHttpResolver ,
8
8
ApiGatewayResolver ,
9
9
APIGatewayRestResolver ,
10
+ CORSConfig ,
10
11
ProxyEventType ,
11
12
Response ,
12
13
Router ,
@@ -537,3 +538,29 @@ def nope() -> dict: ...
537
538
# AND ensure middlewares are called
538
539
assert result ["statusCode" ] == 404
539
540
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"
You can’t perform that action at this time.
0 commit comments