test_api.py
This file
Path
tests/test_api.py
102 lines · 2.6 KiB · Python
Last changed by
made dependencies on certifi and httpcore only load when required (#3377)Joe Marshallbefore adoptione9cabc8
History of this fileTake it
The walk stopped after 200 commits: lines older than 1250a6f point at it.
Bump uvicorn from 0.20.0 to 0.22.0 (#2691)dependabot[bot]before adoption1250a6f
lines 1–87why, one step back1import typing23import pytest45import httpx678def test_get(server):9 response = httpx.get(server.url)10 assert response.status_code == 20011 assert response.reason_phrase == "OK"12 assert response.text == "Hello, world!"13 assert response.http_version == "HTTP/1.1"141516def test_post(server):17 response = httpx.post(server.url, content=b"Hello, world!")18 assert response.status_code == 20019 assert response.reason_phrase == "OK"202122def test_post_byte_iterator(server):23 def data() -> typing.Iterator[bytes]:24 yield b"Hello"25 yield b", "26 yield b"world!"2728 response = httpx.post(server.url, content=data())29 assert response.status_code == 20030 assert response.reason_phrase == "OK"313233def test_post_byte_stream(server):34 class Data(httpx.SyncByteStream):35 def __iter__(self):36 yield b"Hello"37 yield b", "38 yield b"world!"3940 response = httpx.post(server.url, content=Data())41 assert response.status_code == 20042 assert response.reason_phrase == "OK"434445def test_options(server):46 response = httpx.options(server.url)47 assert response.status_code == 20048 assert response.reason_phrase == "OK"495051def test_head(server):52 response = httpx.head(server.url)53 assert response.status_code == 20054 assert response.reason_phrase == "OK"555657def test_put(server):58 response = httpx.put(server.url, content=b"Hello, world!")59 assert response.status_code == 20060 assert response.reason_phrase == "OK"616263def test_patch(server):64 response = httpx.patch(server.url, content=b"Hello, world!")65 assert response.status_code == 20066 assert response.reason_phrase == "OK"676869def test_delete(server):70 response = httpx.delete(server.url)71 assert response.status_code == 20072 assert response.reason_phrase == "OK"737475def test_stream(server):76 with httpx.stream("GET", server.url) as response:77 response.read()7879 assert response.status_code == 20080 assert response.reason_phrase == "OK"81 assert response.text == "Hello, world!"82 assert response.http_version == "HTTP/1.1"838485def test_get_invalid_url():86 with pytest.raises(httpx.UnsupportedProtocol):87 httpx.get("invalid://example.org")made dependencies on certifi and httpcore only load when required (#3377)Joe Marshallbefore adoptione9cabc8
lines 88–102why, one step back888990# check that httpcore isn't imported until we do a request91def test_httpcore_lazy_loading(server):92 import sys9394 # unload our module if it is already loaded95 if "httpx" in sys.modules:96 del sys.modules["httpx"]97 del sys.modules["httpcore"]98 import httpx99100 assert "httpcore" not in sys.modules101 _response = httpx.get(server.url)102 assert "httpcore" in sys.modules