Skip to content
Myr

test_requests.py

This file

Path

tests/test_requests.py

92 lines · 2.5 KiB · Python

Last changed by

Exclude unused code linesTom Christiebefore adoptionee6f42a

History of this file

Take it

Add auto headers on RequestTom Christiebefore adoption042dd22

lines 1–24why, one step back
1import pytest
23import httpcore456def test_host_header():7 request = httpcore.Request("GET", "http://example.org")8 assert request.headers == [9 (b"host", b"example.org"),10 (b"accept-encoding", b"deflate, gzip, br"),11 ]121314def test_content_length_header():15 request = httpcore.Request("POST", "http://example.org", body=b"test 123")16 assert request.headers == [17 (b"host", b"example.org"),18 (b"content-length", b"8"),19 (b"accept-encoding", b"deflate, gzip, br"),20 ]212223def test_transfer_encoding_header():24 async def streaming_body(data):

Exclude unused code linesTom Christiebefore adoptionee6f42a

line 25why, one step back
25 yield data # pragma: nocover

Add auto headers on RequestTom Christiebefore adoption042dd22

lines 26–58why, one step back
26
27 body = streaming_body(b"test 123")2829 request = httpcore.Request("POST", "http://example.org", body=body)30 assert request.headers == [31 (b"host", b"example.org"),32 (b"transfer-encoding", b"chunked"),33 (b"accept-encoding", b"deflate, gzip, br"),34 ]353637def test_override_host_header():38 headers = [(b"host", b"1.2.3.4:80")]3940 request = httpcore.Request("GET", "http://example.org", headers=headers)41 assert request.headers == [42 (b"accept-encoding", b"deflate, gzip, br"),43 (b"host", b"1.2.3.4:80"),44 ]454647def test_override_accept_encoding_header():48 headers = [(b"accept-encoding", b"identity")]4950 request = httpcore.Request("GET", "http://example.org", headers=headers)51 assert request.headers == [52 (b"host", b"example.org"),53 (b"accept-encoding", b"identity"),54 ]555657def test_override_content_length_header():58 async def streaming_body(data):

Exclude unused code linesTom Christiebefore adoptionee6f42a

line 59why, one step back
59 yield data # pragma: nocover

Add auto headers on RequestTom Christiebefore adoption042dd22

lines 60–92why, one step back
60
61 body = streaming_body(b"test 123")62 headers = [(b"content-length", b"8")]6364 request = httpcore.Request("POST", "http://example.org", body=body, headers=headers)65 assert request.headers == [66 (b"host", b"example.org"),67 (b"accept-encoding", b"deflate, gzip, br"),68 (b"content-length", b"8"),69 ]707172def test_url():73 request = httpcore.Request("GET", "http://example.org")74 assert request.url.scheme == "http"75 assert request.url.port == 8076 assert request.url.target == "/"7778 request = httpcore.Request("GET", "https://example.org/abc?foo=bar")79 assert request.url.scheme == "https"80 assert request.url.port == 44381 assert request.url.target == "/abc?foo=bar"828384def test_invalid_urls():85 with pytest.raises(ValueError):86 httpcore.Request("GET", "example.org")8788 with pytest.raises(ValueError):89 httpcore.Request("GET", "invalid://example.org")9091 with pytest.raises(ValueError):92 httpcore.Request("GET", "http:///foo")