mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Improve tests in Bring! integration (#162853)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"""Test todo entity notification action of the Bring! integration."""
|
||||
|
||||
import re
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from bring_api import BringNotificationType, BringRequestException
|
||||
@@ -15,7 +14,7 @@ from homeassistant.components.bring.services import (
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -63,10 +62,7 @@ async def test_send_notification_exception(
|
||||
|
||||
assert bring_config_entry.state is ConfigEntryState.LOADED
|
||||
mock_bring_client.notify.side_effect = BringRequestException
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match="Failed to send push notification for Bring! due to a connection error, try again later",
|
||||
):
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUSH_NOTIFICATION,
|
||||
@@ -76,6 +72,7 @@ async def test_send_notification_exception(
|
||||
target={ATTR_ENTITY_ID: "todo.einkauf"},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "notify_request_failed"
|
||||
|
||||
|
||||
async def test_send_notification_service_validation_error(
|
||||
@@ -91,12 +88,7 @@ async def test_send_notification_service_validation_error(
|
||||
|
||||
assert bring_config_entry.state is ConfigEntryState.LOADED
|
||||
mock_bring_client.notify.side_effect = ValueError
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=re.escape(
|
||||
"This action requires field item, please enter a valid value for item"
|
||||
),
|
||||
):
|
||||
with pytest.raises(ServiceValidationError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUSH_NOTIFICATION,
|
||||
@@ -104,3 +96,5 @@ async def test_send_notification_service_validation_error(
|
||||
target={ATTR_ENTITY_ID: "todo.einkauf"},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "notify_missing_argument"
|
||||
assert err.value.translation_placeholders == {"field": "item"}
|
||||
|
||||
@@ -82,10 +82,7 @@ async def test_send_reaction_exception(
|
||||
|
||||
assert bring_config_entry.state is ConfigEntryState.LOADED
|
||||
mock_bring_client.notify.side_effect = BringRequestException
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match="Failed to send reaction for Bring! due to a connection error, try again later",
|
||||
):
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_ACTIVITY_STREAM_REACTION,
|
||||
@@ -95,6 +92,7 @@ async def test_send_reaction_exception(
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "reaction_request_failed"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_bring_client")
|
||||
@@ -143,10 +141,7 @@ async def test_send_reaction_unknown_entity(
|
||||
entity_registry.async_update_entity(
|
||||
"event.einkauf_activities", disabled_by=er.RegistryEntryDisabler.USER
|
||||
)
|
||||
with pytest.raises(
|
||||
ServiceValidationError,
|
||||
match="Failed to send reaction for Bring! — Unknown entity event.einkauf_activities",
|
||||
):
|
||||
with pytest.raises(ServiceValidationError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_ACTIVITY_STREAM_REACTION,
|
||||
@@ -157,6 +152,11 @@ async def test_send_reaction_unknown_entity(
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert err.value.translation_key == "entity_not_found"
|
||||
assert err.value.translation_placeholders == {
|
||||
"entity_id": "event.einkauf_activities"
|
||||
}
|
||||
|
||||
|
||||
async def test_send_reaction_not_found(
|
||||
hass: HomeAssistant,
|
||||
@@ -174,10 +174,7 @@ async def test_send_reaction_not_found(
|
||||
|
||||
assert bring_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match="Failed to send reaction for Bring! — No recent activity found",
|
||||
):
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_ACTIVITY_STREAM_REACTION,
|
||||
@@ -187,3 +184,4 @@ async def test_send_reaction_not_found(
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "activity_not_found"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Test for todo platform of the Bring! integration."""
|
||||
|
||||
from collections.abc import Generator
|
||||
import re
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from bring_api import BringItemOperation, BringItemsResponse, BringRequestException
|
||||
@@ -107,9 +106,7 @@ async def test_add_item_exception(
|
||||
assert bring_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
mock_bring_client.save_item.side_effect = BringRequestException
|
||||
with pytest.raises(
|
||||
HomeAssistantError, match="Failed to save item Äpfel to Bring! list"
|
||||
):
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
TODO_DOMAIN,
|
||||
TodoServices.ADD_ITEM,
|
||||
@@ -117,6 +114,8 @@ async def test_add_item_exception(
|
||||
target={ATTR_ENTITY_ID: "todo.einkauf"},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "todo_save_item_failed"
|
||||
assert err.value.translation_placeholders == {"name": "Äpfel"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_uuid")
|
||||
@@ -170,9 +169,7 @@ async def test_update_item_exception(
|
||||
assert bring_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
mock_bring_client.batch_update_list.side_effect = BringRequestException
|
||||
with pytest.raises(
|
||||
HomeAssistantError, match="Failed to update item Paprika to Bring! list"
|
||||
):
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
TODO_DOMAIN,
|
||||
TodoServices.UPDATE_ITEM,
|
||||
@@ -184,6 +181,8 @@ async def test_update_item_exception(
|
||||
target={ATTR_ENTITY_ID: "todo.einkauf"},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "todo_update_item_failed"
|
||||
assert err.value.translation_placeholders == {"name": "Paprika"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_uuid")
|
||||
@@ -245,9 +244,7 @@ async def test_rename_item_exception(
|
||||
assert bring_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
mock_bring_client.batch_update_list.side_effect = BringRequestException
|
||||
with pytest.raises(
|
||||
HomeAssistantError, match="Failed to rename item Gurke to Bring! list"
|
||||
):
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
TODO_DOMAIN,
|
||||
TodoServices.UPDATE_ITEM,
|
||||
@@ -259,6 +256,8 @@ async def test_rename_item_exception(
|
||||
target={ATTR_ENTITY_ID: "todo.einkauf"},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "todo_rename_item_failed"
|
||||
assert err.value.translation_placeholders == {"name": "Gurke"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_uuid")
|
||||
@@ -309,10 +308,7 @@ async def test_delete_items_exception(
|
||||
|
||||
assert bring_config_entry.state is ConfigEntryState.LOADED
|
||||
mock_bring_client.batch_update_list.side_effect = BringRequestException
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=re.escape("Failed to delete 1 item(s) from Bring! list"),
|
||||
):
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
await hass.services.async_call(
|
||||
TODO_DOMAIN,
|
||||
TodoServices.REMOVE_ITEM,
|
||||
@@ -320,3 +316,6 @@ async def test_delete_items_exception(
|
||||
target={ATTR_ENTITY_ID: "todo.einkauf"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert err.value.translation_key == "todo_delete_item_failed"
|
||||
assert err.value.translation_placeholders == {"count": "1"}
|
||||
|
||||
Reference in New Issue
Block a user