Skip to content
Myr

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 file

Take it

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

Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb

lines 1–20why, one step back
1import pytest
23import 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"1920

Added RequestContent (#636)Tom Christiebefore adoption8d4f182

lines 21–22why, one step back
21@pytest.mark.asyncio
22async def test_url_encoded_data():

Drop sync (#544)Tom Christiebefore adoption206c537

line 23why, one step back
23 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 back
24 content = b"".join([part async for part in request.stream])
25

Drop sync (#544)Tom Christiebefore adoption206c537

line 26why, one step back
26 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 back
27 assert content == b"test=123"

Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb

lines 28–29why, one step back
28
29

Added RequestContent (#636)Tom Christiebefore adoption8d4f182

lines 30–31why, one step back
30@pytest.mark.asyncio
31async def test_json_encoded_data():

Drop sync (#544)Tom Christiebefore adoption206c537

line 32why, one step back
32 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 back
33 content = b"".join([part async for part in request.stream])
34

Drop sync (#544)Tom Christiebefore adoption206c537

line 35why, one step back
35 assert request.headers["Content-Type"] == "application/json"

Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc

line 36why, one step back
36 assert content == b'{"test": 123}'

Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb

lines 37–39why, one step back
37
3839def test_transfer_encoding_header():

Drop sync (#544)Tom Christiebefore adoption206c537

line 40why, one step back
40 async def streaming_body(data):

Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb

lines 41–64why, one step back
41 yield data # pragma: nocover
4243 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 back
65 async def streaming_body(data):

Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb

lines 66–94why, one step back
66 yield data # pragma: nocover
6768 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")