Skip to content
Myr

test_requests.py

This file

Path

tests/models/test_requests.py

112 lines · 3.6 KiB · Python

Last changed by

URL.port becomes Optional[int] (#1080)Tom Christiebefore adoptionc089480

History of this file

Take it

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

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

lines 1–12why, 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")

Revert "Add content-length header for empty bytestream (#866)" (#898)Tom Christiebefore adoption631ba97

line 13why, one step back
13 assert "Content-Length" not in request.headers

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

lines 14–20why, one step back
14
1516def test_content_length_header():17 request = httpx.Request("POST", "http://example.org", data=b"test 123")18 assert request.headers["Content-Length"] == "8"1920

Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76

line 21why, one step back
21def test_url_encoded_data():

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

line 22why, one step back
22 request = httpx.Request("POST", "http://example.org", data={"test": "123"})

Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76

line 23why, one step back
23 request.read()

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

lines 24–25why, one step back
24
25 assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"

Public Auth API (#732)Tom Christiebefore adoption12dd157

line 26why, one step back
26 assert request.content == b"test=123"

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

lines 27–28why, one step back
27
28

Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76

line 29why, one step back
29def test_json_encoded_data():

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

line 30why, one step back
30 request = httpx.Request("POST", "http://example.org", json={"test": 123})

Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76

line 31why, one step back
31 request.read()

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

lines 32–33why, one step back
32
33 assert request.headers["Content-Type"] == "application/json"

Public Auth API (#732)Tom Christiebefore adoption12dd157

lines 34–36why, one step back
34 assert request.content == b'{"test": 123}'
3536

Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76

lines 37–45why, one step back
37def test_read_and_stream_data():
38 # Ensure a request may still be streamed if it has been read.39 # Needed for cases such as authentication classes that read the request body.40 request = httpx.Request("POST", "http://example.org", json={"test": 123})41 request.read()42 content = b"".join([part for part in request.stream])43 assert content == request.content4445

Public Auth API (#732)Tom Christiebefore adoption12dd157

line 46why, one step back
46@pytest.mark.asyncio

Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76

line 47why, one step back
47async def test_aread_and_stream_data():

Public Auth API (#732)Tom Christiebefore adoption12dd157

lines 48–62why, one step back
48 # Ensure a request may still be streamed if it has been read.
49 # Needed for cases such as authentication classes that read the request body.50 request = httpx.Request("POST", "http://example.org", json={"test": 123})51 await request.aread()52 content = b"".join([part async for part in request.stream])53 assert content == request.content545556@pytest.mark.asyncio57async def test_cannot_access_content_without_read():58 # Ensure a request may still be streamed if it has been read.59 #  Needed for cases such as authentication classes that read the request body.60 request = httpx.Request("POST", "http://example.org", json={"test": 123})61 with pytest.raises(httpx.RequestNotRead):62 request.content

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

lines 63–104why, one step back
63
6465def test_transfer_encoding_header():66 async def streaming_body(data):67 yield data # pragma: nocover6869 data = streaming_body(b"test 123")7071 request = httpx.Request("POST", "http://example.org", data=data)72 assert "Content-Length" not in request.headers73 assert request.headers["Transfer-Encoding"] == "chunked"747576def test_override_host_header():77 headers = {"host": "1.2.3.4:80"}7879 request = httpx.Request("GET", "http://example.org", headers=headers)80 assert request.headers["Host"] == "1.2.3.4:80"818283def test_override_accept_encoding_header():84 headers = {"Accept-Encoding": "identity"}8586 request = httpx.Request("GET", "http://example.org", headers=headers)87 assert request.headers["Accept-Encoding"] == "identity"888990def test_override_content_length_header():91 async def streaming_body(data):92 yield data # pragma: nocover9394 data = streaming_body(b"test 123")95 headers = {"Content-Length": "8"}9697 request = httpx.Request("POST", "http://example.org", data=data, headers=headers)98 assert request.headers["Content-Length"] == "8"99100101def test_url():102 url = "http://example.org"103 request = httpx.Request("GET", url)104 assert request.url.scheme == "http"

URL.port becomes Optional[int] (#1080)Tom Christiebefore adoptionc089480

line 105why, one step back
105 assert request.url.port is None

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

lines 106–110why, one step back
106 assert request.url.full_path == "/"
107108 url = "https://example.org/abc?foo=bar"109 request = httpx.Request("GET", url)110 assert request.url.scheme == "https"

URL.port becomes Optional[int] (#1080)Tom Christiebefore adoptionc089480

line 111why, one step back
111 assert request.url.port is None

Drop `Origin` from public API (#688)Andrés Álvarezbefore adoption2b92a78

line 112why, one step back
112 assert request.url.full_path == "/abc?foo=bar"