Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
davemooreuws committed Apr 3, 2024
1 parent 46842c3 commit b26a81c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/resources/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# from nitric.faas import HttpMethod, MethodOptions, ApiWorkerOptions
from nitric.resources import api, ApiOptions, JwtSecurityDefinition
from nitric.resources.apis import MethodOptions, ScopedOidcOptions, oidc_rule
from nitric.resources.apis import MethodOptions, ScopedOidcOptions, oidc_rule, HttpMiddleware
from nitric.proto.resources.v1 import (
ApiOpenIdConnectionDefinition,
ApiSecurityDefinitionResource,
Expand All @@ -40,6 +40,7 @@
from nitric.proto.apis.v1 import ApiDetailsResponse, ApiDetailsRequest, ApiWorkerScopes

from nitric.context import (
HttpContext,
HttpMethod,
)

Expand Down Expand Up @@ -221,6 +222,23 @@ def test_api_route(self):
assert test_route.middleware == []
assert test_route.api.name == test_api.name

def test_api_route_middleware(self):
mock_declare = AsyncMock()
mock_response = Object()
mock_declare.return_value = mock_response

async def middleware_test(ctx: HttpContext, nxt: HttpMiddleware):
return nxt(ctx)

with patch("nitric.proto.resources.v1.ResourcesStub.declare", mock_declare):
test_api = api("test-api-route", ApiOptions(path="/api/v2/", middleware=[middleware_test]))

test_route = test_api._route("/hello")

assert test_route.path == "/api/v2/hello"
assert test_route.middleware == [middleware_test]
assert test_route.api.name == test_api.name

def test_define_route(self):
mock_declare = AsyncMock()
mock_response = Object()
Expand Down

0 comments on commit b26a81c

Please sign in to comment.