response = await client.get(url)
assert response.status_code == 200
assert response.text == "Hello, world!"
+ assert response.protocol == "HTTP/1.1"
+ assert response.headers
+ assert repr(response) == "<Response(200, 'OK')>"
@pytest.mark.asyncio
response.raise_for_status()
else:
assert response.raise_for_status() is None
+
+
+@pytest.mark.asyncio
+async def test_options(server):
+ url = "http://127.0.0.1:8000/"
+ async with httpcore.AsyncClient() as client:
+ response = await client.options(url)
+ assert response.status_code == 200
+ assert response.text == "Hello, world!"
+
+
+@pytest.mark.asyncio
+async def test_head(server):
+ url = "http://127.0.0.1:8000/"
+ async with httpcore.AsyncClient() as client:
+ response = await client.head(url)
+ assert response.status_code == 200
+ assert response.text == ""
+
+
+@pytest.mark.asyncio
+async def test_put(server):
+ url = "http://127.0.0.1:8000/"
+ async with httpcore.AsyncClient() as client:
+ response = await client.put(url, data=b"Hello, world!")
+ assert response.status_code == 200
+
+
+@pytest.mark.asyncio
+async def test_patch(server):
+ url = "http://127.0.0.1:8000/"
+ async with httpcore.AsyncClient() as client:
+ response = await client.patch(url, data=b"Hello, world!")
+ assert response.status_code == 200
+
+
+@pytest.mark.asyncio
+async def test_delete(server):
+ url = "http://127.0.0.1:8000/"
+ async with httpcore.AsyncClient() as client:
+ response = await client.delete(url)
+ assert response.status_code == 200
+ assert response.text == "Hello, world!"
@threadpool
def test_get(server):
+ url = "http://127.0.0.1:8000/"
with httpcore.Client() as http:
- response = http.get("http://127.0.0.1:8000/")
+ response = http.get(url)
assert response.status_code == 200
+ assert response.url == httpcore.URL(url)
assert response.content == b"Hello, world!"
assert response.text == "Hello, world!"
assert response.protocol == "HTTP/1.1"
+ assert response.encoding == "iso-8859-1"
+ assert response.request.url == httpcore.URL(url)
assert response.headers
- assert repr(response) == "<SyncResponse(status_code=200)>"
+ assert response.is_redirect is False
+ assert repr(response) == "<SyncResponse(200, 'OK')>"
@threadpool
response.close() # TODO: should Response be available as context managers?
+@threadpool
+def test_raise_for_status(server):
+ with httpcore.Client() as client:
+ for status_code in (200, 400, 404, 500, 505):
+ response = client.request(
+ "GET", "http://127.0.0.1:8000/status/{}".format(status_code)
+ )
+
+ if 400 <= status_code < 600:
+ with pytest.raises(httpcore.exceptions.HttpError):
+ response.raise_for_status()
+ else:
+ assert response.raise_for_status() is None
+
+
@threadpool
def test_options(server):
- with httpcore.SyncClient() as http:
+ with httpcore.Client() as http:
response = http.options("http://127.0.0.1:8000/")
-
assert response.status_code == 200
assert response.reason_phrase == "OK"
@threadpool
def test_head(server):
- with httpcore.SyncClient() as http:
+ with httpcore.Client() as http:
response = http.head("http://127.0.0.1:8000/")
-
assert response.status_code == 200
assert response.reason_phrase == "OK"
@threadpool
def test_put(server):
- with httpcore.SyncClient() as http:
+ with httpcore.Client() as http:
response = http.put("http://127.0.0.1:8000/", data=b"Hello, world!")
assert response.status_code == 200
assert response.reason_phrase == "OK"
@threadpool
def test_patch(server):
- with httpcore.SyncClient() as http:
+ with httpcore.Client() as http:
response = http.patch("http://127.0.0.1:8000/", data=b"Hello, world!")
assert response.status_code == 200
assert response.reason_phrase == "OK"
@threadpool
def test_delete(server):
- with httpcore.SyncClient() as http:
+ with httpcore.Client() as http:
response = http.delete("http://127.0.0.1:8000/")
assert response.status_code == 200
assert response.reason_phrase == "OK"