test_client.py
This file
Path
tests/client/test_client.py
155 lines · 4.4 KiB · Python
Last changed by
Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
History of this fileTake it
The walk stopped after 200 commits: lines older than fc3df51 point at it.
Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 1–7why, one step back1from datetime import timedelta23import pytest45import httpx67Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 8why, one step back8def test_get(server):Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
line 9why, one step back9 url = server.urlReintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 10–11why, one step back10 with httpx.Client() as http:11 response = http.get(url)Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 12–24why, one step back12 assert response.status_code == 20013 assert response.url == url14 assert response.content == b"Hello, world!"15 assert response.text == "Hello, world!"16 assert response.http_version == "HTTP/1.1"17 assert response.encoding == "iso-8859-1"18 assert response.request.url == url19 assert response.headers20 assert response.is_redirect is False21 assert repr(response) == "<Response [200 OK]>"22 assert response.elapsed > timedelta(0)2324Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 25why, one step back25def test_build_request(server):Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 26–28why, one step back26 url = server.url.copy_with(path="/echo_headers")27 headers = {"Custom-header": "value"}28Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 29why, one step back29 with httpx.Client() as client:Drop sync (#544)Tom Christiebefore adoption206c537
line 30why, one step back30 request = client.build_request("GET", url)Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
line 31why, one step back31 request.headers.update(headers)Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 32why, one step back32 response = client.send(request)Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 33–39why, one step back3334 assert response.status_code == 20035 assert response.url == url3637 assert response.json()["Custom-header"] == "value"3839Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 40–42why, one step back40def test_post(server):41 with httpx.Client() as client:42 response = client.post(server.url, data=b"Hello, world!")Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 43–46why, one step back43 assert response.status_code == 20044 assert response.reason_phrase == "OK"4546Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 47–49why, one step back47def test_post_json(server):48 with httpx.Client() as client:49 response = client.post(server.url, json={"text": "Hello, world!"})Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 50–53why, one step back50 assert response.status_code == 20051 assert response.reason_phrase == "OK"5253Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 54–57why, one step back54def test_stream_response(server):55 with httpx.Client() as client:56 with client.stream("GET", server.url) as response:57 content = response.read()Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 58–61why, one step back58 assert response.status_code == 20059 assert content == b"Hello, world!"6061Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 62why, one step back62def test_stream_iterator(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 63–64why, one step back63 body = b""64Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 65–67why, one step back65 with httpx.Client() as client:66 with client.stream("GET", server.url) as response:67 for chunk in response.iter_bytes():Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 68–69why, one step back68 body += chunk69Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 70–73why, one step back70 assert response.status_code == 20071 assert body == b"Hello, world!"7273Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 74why, one step back74def test_raw_iterator(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 75–76why, one step back75 body = b""76Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 77–79why, one step back77 with httpx.Client() as client:78 with client.stream("GET", server.url) as response:79 for chunk in response.iter_raw():Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 80–81why, one step back80 body += chunk81Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 82–85why, one step back82 assert response.status_code == 20083 assert body == b"Hello, world!"8485Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 86–87why, one step back86def test_raise_for_status(server):87 with httpx.Client() as client:Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
line 88why, one step back88 for status_code in (200, 400, 404, 500, 505):Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 89why, one step back89 response = client.request(Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 90–99why, one step back90 "GET", server.url.copy_with(path="/status/{}".format(status_code))91 )92 if 400 <= status_code < 600:93 with pytest.raises(httpx.HTTPError) as exc_info:94 response.raise_for_status()95 assert exc_info.value.response == response96 else:97 assert response.raise_for_status() is None9899Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 100–102why, one step back100def test_options(server):101 with httpx.Client() as client:102 response = client.options(server.url)Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 103–106why, one step back103 assert response.status_code == 200104 assert response.reason_phrase == "OK"105106Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 107–109why, one step back107def test_head(server):108 with httpx.Client() as client:109 response = client.head(server.url)Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 110–113why, one step back110 assert response.status_code == 200111 assert response.reason_phrase == "OK"112113Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 114–116why, one step back114def test_put(server):115 with httpx.Client() as client:116 response = client.put(server.url, data=b"Hello, world!")Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 117–120why, one step back117 assert response.status_code == 200118 assert response.reason_phrase == "OK"119120Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 121–123why, one step back121def test_patch(server):122 with httpx.Client() as client:123 response = client.patch(server.url, data=b"Hello, world!")Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 124–127why, one step back124 assert response.status_code == 200125 assert response.reason_phrase == "OK"126127Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 128–130why, one step back128def test_delete(server):129 with httpx.Client() as client:130 response = client.delete(server.url)Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 131–134why, one step back131 assert response.status_code == 200132 assert response.reason_phrase == "OK"133134Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 135why, one step back135def test_base_url(server):Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
line 136why, one step back136 base_url = server.urlReintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 137–138why, one step back137 with httpx.Client(base_url=base_url) as client:138 response = client.get("/")Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 139–143why, one step back139 assert response.status_code == 200140 assert response.url == base_url141142143def test_merge_url():Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 144why, one step back144 client = httpx.Client(base_url="https://www.paypal.com/")Don't check trio import in definition of backend fixture params (#447)Florimond Mancabefore adoptionfc3df51
lines 145–150why, one step back145 url = client.merge_url("http://www.paypal.com")146147 assert url.scheme == "https"148 assert url.is_ssl149150Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 151why, one step back151def test_elapsed_delay(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 152why, one step back152 url = server.url.copy_with(path="/slow_response/100")Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 153–154why, one step back153 with httpx.Client() as client:154 response = client.get(url)Trivial-case test for response.elapsedTom Christiebefore adoption02d16bf
line 155why, one step back155 assert response.elapsed.total_seconds() > 0.0