Skip to content

Commit

Permalink
add baize.asgi test
Browse files Browse the repository at this point in the history
  • Loading branch information
abersheeran committed Jun 26, 2024
1 parent 5308867 commit c09cf7f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
24 changes: 23 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ dev = [
]
benchmark = ["uvicorn>=0.16.0", "asgiref>=3.4.1"]
test = [
"pytest<8.0.0,>=7.0.1",
"pytest-cov<4.0.0,>=3.0.0",
"pytest-asyncio<1.0.0,>=0.11.0",
"starlette>=0.37.2",
"pytest<8.0.0,>=7.0.1",
"pytest-cov<4.0.0,>=3.0.0",
"pytest-asyncio<1.0.0,>=0.11.0",
"starlette>=0.37.2",
"baize>=0.20.8",
]

[tool.pdm.build]
Expand Down
16 changes: 16 additions & 0 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,19 @@ async def dispatch(self, request, call_next):
assert response.status_code == 200
assert response.text == '{"hello":"world"}'
assert response.headers["x-middleware"] == "true"


def test_baize_stream_response():
from baize.asgi import StreamResponse

async def stream():
for i in range(10):
yield str(i).encode()

app = ASGIMiddleware(StreamResponse(stream()))
with httpx.Client(
transport=httpx.WSGITransport(app=app), base_url="http://testserver:80"
) as client:
response = client.get("/")
assert response.status_code == 200
assert response.text == "0123456789"

0 comments on commit c09cf7f

Please sign in to comment.