mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 05:57:01 +00:00
JSON serialize NamedTuple subclasses with aiohttp (#74971)
This commit is contained in:
@@ -19,6 +19,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import EVENT_HOMEASSISTANT_CLOSE
|
||||
import homeassistant.helpers.aiohttp_client as client
|
||||
from homeassistant.util.color import RGBColor
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -215,6 +216,16 @@ async def test_async_aiohttp_proxy_stream_client_err(aioclient_mock, camera_clie
|
||||
assert resp.status == 502
|
||||
|
||||
|
||||
async def test_sending_named_tuple(hass, aioclient_mock):
|
||||
"""Test sending a named tuple in json."""
|
||||
resp = aioclient_mock.post("http://127.0.0.1/rgb", json={"rgb": RGBColor(4, 3, 2)})
|
||||
session = client.async_create_clientsession(hass)
|
||||
resp = await session.post("http://127.0.0.1/rgb", json={"rgb": RGBColor(4, 3, 2)})
|
||||
assert resp.status == 200
|
||||
await resp.json() == {"rgb": RGBColor(4, 3, 2)}
|
||||
aioclient_mock.mock_calls[0][2]["rgb"] == RGBColor(4, 3, 2)
|
||||
|
||||
|
||||
async def test_client_session_immutable_headers(hass):
|
||||
"""Test we can't mutate headers."""
|
||||
session = client.async_get_clientsession(hass)
|
||||
|
||||
Reference in New Issue
Block a user