test_headers.py
This file
Path
tests/client/test_headers.py
187 lines · 5.5 KiB · Python
Last changed by
Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941
History of this fileTake it
The walk stopped after 200 commits: lines older than 991915a point at it.
Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 1–4why, one step back1#!/usr/bin/env python323import pytest4Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 5why, one step back5import httpxRefactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 6why, one step back6from tests.utils import MockTransportRename pool limit options (#968)Tom Christiebefore adoption991915a
lines 7–8why, one step back78Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 9–10why, one step back9def echo_headers(request: httpx.Request) -> httpx.Response:10 data = {"headers": dict(request.headers)}Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941
line 11why, one step back11 return httpx.Response(200, json=data)Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 12–13why, one step back1213Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 14why, one step back14def test_client_header():Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 15–20why, one step back15 """16 Set a header in the Client.17 """18 url = "http://example.org/echo_headers"19 headers = {"Example-Header": "example-value"}20Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 21why, one step back21 client = httpx.Client(transport=MockTransport(echo_headers), headers=headers)Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 22why, one step back22 response = client.get(url)Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 23–31why, one step back2324 assert response.status_code == 20025 assert response.json() == {26 "headers": {27 "accept": "*/*",28 "accept-encoding": "gzip, deflate, br",29 "connection": "keep-alive",30 "example-header": "example-value",31 "host": "example.org",Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 32why, one step back32 "user-agent": f"python-httpx/{httpx.__version__}",Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 33–36why, one step back33 }34 }3536Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 37why, one step back37def test_header_merge():Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 38–40why, one step back38 url = "http://example.org/echo_headers"39 client_headers = {"User-Agent": "python-myclient/0.2.1"}40 request_headers = {"X-Auth-Token": "FooBarBazToken"}Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 41why, one step back41 client = httpx.Client(transport=MockTransport(echo_headers), headers=client_headers)Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 42why, one step back42 response = client.get(url, headers=request_headers)Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 43–56why, one step back4344 assert response.status_code == 20045 assert response.json() == {46 "headers": {47 "accept": "*/*",48 "accept-encoding": "gzip, deflate, br",49 "connection": "keep-alive",50 "host": "example.org",51 "user-agent": "python-myclient/0.2.1",52 "x-auth-token": "FooBarBazToken",53 }54 }5556Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 57why, one step back57def test_header_merge_conflicting_headers():Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 58–60why, one step back58 url = "http://example.org/echo_headers"59 client_headers = {"X-Auth-Token": "FooBar"}60 request_headers = {"X-Auth-Token": "BazToken"}Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 61why, one step back61 client = httpx.Client(transport=MockTransport(echo_headers), headers=client_headers)Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 62why, one step back62 response = client.get(url, headers=request_headers)Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 63–70why, one step back6364 assert response.status_code == 20065 assert response.json() == {66 "headers": {67 "accept": "*/*",68 "accept-encoding": "gzip, deflate, br",69 "connection": "keep-alive",70 "host": "example.org",Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 71why, one step back71 "user-agent": f"python-httpx/{httpx.__version__}",Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 72–76why, one step back72 "x-auth-token": "BazToken",73 }74 }7576Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 77why, one step back77def test_header_update():Rename pool limit options (#968)Tom Christiebefore adoption991915a
line 78why, one step back78 url = "http://example.org/echo_headers"Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 79why, one step back79 client = httpx.Client(transport=MockTransport(echo_headers))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 80why, one step back80 first_response = client.get(url)Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 81–83why, one step back81 client.headers.update(82 {"User-Agent": "python-myclient/0.2.1", "Another-Header": "AThing"}83 )Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 84why, one step back84 second_response = client.get(url)Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 85–92why, one step back8586 assert first_response.status_code == 20087 assert first_response.json() == {88 "headers": {89 "accept": "*/*",90 "accept-encoding": "gzip, deflate, br",91 "connection": "keep-alive",92 "host": "example.org",Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 93why, one step back93 "user-agent": f"python-httpx/{httpx.__version__}",Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 94–109why, one step back94 }95 }9697 assert second_response.status_code == 20098 assert second_response.json() == {99 "headers": {100 "accept": "*/*",101 "accept-encoding": "gzip, deflate, br",102 "another-header": "AThing",103 "connection": "keep-alive",104 "host": "example.org",105 "user-agent": "python-myclient/0.2.1",106 }107 }108109Header refinements (#1248)Tom Christiebefore adoption19b863a
lines 110–115why, one step back110def test_remove_default_header():111 """112 Remove a default header from the Client.113 """114 url = "http://example.org/echo_headers"115Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 116why, one step back116 client = httpx.Client(transport=MockTransport(echo_headers))Header refinements (#1248)Tom Christiebefore adoption19b863a
lines 117–131why, one step back117 del client.headers["User-Agent"]118119 response = client.get(url)120121 assert response.status_code == 200122 assert response.json() == {123 "headers": {124 "accept": "*/*",125 "accept-encoding": "gzip, deflate, br",126 "connection": "keep-alive",127 "host": "example.org",128 }129 }130131Rename pool limit options (#968)Tom Christiebefore adoption991915a
line 132why, one step back132def test_header_does_not_exist():Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 133why, one step back133 headers = httpx.Headers({"foo": "bar"})Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 134–137why, one step back134 with pytest.raises(KeyError):135 del headers["baz"]136137Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 138why, one step back138def test_host_with_auth_and_port_in_url():Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 139–145why, one step back139 """140 The Host header should only include the hostname, or hostname:port141 (for non-default ports only). Any userinfo or default port should not142 be present.143 """144 url = "http://username:password@example.org:80/echo_headers"145Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 146why, one step back146 client = httpx.Client(transport=MockTransport(echo_headers))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 147why, one step back147 response = client.get(url)Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 148–155why, one step back148149 assert response.status_code == 200150 assert response.json() == {151 "headers": {152 "accept": "*/*",153 "accept-encoding": "gzip, deflate, br",154 "connection": "keep-alive",155 "host": "example.org",Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 156why, one step back156 "user-agent": f"python-httpx/{httpx.__version__}",Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 157–161why, one step back157 "authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",158 }159 }160161Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 162why, one step back162def test_host_with_non_default_port_in_url():Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 163–168why, one step back163 """164 If the URL includes a non-default port, then it should be included in165 the Host header.166 """167 url = "http://username:password@example.org:123/echo_headers"168Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 169why, one step back169 client = httpx.Client(transport=MockTransport(echo_headers))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 170why, one step back170 response = client.get(url)Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 171–178why, one step back171172 assert response.status_code == 200173 assert response.json() == {174 "headers": {175 "accept": "*/*",176 "accept-encoding": "gzip, deflate, br",177 "connection": "keep-alive",178 "host": "example.org:123",Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 179why, one step back179 "user-agent": f"python-httpx/{httpx.__version__}",Rename pool limit options (#968)Tom Christiebefore adoption991915a
lines 180–182why, one step back180 "authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",181 }182 }Fix request auto headers (#1205)Tom Christiebefore adoption19515e8
lines 183–185why, one step back183184185def test_request_auto_headers():Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 186why, one step back186 request = httpx.Request("GET", "https://www.example.org/")Fix request auto headers (#1205)Tom Christiebefore adoption19515e8
line 187why, one step back187 assert "host" in request.headers