Allow sending webhooks via WS connection (#62725)
This commit is contained in:
parent
3f7275a9c7
commit
1ea3a17d89
7 changed files with 187 additions and 92 deletions
|
@ -1,4 +1,5 @@
|
|||
"""Test aiohttp request helper."""
|
||||
from aiohttp import web
|
||||
|
||||
from homeassistant.util import aiohttp
|
||||
|
||||
|
@ -25,3 +26,53 @@ async def test_request_post_query():
|
|||
assert request.method == "POST"
|
||||
assert await request.post() == {"hello": "2", "post": "true"}
|
||||
assert request.query == {"get": "true"}
|
||||
|
||||
|
||||
def test_serialize_text():
|
||||
"""Test serializing a text response."""
|
||||
response = web.Response(status=201, text="Hello")
|
||||
assert aiohttp.serialize_response(response) == {
|
||||
"status": 201,
|
||||
"body": "Hello",
|
||||
"headers": {"Content-Type": "text/plain; charset=utf-8"},
|
||||
}
|
||||
|
||||
|
||||
def test_serialize_body_str():
|
||||
"""Test serializing a response with a str as body."""
|
||||
response = web.Response(status=201, body="Hello")
|
||||
assert aiohttp.serialize_response(response) == {
|
||||
"status": 201,
|
||||
"body": "Hello",
|
||||
"headers": {"Content-Length": "5", "Content-Type": "text/plain; charset=utf-8"},
|
||||
}
|
||||
|
||||
|
||||
def test_serialize_body_None():
|
||||
"""Test serializing a response with a str as body."""
|
||||
response = web.Response(status=201, body=None)
|
||||
assert aiohttp.serialize_response(response) == {
|
||||
"status": 201,
|
||||
"body": None,
|
||||
"headers": {},
|
||||
}
|
||||
|
||||
|
||||
def test_serialize_body_bytes():
|
||||
"""Test serializing a response with a str as body."""
|
||||
response = web.Response(status=201, body=b"Hello")
|
||||
assert aiohttp.serialize_response(response) == {
|
||||
"status": 201,
|
||||
"body": "Hello",
|
||||
"headers": {},
|
||||
}
|
||||
|
||||
|
||||
def test_serialize_json():
|
||||
"""Test serializing a JSON response."""
|
||||
response = web.json_response({"how": "what"})
|
||||
assert aiohttp.serialize_response(response) == {
|
||||
"status": 200,
|
||||
"body": '{"how": "what"}',
|
||||
"headers": {"Content-Type": "application/json; charset=utf-8"},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue