Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
40 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Helper functions for cloud components.""" | ||
from typing import Any, Dict | ||
|
||
from aiohttp import web | ||
|
||
|
||
def aiohttp_serialize_response(response: web.Response) -> Dict[str, Any]: | ||
"""Serialize an aiohttp response to a dictionary.""" | ||
return { | ||
'status': response.status, | ||
'body': response.text, | ||
'headers': dict(response.headers), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Test aiohttp request helper.""" | ||
from aiohttp import web | ||
|
||
from homeassistant.components.cloud import utils | ||
|
||
|
||
def test_serialize_text(): | ||
"""Test serializing a text response.""" | ||
response = web.Response(status=201, text='Hello') | ||
assert utils.aiohttp_serialize_response(response) == { | ||
'status': 201, | ||
'body': 'Hello', | ||
'headers': {'Content-Type': 'text/plain; charset=utf-8'}, | ||
} | ||
|
||
|
||
def test_serialize_json(): | ||
"""Test serializing a JSON response.""" | ||
response = web.json_response({"how": "what"}) | ||
assert utils.aiohttp_serialize_response(response) == { | ||
'status': 200, | ||
'body': '{"how": "what"}', | ||
'headers': {'Content-Type': 'application/json; charset=utf-8'}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters