Get ServiceValidationError message from translation cache only (#113704)

* Get ServiceValidationError message from translation cache only

* Remove message for NotValidPresetModeError
This commit is contained in:
Jan Bouwhuis 2024-03-18 14:42:21 +01:00 committed by GitHub
parent ec7aecef84
commit 3dc8df2403
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 16 additions and 43 deletions

View file

@ -1,5 +1,7 @@
"""Tests for the services provided by the EnergyZero integration."""
import re
import pytest
from syrupy.assertion import SnapshotAssertion
import voluptuous as vol
@ -101,7 +103,7 @@ def config_entry_data(
"start": "incorrect date",
},
ServiceValidationError,
"Invalid datetime provided.",
"Invalid date provided. Got incorrect date",
),
(
{"config_entry": True},
@ -110,7 +112,7 @@ def config_entry_data(
"end": "incorrect date",
},
ServiceValidationError,
"Invalid datetime provided.",
"Invalid date provided. Got incorrect date",
),
],
indirect=["config_entry_data"],
@ -125,7 +127,7 @@ async def test_service_validation(
) -> None:
"""Test the EnergyZero Service validation."""
with pytest.raises(error, match=error_message):
with pytest.raises(error) as exc:
await hass.services.async_call(
DOMAIN,
service,
@ -133,6 +135,7 @@ async def test_service_validation(
blocking=True,
return_response=True,
)
assert re.match(error_message, str(exc.value))
@pytest.mark.usefixtures("init_integration")

View file

@ -550,8 +550,8 @@ async def test_service_call_with_template_topic_renders_invalid_topic(
blocking=True,
)
assert str(exc.value) == (
"Unable to publish: topic template 'test/{{ '+' if True else 'topic' }}/topic' "
"produced an invalid topic 'test/+/topic' after rendering "
"Unable to publish: topic template `test/{{ '+' if True else 'topic' }}/topic` "
"produced an invalid topic `test/+/topic` after rendering "
"(Wildcards cannot be used in topic names)"
)
assert not mqtt_mock.async_publish.called

View file

@ -348,12 +348,12 @@ async def test_add_item_service_raises(
(
{"item": "Submit forms", "description": "Submit tax forms"},
ServiceValidationError,
"does not support setting field 'description'",
"does not support setting field: description",
),
(
{"item": "Submit forms", "due_date": "2023-11-17"},
ServiceValidationError,
"does not support setting field 'due_date'",
"does not support setting field: due_date",
),
(
{
@ -361,7 +361,7 @@ async def test_add_item_service_raises(
"due_datetime": f"2023-11-17T17:00:00{TEST_OFFSET}",
},
ServiceValidationError,
"does not support setting field 'due_datetime'",
"does not support setting field: due_datetime",
),
],
)
@ -376,7 +376,7 @@ async def test_add_item_service_invalid_input(
await create_mock_platform(hass, [test_entity])
with pytest.raises(expected_exception, match=expected_error):
with pytest.raises(expected_exception) as exc:
await hass.services.async_call(
DOMAIN,
"add_item",
@ -385,6 +385,8 @@ async def test_add_item_service_invalid_input(
blocking=True,
)
assert expected_error in str(exc.value)
@pytest.mark.parametrize(
("supported_entity_feature", "item_data", "expected_item"),

View file

@ -175,7 +175,7 @@ async def test_operation_mode_validation(
DOMAIN, SERVICE_SET_OPERATION_MODE, data, blocking=True
)
assert (
str(exc.value) == "Operation mode test not valid for entity water_heater.test. "
str(exc.value) == "Operation mode test is not valid for water_heater.test. "
"The operation list is not defined"
)
assert exc.value.translation_domain == DOMAIN
@ -191,7 +191,7 @@ async def test_operation_mode_validation(
DOMAIN, SERVICE_SET_OPERATION_MODE, data, blocking=True
)
assert (
str(exc.value) == "Operation mode test not valid for entity water_heater.test. "
str(exc.value) == "Operation mode test is not valid for water_heater.test. "
"Valid operation modes are: gas, eco"
)
assert exc.value.translation_domain == DOMAIN