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 0e8dae4 point at it.

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 1–2why, one step back
1import pytest
2

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 3why, one step back
3import httpx

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 4–6why, one step back
4
56def test_request_repr():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 7why, one step back
7 request = httpx.Request("GET", "http://example.org")

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 8–11why, one step back
8 assert repr(request) == "<Request('GET', 'http://example.org')>"
91011def test_no_content():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 12why, one step back
12 request = httpx.Request("GET", "http://example.org")

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 13–16why, one step back
13 assert "Content-Length" not in request.headers
141516def test_content_length_header():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 18–21why, one step back
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"

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

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}'

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

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):

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 35–38why, one step back
35 yield data # pragma: nocover
3637 data = streaming_body(b"test 123")38

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 39why, one step back
39 request = httpx.Request("POST", "http://example.org", data=data)

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 40–46why, one step back
40 assert "Content-Length" not in request.headers
41 assert request.headers["Transfer-Encoding"] == "chunked"424344def test_override_host_header():45 headers = {"host": "1.2.3.4:80"}46

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 47why, one step back
47 request = httpx.Request("GET", "http://example.org", headers=headers)

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 48–53why, one step back
48 assert request.headers["Host"] == "1.2.3.4:80"
495051def test_override_accept_encoding_header():52 headers = {"Accept-Encoding": "identity"}53

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 54why, one step back
54 request = httpx.Request("GET", "http://example.org", headers=headers)

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 55–58why, one step back
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):

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 60–64why, one step back
60 yield data # pragma: nocover
6162 data = streaming_body(b"test 123")63 headers = {"Content-Length": "8"}64

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 65why, one step back
65 request = httpx.Request("POST", "http://example.org", data=data, headers=headers)

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 66–70why, one step back
66 assert request.headers["Content-Length"] == "8"
676869def test_url():70 url = "http://example.org"

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 71why, one step back
71 request = httpx.Request("GET", url)

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 72–76why, one step back
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"

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 77why, one step back
77 request = httpx.Request("GET", url)

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

lines 78–83why, one step back
78 assert request.url.scheme == "https"
79 assert request.url.port == 44380 assert request.url.full_path == "/abc?foo=bar"818283def test_invalid_urls():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 84–85why, one step back
84 with pytest.raises(httpx.InvalidURL):
85 httpx.Request("GET", "example.org")

Multipart data values encoding (#121)ambrozicbefore adoption0e8dae4

line 86why, one step back
86

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 87–88why, one step back
87 with pytest.raises(httpx.InvalidURL):
88 httpx.Request("GET", "http:///foo")