test_requests.py
This file
Path
tests/models/test_requests.py
118 lines · 3.3 KiB · Python
Last changed by
Drop Host header for HTTP/2 (#82)Tom Christiebefore adoption76bc6c6
History of this fileTake it
Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 1–5why, one step back1import pytest23import httpcore45Increase test coverageTom Christiebefore adoptione99ffbd
lines 6–10why, one step back6def test_request_repr():7 request = httpcore.Request("GET", "http://example.org")8 assert repr(request) == "<Request('GET', 'http://example.org')>"910Drop Host header for HTTP/2 (#82)Tom Christiebefore adoption76bc6c6
line 11why, one step back11def test_no_content():Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 12–14why, one step back12 request = httpcore.Request("GET", "http://example.org")13 request.prepare()14 assert request.headers == httpcore.Headers(Drop Host header for HTTP/2 (#82)Tom Christiebefore adoption76bc6c6
line 15why, one step back15 [(b"accept-encoding", b"deflate, gzip, br")]Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 16–19why, one step back16 )171819def test_content_length_header():Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 20why, one step back20 request = httpcore.Request("POST", "http://example.org", data=b"test 123")Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 21–29why, one step back21 request.prepare()22 assert request.headers == httpcore.Headers(23 [24 (b"content-length", b"8"),25 (b"accept-encoding", b"deflate, gzip, br"),26 ]27 )2829Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
lines 30–42why, one step back30def test_url_encoded_data():31 request = httpcore.Request("POST", "http://example.org", data={"test": "123"})32 request.prepare()33 assert request.headers == httpcore.Headers(34 [35 (b"content-length", b"8"),36 (b"accept-encoding", b"deflate, gzip, br"),37 (b"content-type", b"application/x-www-form-urlencoded"),38 ]39 )40 assert request.content == b"test=123"4142Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 43–46why, one step back43def test_transfer_encoding_header():44 async def streaming_body(data):45 yield data # pragma: nocover46Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 47why, one step back47 data = streaming_body(b"test 123")Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 48why, one step back48Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 49why, one step back49 request = httpcore.Request("POST", "http://example.org", data=data)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 50–74why, one step back50 request.prepare()51 assert request.headers == httpcore.Headers(52 [53 (b"transfer-encoding", b"chunked"),54 (b"accept-encoding", b"deflate, gzip, br"),55 ]56 )575859def test_override_host_header():60 headers = [(b"host", b"1.2.3.4:80")]6162 request = httpcore.Request("GET", "http://example.org", headers=headers)63 request.prepare()64 assert request.headers == httpcore.Headers(65 [(b"accept-encoding", b"deflate, gzip, br"), (b"host", b"1.2.3.4:80")]66 )676869def test_override_accept_encoding_header():70 headers = [(b"accept-encoding", b"identity")]7172 request = httpcore.Request("GET", "http://example.org", headers=headers)73 request.prepare()74 assert request.headers == httpcore.Headers(Drop Host header for HTTP/2 (#82)Tom Christiebefore adoption76bc6c6
line 75why, one step back75 [(b"accept-encoding", b"identity")]Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 76–82why, one step back76 )777879def test_override_content_length_header():80 async def streaming_body(data):81 yield data # pragma: nocover82Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 83why, one step back83 data = streaming_body(b"test 123")Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 84–85why, one step back84 headers = [(b"content-length", b"8")]85Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 86why, one step back86 request = httpcore.Request("POST", "http://example.org", data=data, headers=headers)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 87–96why, one step back87 request.prepare()88 assert request.headers == httpcore.Headers(89 [90 (b"accept-encoding", b"deflate, gzip, br"),91 (b"content-length", b"8"),92 ]93 )949596def test_url():Include URL.__hash__ in test (#64)Yeray Diaz Diazbefore adoption2e9ab2e
lines 97–98why, one step back97 url = "http://example.org"98 request = httpcore.Request("GET", url)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 99–102why, one step back99 assert request.url.scheme == "http"100 assert request.url.port == 80101 assert request.url.full_path == "/"102Include URL.__hash__ in test (#64)Yeray Diaz Diazbefore adoption2e9ab2e
lines 103–104why, one step back103 url = "https://example.org/abc?foo=bar"104 request = httpcore.Request("GET", url)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 105–110why, one step back105 assert request.url.scheme == "https"106 assert request.url.port == 443107 assert request.url.full_path == "/abc?foo=bar"108109110def test_invalid_urls():Use rfc3986 for URL handlingTom Christiebefore adoption302fe93
line 111why, one step back111 with pytest.raises(httpcore.InvalidURL):Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 112–113why, one step back112 httpcore.Request("GET", "example.org")113Use rfc3986 for URL handlingTom Christiebefore adoption302fe93
line 114why, one step back114 with pytest.raises(httpcore.InvalidURL):Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 115–116why, one step back115 httpcore.Request("GET", "invalid://example.org")116Use rfc3986 for URL handlingTom Christiebefore adoption302fe93
line 117why, one step back117 with pytest.raises(httpcore.InvalidURL):Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 118why, one step back118 httpcore.Request("GET", "http:///foo")