Make exceptions in rest_command services translatable (#107252)

This commit is contained in:
Jan-Philipp Benecke 2024-01-05 15:44:31 +01:00 committed by GitHub
parent 0d7627da22
commit 8bbfee7801
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 21 deletions

View file

@ -115,8 +115,11 @@ class TestRestCommandComponent:
aioclient_mock.get(self.url, exc=asyncio.TimeoutError())
self.hass.services.call(rc.DOMAIN, "get_test", {})
self.hass.block_till_done()
with pytest.raises(
HomeAssistantError,
match=r"^Timeout when calling resource 'https://example.com/'$",
):
self.hass.services.call(rc.DOMAIN, "get_test", {}, blocking=True)
assert len(aioclient_mock.mock_calls) == 1
@ -127,8 +130,11 @@ class TestRestCommandComponent:
aioclient_mock.get(self.url, exc=aiohttp.ClientError())
self.hass.services.call(rc.DOMAIN, "get_test", {})
self.hass.block_till_done()
with pytest.raises(
HomeAssistantError,
match=r"^Client error occurred when calling resource 'https://example.com/'$",
):
self.hass.services.call(rc.DOMAIN, "get_test", {}, blocking=True)
assert len(aioclient_mock.mock_calls) == 1
@ -412,7 +418,10 @@ class TestRestCommandComponent:
assert not response
# Throws error when requesting response
with pytest.raises(HomeAssistantError):
with pytest.raises(
HomeAssistantError,
match=r"^Response of 'https://example.com/' could not be decoded as JSON$",
):
response = self.hass.services.call(
rc.DOMAIN, "get_test", {}, blocking=True, return_response=True
)
@ -439,7 +448,10 @@ class TestRestCommandComponent:
assert not response
# Throws Decode error when requesting response
with pytest.raises(HomeAssistantError):
with pytest.raises(
HomeAssistantError,
match=r"^Response of 'https://example.com/' could not be decoded as text$",
):
response = self.hass.services.call(
rc.DOMAIN, "get_test", {}, blocking=True, return_response=True
)