Skip to content

Commit

Permalink
integration test update for Esmerald (#1087)
Browse files Browse the repository at this point in the history
* integration test update for Esmerald

* use @dantownsend code for dummy_server
  • Loading branch information
sinisaos authored Sep 30, 2024
1 parent 6aa998c commit 36ccc28
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
4 changes: 2 additions & 2 deletions piccolo/apps/asgi/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
SERVERS = ["uvicorn", "Hypercorn", "granian"]
ROUTER_DEPENDENCIES = {
"starlette": ["starlette"],
"fastapi": ["fastapi>=0.112.1"],
"fastapi": ["fastapi"],
"blacksheep": ["blacksheep"],
"litestar": ["litestar"],
"esmerald": ["esmerald==3.3.0"],
"esmerald": ["esmerald"],
"lilya": ["lilya"],
}
ROUTERS = list(ROUTER_DEPENDENCIES.keys())
Expand Down
1 change: 1 addition & 0 deletions requirements/test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coveralls==3.3.1
httpx==0.27.2
pytest-cov==3.0.0
pytest==6.2.5
python-dateutil==2.8.2
Expand Down
38 changes: 10 additions & 28 deletions tests/apps/asgi/commands/files/dummy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import sys
import typing as t

from httpx import AsyncClient

def dummy_server(app: t.Union[str, t.Callable] = "app:app"):

async def dummy_server(app: t.Union[str, t.Callable] = "app:app"):
"""
A very simplistic ASGI server. It's used to run the generated ASGI
applications in unit tests.
Expand All @@ -20,33 +22,13 @@ def dummy_server(app: t.Union[str, t.Callable] = "app:app"):
if isinstance(app, str):
path, app_name = app.rsplit(":")
module = importlib.import_module(path)
app = getattr(module, app_name)

async def send(message):
if message["type"] == "http.response.start":
if message["status"] == 200:
print("Received 200")
else:
sys.exit("200 not received from app")

async def receive():
pass

scope = {
"scheme": "http",
"type": "http",
"path": "/",
"raw_path": b"/",
"method": "GET",
"query_string": b"",
"headers": [],
}
if callable(app):
asyncio.run(app(scope, receive, send))
print("Exiting dummy server ...")
else:
sys.exit("The app isn't callable!")
app = t.cast(t.Callable, getattr(module, app_name))

async with AsyncClient(app=app) as client:
response = await client.get("http://localhost:8000")
if response.status_code != 200:
sys.exit("The app isn't callable!")


if __name__ == "__main__":
dummy_server()
asyncio.run(dummy_server())

0 comments on commit 36ccc28

Please sign in to comment.