-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_issue_async_function.py
More file actions
37 lines (25 loc) · 1.07 KB
/
test_issue_async_function.py
File metadata and controls
37 lines (25 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from starlette.applications import Starlette
from starlette.responses import Response
from starlette.routing import Route
from starlette.testclient import TestClient
from kink import di, inject
def test_resolve_kwargs_in_async_function() -> None:
di["name"] = "Bob"
@inject()
async def example_async(request, name: str = "Tom") -> Response:
body = await request.body()
return Response(f"Hello {name}")
application = Starlette(routes=[Route("/test", example_async, methods=["GET"])])
test_client = TestClient(application)
response = test_client.get("/test")
assert response.status_code == 200
assert response.content == b"Hello Bob"
def test_resolve_no_parameters_in_async() -> None:
@inject
async def example_async(request) -> Response:
return Response(f"Hello Bob")
application = Starlette(routes=[Route("/test", example_async, methods=["GET"])])
test_client = TestClient(application)
response = test_client.get("/test")
assert response.status_code == 200
assert response.content == b"Hello Bob"