1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Fetch MaxLengthExceeded exception mesage from the translation cache (#113904)

* Fetch MaxLengthExceeded exception mesage from the translation cache

* Update homeassistant/components/homeassistant/strings.json

Co-authored-by: J. Nick Koston <nick@koston.org>

* Add case without homeassistant integration

* Fix test

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Jan Bouwhuis
2024-03-21 06:53:26 +01:00
committed by GitHub
parent 6ddef7bbff
commit 8edbf88da1
3 changed files with 29 additions and 4 deletions

View File

@@ -58,6 +58,7 @@ from homeassistant.exceptions import (
ServiceNotFound,
)
from homeassistant.helpers.json import json_dumps
from homeassistant.setup import async_setup_component
from homeassistant.util.async_ import create_eager_task
import homeassistant.util.dt as dt_util
from homeassistant.util.read_only_dict import ReadOnlyDict
@@ -1314,9 +1315,26 @@ async def test_eventbus_max_length_exceeded(hass: HomeAssistant) -> None:
"this_event_exceeds_the_max_character_length_even_with_the_new_limit"
)
# Without cached translations the translation key is returned
with pytest.raises(MaxLengthExceeded) as exc_info:
hass.bus.async_fire(long_evt_name)
assert str(exc_info.value) == "max_length_exceeded"
assert exc_info.value.property_name == "event_type"
assert exc_info.value.max_length == 64
assert exc_info.value.value == long_evt_name
# Fetch translations
await async_setup_component(hass, "homeassistant", {})
# With cached translations the formatted message is returned
with pytest.raises(MaxLengthExceeded) as exc_info:
hass.bus.async_fire(long_evt_name)
assert (
str(exc_info.value)
== f"Value {long_evt_name} for property event_type has a maximum length of 64 characters"
)
assert exc_info.value.property_name == "event_type"
assert exc_info.value.max_length == 64
assert exc_info.value.value == long_evt_name