Skip to content
Myr

test_wsgi.py

This file

Path

tests/test_wsgi.py

118 lines · 2.9 KiB · Python

Last changed by

Exception hierarchy (#1095)Tom Christiebefore adoption9409900

History of this file

Take it

The walk stopped after 200 commits: lines older than 6614831 point at it.

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

line 1why, one step back
1import sys

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 2why, one step back
2from functools import partial

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

lines 3–8why, one step back
3
4import pytest56import httpx78

Fix support for generator-based WSGI apps (#887)Ed Singletonbefore adoption94323f9

lines 9–11why, one step back
9def application_factory(output):
10 def application(environ, start_response):11 status = "200 OK"

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

line 12why, one step back
12

Fix support for generator-based WSGI apps (#887)Ed Singletonbefore adoption94323f9

lines 13–15why, one step back
13 response_headers = [
14 ("Content-type", "text/plain"),15 ]

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

line 16why, one step back
16

Fix support for generator-based WSGI apps (#887)Ed Singletonbefore adoption94323f9

line 17why, one step back
17 start_response(status, response_headers)

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

line 18why, one step back
18

Fix support for generator-based WSGI apps (#887)Ed Singletonbefore adoption94323f9

lines 19–20why, one step back
19 for item in output:
20 yield item

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

line 21why, one step back
21

Fix support for generator-based WSGI apps (#887)Ed Singletonbefore adoption94323f9

line 22why, one step back
22 return application

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

line 23why, one step back
23

Fix support for generator-based WSGI apps (#887)Ed Singletonbefore adoption94323f9

line 24why, one step back
24

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

lines 25–54why, one step back
25def echo_body(environ, start_response):
26 status = "200 OK"27 output = environ["wsgi.input"].read()2829 response_headers = [30 ("Content-type", "text/plain"),31 ]3233 start_response(status, response_headers)3435 return [output]363738def echo_body_with_response_stream(environ, start_response):39 status = "200 OK"4041 response_headers = [("Content-Type", "text/plain")]4243 start_response(status, response_headers)4445 def output_generator(f):46 while True:47 output = f.read(2)48 if not output:49 break50 yield output5152 return output_generator(f=environ["wsgi.input"])5354

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 55why, one step back
55def raise_exc(environ, start_response, exc=ValueError):

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

lines 56–63why, one step back
56 status = "500 Server Error"
57 output = b"Nope!"5859 response_headers = [60 ("Content-type", "text/plain"),61 ]6263 try:

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 64–65why, one step back
64 raise exc()
65 except exc:

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

lines 66–72why, one step back
66 exc_info = sys.exc_info()
67 start_response(status, response_headers, exc_info=exc_info)6869 return [output]707172def test_wsgi():

Fix support for generator-based WSGI apps (#887)Ed Singletonbefore adoption94323f9

line 73why, one step back
73 client = httpx.Client(app=application_factory([b"Hello, World!"]))

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

lines 74–95why, one step back
74 response = client.get("http://www.example.org/")
75 assert response.status_code == 20076 assert response.text == "Hello, World!"777879def test_wsgi_upload():80 client = httpx.Client(app=echo_body)81 response = client.post("http://www.example.org/", data=b"example")82 assert response.status_code == 20083 assert response.text == "example"848586def test_wsgi_upload_with_response_stream():87 client = httpx.Client(app=echo_body_with_response_stream)88 response = client.post("http://www.example.org/", data=b"example")89 assert response.status_code == 20090 assert response.text == "example"919293def test_wsgi_exc():94 client = httpx.Client(app=raise_exc)95 with pytest.raises(ValueError):

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 96–99why, one step back
96 client.get("http://www.example.org/")
979899def test_wsgi_http_error():

Exception hierarchy (#1095)Tom Christiebefore adoption9409900

lines 100–101why, one step back
100 client = httpx.Client(app=partial(raise_exc, exc=RuntimeError))
101 with pytest.raises(RuntimeError):

Use a base_url in app dispatcher examples (#799)Florimond Mancabefore adoption6614831

line 102why, one step back
102 client.get("http://www.example.org/")

Fix support for generator-based WSGI apps (#887)Ed Singletonbefore adoption94323f9

lines 103–118why, one step back
103
104105def test_wsgi_generator():106 output = [b"", b"", b"Some content", b" and more content"]107 client = httpx.Client(app=application_factory(output))108 response = client.get("http://www.example.org/")109 assert response.status_code == 200110 assert response.text == "Some content and more content"111112113def test_wsgi_generator_empty():114 output = [b"", b"", b"", b""]115 client = httpx.Client(app=application_factory(output))116 response = client.get("http://www.example.org/")117 assert response.status_code == 200118 assert response.text == ""