|
3 | 3 | from flama import endpoints, http, injection, websockets |
4 | 4 | from flama.applications import Flama |
5 | 5 | from flama.client import Client |
| 6 | +from flama.routing.routes.mount import Mount |
6 | 7 |
|
7 | 8 |
|
8 | 9 | class Puppy: |
@@ -166,3 +167,39 @@ def foo(unknown: Unknown): |
166 | 167 | ): |
167 | 168 | async with Client(app) as client: |
168 | 169 | 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