Skip to content

Commit 89640cf

Browse files
committed
✅ Tests for injection on mounted applications
1 parent 084818a commit 89640cf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/test_injection.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from flama import endpoints, http, injection, websockets
44
from flama.applications import Flama
55
from flama.client import Client
6+
from flama.routing.routes.mount import Mount
67

78

89
class Puppy:
@@ -166,3 +167,39 @@ def foo(unknown: Unknown):
166167
):
167168
async with Client(app) as client:
168169
await client.request("get", "/")
170+
171+
async def test_injection_mount(self, puppy_component):
172+
foo_app = Flama(schema=None, docs=None, components=[puppy_component])
173+
app = Flama(schema=None, docs=None, routes=[Mount("/foo/", app=foo_app)])
174+
175+
@foo_app.route("/puppy/")
176+
async def puppy(puppy: Puppy):
177+
return http.JSONResponse({"puppy": puppy.name})
178+
179+
async with Client(app) as client:
180+
response = await client.request("get", "/foo/puppy/")
181+
182+
assert response.status_code == 200
183+
assert response.json() == {"puppy": "Canna"}
184+
185+
async def test_injection_nested_mount(self, puppy_component, owner_component):
186+
bar_app = Flama(schema=None, docs=None, components=[owner_component])
187+
foo_app = Flama(schema=None, docs=None, components=[puppy_component], routes=[Mount("/bar", app=bar_app)])
188+
app = Flama(schema=None, docs=None, routes=[Mount("/foo/", app=foo_app)])
189+
190+
@foo_app.route("/puppy/")
191+
async def puppy(puppy: Puppy):
192+
return http.JSONResponse({"puppy": puppy.name})
193+
194+
@bar_app.route("/owner/")
195+
async def owner(puppy: Puppy, owner: Owner):
196+
return http.JSONResponse({"owner": owner.name, "puppy": puppy.name})
197+
198+
async with Client(app) as client:
199+
response_puppy = await client.request("get", "/foo/puppy/")
200+
response_owner = await client.request("get", "/foo/bar/owner/")
201+
202+
assert response_puppy.status_code == 200
203+
assert response_puppy.json() == {"puppy": "Canna"}
204+
assert response_owner.status_code == 200
205+
assert response_owner.json() == {"owner": "Perdy", "puppy": "Canna"}

0 commit comments

Comments
 (0)