test_requests.py
This file
Path
tests/models/test_requests.py
94 lines · 2.7 KiB · Python
Last changed by
Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc
History of this fileTake it
The walk stopped after 200 commits: lines older than c9810a7 point at it.
Add support for SSL_CERT_FILE and SSL_CERT_DIR (#307)Can Sarıgölbefore adoptionc9810a7
lines 1–20why, one step back1import pytest23import httpx456def test_request_repr():7 request = httpx.Request("GET", "http://example.org")8 assert repr(request) == "<Request('GET', 'http://example.org')>"91011def test_no_content():12 request = httpx.Request("GET", "http://example.org")13 assert "Content-Length" not in request.headers141516def test_content_length_header():17 request = httpx.Request("POST", "http://example.org", data=b"test 123")18 assert request.headers["Content-Length"] == "8"1920Added RequestContent (#636)Tom Christiebefore adoption8d4f182
lines 21–22why, one step back21@pytest.mark.asyncio22async def test_url_encoded_data():Drop sync (#544)Tom Christiebefore adoption206c537
line 23why, one step back23 request = httpx.Request("POST", "http://example.org", data={"test": "123"})Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc
lines 24–25why, one step back24 content = b"".join([part async for part in request.stream])25Drop sync (#544)Tom Christiebefore adoption206c537
line 26why, one step back26 assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc
line 27why, one step back27 assert content == b"test=123"Add support for SSL_CERT_FILE and SSL_CERT_DIR (#307)Can Sarıgölbefore adoptionc9810a7
lines 28–29why, one step back2829Added RequestContent (#636)Tom Christiebefore adoption8d4f182
lines 30–31why, one step back30@pytest.mark.asyncio31async def test_json_encoded_data():Drop sync (#544)Tom Christiebefore adoption206c537
line 32why, one step back32 request = httpx.Request("POST", "http://example.org", json={"test": 123})Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc
lines 33–34why, one step back33 content = b"".join([part async for part in request.stream])34Drop sync (#544)Tom Christiebefore adoption206c537
line 35why, one step back35 assert request.headers["Content-Type"] == "application/json"Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc
line 36why, one step back36 assert content == b'{"test": 123}'Add support for SSL_CERT_FILE and SSL_CERT_DIR (#307)Can Sarıgölbefore adoptionc9810a7
lines 37–39why, one step back373839def test_transfer_encoding_header():Drop sync (#544)Tom Christiebefore adoption206c537
line 40why, one step back40 async def streaming_body(data):Add support for SSL_CERT_FILE and SSL_CERT_DIR (#307)Can Sarıgölbefore adoptionc9810a7
lines 41–64why, one step back41 yield data # pragma: nocover4243 data = streaming_body(b"test 123")4445 request = httpx.Request("POST", "http://example.org", data=data)46 assert "Content-Length" not in request.headers47 assert request.headers["Transfer-Encoding"] == "chunked"484950def test_override_host_header():51 headers = {"host": "1.2.3.4:80"}5253 request = httpx.Request("GET", "http://example.org", headers=headers)54 assert request.headers["Host"] == "1.2.3.4:80"555657def test_override_accept_encoding_header():58 headers = {"Accept-Encoding": "identity"}5960 request = httpx.Request("GET", "http://example.org", headers=headers)61 assert request.headers["Accept-Encoding"] == "identity"626364def test_override_content_length_header():Drop sync (#544)Tom Christiebefore adoption206c537
line 65why, one step back65 async def streaming_body(data):Add support for SSL_CERT_FILE and SSL_CERT_DIR (#307)Can Sarıgölbefore adoptionc9810a7
lines 66–94why, one step back66 yield data # pragma: nocover6768 data = streaming_body(b"test 123")69 headers = {"Content-Length": "8"}7071 request = httpx.Request("POST", "http://example.org", data=data, headers=headers)72 assert request.headers["Content-Length"] == "8"737475def test_url():76 url = "http://example.org"77 request = httpx.Request("GET", url)78 assert request.url.scheme == "http"79 assert request.url.port == 8080 assert request.url.full_path == "/"8182 url = "https://example.org/abc?foo=bar"83 request = httpx.Request("GET", url)84 assert request.url.scheme == "https"85 assert request.url.port == 44386 assert request.url.full_path == "/abc?foo=bar"878889def test_invalid_urls():90 with pytest.raises(httpx.InvalidURL):91 httpx.Request("GET", "example.org")9293 with pytest.raises(httpx.InvalidURL):94 httpx.Request("GET", "http:///foo")