Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

85 lines · 2.1 KiB · Python

Last changed by

Fix for stream uploads that subclass SyncByteStream/AsyncByteStream (#2016)Tom Christiebefore adoptionb7dc0c3

History of this file

Take it

1import pytest23import httpx456def test_get(server):7    response = httpx.get(server.url)8    assert response.status_code == 2009    assert response.reason_phrase == "OK"10    assert response.text == "Hello, world!"11    assert response.http_version == "HTTP/1.1"121314def test_post(server):15    response = httpx.post(server.url, content=b"Hello, world!")16    assert response.status_code == 20017    assert response.reason_phrase == "OK"181920def test_post_byte_iterator(server):21    def data():22        yield b"Hello"23        yield b", "24        yield b"world!"2526    response = httpx.post(server.url, content=data())27    assert response.status_code == 20028    assert response.reason_phrase == "OK"293031def test_post_byte_stream(server):32    class Data(httpx.SyncByteStream):33        def __iter__(self):34            yield b"Hello"35            yield b", "36            yield b"world!"3738    response = httpx.post(server.url, content=Data())39    assert response.status_code == 20040    assert response.reason_phrase == "OK"414243def test_options(server):44    response = httpx.options(server.url)45    assert response.status_code == 20046    assert response.reason_phrase == "OK"474849def test_head(server):50    response = httpx.head(server.url)51    assert response.status_code == 20052    assert response.reason_phrase == "OK"535455def test_put(server):56    response = httpx.put(server.url, content=b"Hello, world!")57    assert response.status_code == 20058    assert response.reason_phrase == "OK"596061def test_patch(server):62    response = httpx.patch(server.url, content=b"Hello, world!")63    assert response.status_code == 20064    assert response.reason_phrase == "OK"656667def test_delete(server):68    response = httpx.delete(server.url)69    assert response.status_code == 20070    assert response.reason_phrase == "OK"717273def test_stream(server):74    with httpx.stream("GET", server.url) as response:75        response.read()7677    assert response.status_code == 20078    assert response.reason_phrase == "OK"79    assert response.text == "Hello, world!"80    assert response.http_version == "HTTP/1.1"818283def test_get_invalid_url():84    with pytest.raises(httpx.UnsupportedProtocol):85        httpx.get("invalid://example.org")