test_client.py
This file
Path
tests/client/test_client.py
143 lines · 4.0 KiB · Python
Last changed by
Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
History of this fileTake it
Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 1–2why, one step back1import pytest2Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 3why, one step back3import httpxMerge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 4–5why, one step back45Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 6why, one step back6def test_get(server):Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 7why, one step back7 url = server.urlRenaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 8why, one step back8 with httpx.Client() as http:Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
line 9why, one step back9 response = http.get(url)Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 10why, one step back10 assert response.status_code == 200Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 11why, one step back11 assert response.url == urlMerge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 12why, one step back12 assert response.content == b"Hello, world!"Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 13why, one step back13 assert response.text == "Hello, world!"Response.protocol -> Response.http_version (#250)Tom Christiebefore adoptionc1ec1c3
line 14why, one step back14 assert response.http_version == "HTTP/1.1"Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
line 15why, one step back15 assert response.encoding == "iso-8859-1"Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 16why, one step back16 assert response.request.url == urlMerge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 17–18why, one step back17 assert response.headers18 assert response.is_redirect is FalseFixed response repr. (#101)updatatodaybefore adoptionf9e3ad4
line 19why, one step back19 assert repr(response) == "<Response [200 OK]>"Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 20–21why, one step back2021Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 22why, one step back22def test_post(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 23why, one step back23 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 24why, one step back24 response = http.post(server.url, data=b"Hello, world!")Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 25why, one step back25 assert response.status_code == 200Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 26why, one step back26 assert response.reason_phrase == "OK"Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 27–28why, one step back2728Add json interfacesTom Christiebefore adoption5a63d31
line 29why, one step back29def test_post_json(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 30why, one step back30 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 31why, one step back31 response = http.post(server.url, json={"text": "Hello, world!"})Add json interfacesTom Christiebefore adoption5a63d31
lines 32–35why, one step back32 assert response.status_code == 20033 assert response.reason_phrase == "OK"3435Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 36why, one step back36def test_stream_response(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 37why, one step back37 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 38why, one step back38 response = http.get(server.url, stream=True)Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 39why, one step back39 assert response.status_code == 200Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 40–41why, one step back40 content = response.read()41 assert content == b"Hello, world!"Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 42–43why, one step back4243Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 44why, one step back44def test_stream_iterator(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 45why, one step back45 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 46why, one step back46 response = http.get(server.url, stream=True)Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 47–51why, one step back47 assert response.status_code == 20048 body = b""49 for chunk in response.stream():50 body += chunk51 assert body == b"Hello, world!"Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 52why, one step back52Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 53–54why, one step back5354def test_raw_iterator(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 55why, one step back55 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 56why, one step back56 response = http.get(server.url, stream=True)Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 57–61why, one step back57 assert response.status_code == 20058 body = b""59 for chunk in response.raw():60 body += chunk61 assert body == b"Hello, world!"Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 62–65why, one step back62 response.close() # TODO: should Response be available as context managers?636465def test_raise_for_status(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 66why, one step back66 with httpx.Client() as client:Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 67–68why, one step back67 for status_code in (200, 400, 404, 500, 505):68 response = client.request(Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 69why, one step back69 "GET", server.url.copy_with(path="/status/{}".format(status_code))Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 70–71why, one step back70 )71 if 400 <= status_code < 600:Added base class HTTPError with request/response attribute (#162)halbowbefore adoption92fbe5f
line 72why, one step back72 with pytest.raises(httpx.exceptions.HTTPError) as exc_info:Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
line 73why, one step back73 response.raise_for_status()Added base class HTTPError with request/response attribute (#162)halbowbefore adoption92fbe5f
line 74why, one step back74 assert exc_info.value.response == responseMerge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 75–79why, one step back75 else:76 assert response.raise_for_status() is None777879def test_options(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 80why, one step back80 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 81why, one step back81 response = http.options(server.url)Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 82–86why, one step back82 assert response.status_code == 20083 assert response.reason_phrase == "OK"848586def test_head(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 87why, one step back87 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 88why, one step back88 response = http.head(server.url)Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 89–93why, one step back89 assert response.status_code == 20090 assert response.reason_phrase == "OK"919293def test_put(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 94why, one step back94 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 95why, one step back95 response = http.put(server.url, data=b"Hello, world!")Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 96–100why, one step back96 assert response.status_code == 20097 assert response.reason_phrase == "OK"9899100def test_patch(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 101why, one step back101 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 102why, one step back102 response = http.patch(server.url, data=b"Hello, world!")Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 103–107why, one step back103 assert response.status_code == 200104 assert response.reason_phrase == "OK"105106107def test_delete(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 108why, one step back108 with httpx.Client() as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 109why, one step back109 response = http.delete(server.url)Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 110–111why, one step back110 assert response.status_code == 200111 assert response.reason_phrase == "OK"Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
lines 112–114why, one step back112113114def test_base_url(server):Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 115why, one step back115 base_url = server.urlRenaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 116why, one step back116 with httpx.Client(base_url=base_url) as http:Handle early connection closes (#103)Tom Christiebefore adoptionb9c8a15
line 117why, one step back117 response = http.get("/")Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
line 118why, one step back118 assert response.status_code == 200Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 119why, one step back119 assert response.url == base_urlMove HSTS preload checking to client (#184)Seth Michael Larsonbefore adoption9142a89
lines 120–127why, one step back120121122def test_merge_url():123 client = httpx.Client(base_url="https://www.paypal.com/")124 url = client.merge_url("http://www.paypal.com")125126 assert url.scheme == "https"127 assert url.is_sslEnforce that sync client uses asyncio-based backend (#232)Florimond Mancabefore adoption9c7d23c
lines 128–143why, one step back128129130class DerivedFromAsyncioBackend(httpx.AsyncioBackend):131 pass132133134class AnyBackend:135 pass136137138def test_client_backend_must_be_asyncio_based():139 httpx.Client(backend=httpx.AsyncioBackend())140 httpx.Client(backend=DerivedFromAsyncioBackend())141142 with pytest.raises(ValueError):143 httpx.Client(backend=AnyBackend())