httpx/tests/test_api.py
Tom Christie feb404f86b
Seperate content=... and data=... parameters (#1266)
* Seperate content=... and data=... parameters

* Update compatibility.md
2020-09-15 13:36:10 +01:00

74 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, content=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, content=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, content=b"Hello, world!")
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_patch(server):
response = httpx.patch(server.url, content=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"
def test_get_invalid_url():
with pytest.raises(httpx.UnsupportedProtocol):
httpx.get("invalid://example.org")