2018-11-26 14:10:18 +01:00
|
|
|
"""Test aiohttp request helper."""
|
|
|
|
|
|
|
|
from homeassistant.util import aiohttp
|
|
|
|
|
|
|
|
|
|
|
|
async def test_request_json():
|
|
|
|
"""Test a JSON request."""
|
2020-06-15 16:30:40 -07:00
|
|
|
request = aiohttp.MockRequest(b'{"hello": 2}', mock_source="test")
|
2018-11-26 14:10:18 +01:00
|
|
|
assert request.status == 200
|
2019-07-31 12:25:30 -07:00
|
|
|
assert await request.json() == {"hello": 2}
|
2018-11-26 14:10:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_request_text():
|
|
|
|
"""Test a JSON request."""
|
2020-06-15 16:30:40 -07:00
|
|
|
request = aiohttp.MockRequest(b"hello", status=201, mock_source="test")
|
2018-11-26 14:10:18 +01:00
|
|
|
assert request.status == 201
|
2019-07-31 12:25:30 -07:00
|
|
|
assert await request.text() == "hello"
|
2018-11-26 14:10:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_request_post_query():
|
|
|
|
"""Test a JSON request."""
|
|
|
|
request = aiohttp.MockRequest(
|
2020-06-15 16:30:40 -07:00
|
|
|
b"hello=2&post=true", query_string="get=true", method="POST", mock_source="test"
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
|
|
|
assert request.method == "POST"
|
|
|
|
assert await request.post() == {"hello": "2", "post": "true"}
|
|
|
|
assert request.query == {"get": "true"}
|