Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

87 lines · 2.2 KiB · Python

Last changed by

Not known.

History of this file

Take it

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