httpx/tests/test_api.py
Tom Christie ee37a762ef
Reintroduce sync API. (#735)
* BaseClient and AsyncClient

* Introduce 'httpx.Client'

* Top level API -> sync

* Top level API -> sync

* Add WSGI support, drop deprecated imports

* Wire up timeouts to urllib3

* Wire up pool_limits

* Add urllib3 proxy support

* Pull #734 into sync Client

* Update AsyncClient docstring

* Simpler WSGI implementation

* Set body=None when no content

* Wrap urllib3 connection/read exceptions
2020-01-08 12:31:50 +00:00

75 lines
1.8 KiB
Python

import pytest
import httpx
def test_get(server):
response = httpx.get(server.url)
assert response.status_code == 200
assert response.reason_phrase == "OK"
assert response.text == "Hello, world!"
assert response.http_version == "HTTP/1.1"
def test_post(server):
response = httpx.post(server.url, data=b"Hello, world!")
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_post_byte_iterator(server):
def data():
yield b"Hello"
yield b", "
yield b"world!"
response = httpx.post(server.url, data=data())
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_options(server):
response = httpx.options(server.url)
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_head(server):
response = httpx.head(server.url)
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_put(server):
response = httpx.put(server.url, data=b"Hello, world!")
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_patch(server):
response = httpx.patch(server.url, data=b"Hello, world!")
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_delete(server):
response = httpx.delete(server.url)
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_stream(server):
with httpx.stream("GET", server.url) as response:
response.read()
assert response.status_code == 200
assert response.reason_phrase == "OK"
assert response.text == "Hello, world!"
assert response.http_version == "HTTP/1.1"
@pytest.mark.asyncio
async def test_get_invalid_url(server):
with pytest.raises(httpx.InvalidURL):
await httpx.get("invalid://example.org")