Skip to content
Myr

test_requests.py

This file

Path

tests/models/test_requests.py

88 lines · 2.6 KiB · Python

Last changed by

Drop sync (#544)Tom Christiebefore adoption206c537

History of this file

Take it

The walk stopped after 200 commits: lines older than 20cb8af point at it.

Travis sudo no longer required for Xenial (#266)Hugo van Kemenadebefore adoption20cb8af

lines 1–21why, 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"192021def test_url_encoded_data():

Drop sync (#544)Tom Christiebefore adoption206c537

lines 22–24why, one step back
22 request = httpx.Request("POST", "http://example.org", data={"test": "123"})
23 assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"24 assert request.content == b"test=123"

Travis sudo no longer required for Xenial (#266)Hugo van Kemenadebefore adoption20cb8af

lines 25–27why, one step back
25
2627def test_json_encoded_data():

Drop sync (#544)Tom Christiebefore adoption206c537

lines 28–30why, one step back
28 request = httpx.Request("POST", "http://example.org", json={"test": 123})
29 assert request.headers["Content-Type"] == "application/json"30 assert request.content == b'{"test": 123}'

Travis sudo no longer required for Xenial (#266)Hugo van Kemenadebefore adoption20cb8af

lines 31–33why, one step back
31
3233def test_transfer_encoding_header():

Drop sync (#544)Tom Christiebefore adoption206c537

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

Travis sudo no longer required for Xenial (#266)Hugo van Kemenadebefore adoption20cb8af

lines 35–58why, one step back
35 yield data # pragma: nocover
3637 data = streaming_body(b"test 123")3839 request = httpx.Request("POST", "http://example.org", data=data)40 assert "Content-Length" not in request.headers41 assert request.headers["Transfer-Encoding"] == "chunked"424344def test_override_host_header():45 headers = {"host": "1.2.3.4:80"}4647 request = httpx.Request("GET", "http://example.org", headers=headers)48 assert request.headers["Host"] == "1.2.3.4:80"495051def test_override_accept_encoding_header():52 headers = {"Accept-Encoding": "identity"}5354 request = httpx.Request("GET", "http://example.org", headers=headers)55 assert request.headers["Accept-Encoding"] == "identity"565758def test_override_content_length_header():

Drop sync (#544)Tom Christiebefore adoption206c537

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

Travis sudo no longer required for Xenial (#266)Hugo van Kemenadebefore adoption20cb8af

lines 60–88why, one step back
60 yield data # pragma: nocover
6162 data = streaming_body(b"test 123")63 headers = {"Content-Length": "8"}6465 request = httpx.Request("POST", "http://example.org", data=data, headers=headers)66 assert request.headers["Content-Length"] == "8"676869def test_url():70 url = "http://example.org"71 request = httpx.Request("GET", url)72 assert request.url.scheme == "http"73 assert request.url.port == 8074 assert request.url.full_path == "/"7576 url = "https://example.org/abc?foo=bar"77 request = httpx.Request("GET", url)78 assert request.url.scheme == "https"79 assert request.url.port == 44380 assert request.url.full_path == "/abc?foo=bar"818283def test_invalid_urls():84 with pytest.raises(httpx.InvalidURL):85 httpx.Request("GET", "example.org")8687 with pytest.raises(httpx.InvalidURL):88 httpx.Request("GET", "http:///foo")