starlette/tests/test_decorators.py

25 lines
676 B
Python
Raw Normal View History

2018-06-25 13:15:32 +00:00
from starlette import asgi_application, Response, TestClient
def test_sync_app():
2018-06-25 13:15:32 +00:00
@asgi_application
def app(request):
return Response("hello, world", media_type="text/plain")
client = TestClient(app)
response = client.get("/")
assert response.status_code == 200
assert response.text == "hello, world"
def test_async_app():
@asgi_application
async def app(request):
body = await request.body()
return Response(body, media_type="text/plain")
client = TestClient(app)
response = client.post("/", json={"hello": "world"})
assert response.status_code == 200
assert response.text == '{"hello": "world"}'