Skip to content
Myr

test_requests.py

This file

Path

tests/models/test_requests.py

90 lines · 2.7 KiB · Python

Last changed by

Added RequestContent (#636)Tom Christiebefore adoption8d4f182

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–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

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

Added RequestContent (#636)Tom Christiebefore adoption8d4f182

line 25why, one step back
25 assert await request.content.aread() == b"test=123"

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

lines 26–27why, one step back
26
27

Added RequestContent (#636)Tom Christiebefore adoption8d4f182

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

Drop sync (#544)Tom Christiebefore adoption206c537

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

Added RequestContent (#636)Tom Christiebefore adoption8d4f182

line 32why, one step back
32 assert await request.content.aread() == b'{"test": 123}'

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

lines 33–35why, one step back
33
3435def test_transfer_encoding_header():

Drop sync (#544)Tom Christiebefore adoption206c537

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

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

lines 37–60why, one step back
37 yield data # pragma: nocover
3839 data = streaming_body(b"test 123")4041 request = httpx.Request("POST", "http://example.org", data=data)42 assert "Content-Length" not in request.headers43 assert request.headers["Transfer-Encoding"] == "chunked"444546def test_override_host_header():47 headers = {"host": "1.2.3.4:80"}4849 request = httpx.Request("GET", "http://example.org", headers=headers)50 assert request.headers["Host"] == "1.2.3.4:80"515253def test_override_accept_encoding_header():54 headers = {"Accept-Encoding": "identity"}5556 request = httpx.Request("GET", "http://example.org", headers=headers)57 assert request.headers["Accept-Encoding"] == "identity"585960def test_override_content_length_header():

Drop sync (#544)Tom Christiebefore adoption206c537

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

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

lines 62–90why, one step back
62 yield data # pragma: nocover
6364 data = streaming_body(b"test 123")65 headers = {"Content-Length": "8"}6667 request = httpx.Request("POST", "http://example.org", data=data, headers=headers)68 assert request.headers["Content-Length"] == "8"697071def test_url():72 url = "http://example.org"73 request = httpx.Request("GET", url)74 assert request.url.scheme == "http"75 assert request.url.port == 8076 assert request.url.full_path == "/"7778 url = "https://example.org/abc?foo=bar"79 request = httpx.Request("GET", url)80 assert request.url.scheme == "https"81 assert request.url.port == 44382 assert request.url.full_path == "/abc?foo=bar"838485def test_invalid_urls():86 with pytest.raises(httpx.InvalidURL):87 httpx.Request("GET", "example.org")8889 with pytest.raises(httpx.InvalidURL):90 httpx.Request("GET", "http:///foo")