Skip to content
Myr

test_requests.py

This file

Path

tests/models/test_requests.py

90 lines · 2.7 KiB · Python

Last changed by

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

History of this file

Take it

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 3why, one step back
3import httpx

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

lines 18–21why, one step back
18 assert request.headers["Content-Length"] == "8"
192021def test_url_encoded_data():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 22why, one step back
22 for RequestClass in (httpx.Request, httpx.AsyncRequest):

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 29why, one step back
29 for RequestClass in (httpx.Request, httpx.AsyncRequest):

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

lines 30–40why, one step back
30 request = RequestClass("POST", "http://example.org", json={"test": 123})
31 assert request.headers["Content-Type"] == "application/json"32 assert request.content == b'{"test": 123}'333435def test_transfer_encoding_header():36 def streaming_body(data):37 yield data # pragma: nocover3839 data = streaming_body(b"test 123")40

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

lines 42–48why, one step back
42 assert "Content-Length" not in request.headers
43 assert request.headers["Transfer-Encoding"] == "chunked"444546def test_override_host_header():47 headers = {"host": "1.2.3.4:80"}48

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

lines 50–55why, one step back
50 assert request.headers["Host"] == "1.2.3.4:80"
515253def test_override_accept_encoding_header():54 headers = {"Accept-Encoding": "identity"}55

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

lines 57–66why, one step back
57 assert request.headers["Accept-Encoding"] == "identity"
585960def test_override_content_length_header():61 def streaming_body(data):62 yield data # pragma: nocover6364 data = streaming_body(b"test 123")65 headers = {"Content-Length": "8"}66

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

lines 80–85why, one step back
80 assert request.url.scheme == "https"
81 assert request.url.port == 44382 assert request.url.full_path == "/abc?foo=bar"838485def test_invalid_urls():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Read/Write timeout modes (#104)Tom Christiebefore adoptionf4f05e3

line 88why, one step back
88

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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