Skip to content

Commit 97c9c5b

Browse files
committed
Add more tests
1 parent 50455a1 commit 97c9c5b

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

httpx/_dispatch/wsgi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def _get_non_empty_chunk(body: typing.Iterable) -> typing.Iterable:
1818
for chunk in body:
1919
if chunk:
2020
return itertools.chain([chunk], body)
21+
return []
2122

2223

2324
class WSGIDispatch(SyncDispatcher):

tests/client/test_client.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ def test_elapsed_delay(server):
155155
assert response.elapsed.total_seconds() > 0.0
156156

157157

158-
def test_wsgi_app_generator():
159-
def application(env, start_response):
160-
body = b"""
158+
_wsgi_body = b"""
161159
162160
163161
<!DOCTYPE html>
@@ -170,10 +168,39 @@ def application(env, start_response):
170168
</body>
171169
</html>
172170
"""
171+
172+
173+
def test_wsgi_app():
174+
def application(env, start_response):
175+
start_response("200 OK", [("Content-Type", "text/html")])
176+
return [_wsgi_body]
177+
178+
with httpx.Client(app=application) as client:
179+
response = client.get("http://example.com/")
180+
assert response.status_code == 200
181+
assert b"This page deliberately left blank" in response.content
182+
183+
184+
def test_wsgi_app_generator():
185+
def application(env, start_response):
173186
start_response("200 OK", [("Content-Type", "text/html")])
174-
for line in body.split(b"\n"):
187+
for line in _wsgi_body.split(b"\n"):
175188
yield line
176189

177190
with httpx.Client(app=application) as client:
178191
response = client.get("http://example.com/")
192+
assert response.status_code == 200
179193
assert b"This page deliberately left blank" in response.content
194+
195+
196+
def test_wsgi_app_generator_empty():
197+
def application(env, start_response):
198+
body = [b"", b"", b""]
199+
start_response("200 OK", [("Content-Type", "text/html")])
200+
for line in body:
201+
yield line
202+
203+
with httpx.Client(app=application) as client:
204+
response = client.get("http://example.com/")
205+
assert response.status_code == 200
206+
assert response.content == b""

0 commit comments

Comments
 (0)