summaryrefslogtreecommitdiffstats
path: root/lang/python/python-starlette/test.sh
blob: f515479e4c9795c023b074ad8db53d79b783736d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh

[ "$1" = python3-starlette ] || exit 0

python3 - << 'EOF'

from starlette.applications import Starlette
from starlette.responses import JSONResponse, PlainTextResponse
from starlette.routing import Route

# Render responses (no server or event loop needed) and build an app with a
# route, exercising the response encoders and the router.
assert JSONResponse({"a": 1}).body == b'{"a":1}'
assert PlainTextResponse("hi").body == b"hi"

async def home(request):
    return JSONResponse({"ok": True})

app = Starlette(routes=[Route("/", home)])
assert any(getattr(r, "path", None) == "/" for r in app.routes)

EOF