|
26 | 26 |
|
27 | 27 | # from nitric.faas import HttpMethod, MethodOptions, ApiWorkerOptions |
28 | 28 | from nitric.resources import api, ApiOptions, JwtSecurityDefinition |
29 | | -from nitric.resources.apis import MethodOptions, ScopedOidcOptions, oidc_rule |
| 29 | +from nitric.resources.apis import MethodOptions, ScopedOidcOptions, oidc_rule, HttpMiddleware |
30 | 30 | from nitric.proto.resources.v1 import ( |
31 | 31 | ApiOpenIdConnectionDefinition, |
32 | 32 | ApiSecurityDefinitionResource, |
|
40 | 40 | from nitric.proto.apis.v1 import ApiDetailsResponse, ApiDetailsRequest, ApiWorkerScopes |
41 | 41 |
|
42 | 42 | from nitric.context import ( |
| 43 | + HttpContext, |
43 | 44 | HttpMethod, |
44 | 45 | ) |
45 | 46 |
|
@@ -221,6 +222,23 @@ def test_api_route(self): |
221 | 222 | assert test_route.middleware == [] |
222 | 223 | assert test_route.api.name == test_api.name |
223 | 224 |
|
| 225 | + def test_api_route_middleware(self): |
| 226 | + mock_declare = AsyncMock() |
| 227 | + mock_response = Object() |
| 228 | + mock_declare.return_value = mock_response |
| 229 | + |
| 230 | + async def middleware_test(ctx: HttpContext, nxt: HttpMiddleware): |
| 231 | + return nxt(ctx) |
| 232 | + |
| 233 | + with patch("nitric.proto.resources.v1.ResourcesStub.declare", mock_declare): |
| 234 | + test_api = api("test-api-route-middleware", ApiOptions(path="/api/v2/", middleware=[middleware_test])) |
| 235 | + |
| 236 | + test_route = test_api._route("/test") |
| 237 | + |
| 238 | + assert len(test_api.middleware) == 1 |
| 239 | + assert len(test_route.middleware) == 1 |
| 240 | + |
| 241 | + |
224 | 242 | def test_define_route(self): |
225 | 243 | mock_declare = AsyncMock() |
226 | 244 | mock_response = Object() |
|
0 commit comments