-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for Bring integration #123087
Merged
Merged
Add tests for Bring integration #123087
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"uuid": "77a151f8-77c4-47a3-8295-c750a0e69d4f", | ||
"status": "REGISTERED", | ||
"purchase": [ | ||
{ | ||
"uuid": "b5d0790b-5f32-4d5c-91da-e29066f167de", | ||
"itemId": "Paprika", | ||
"specification": "Rot", | ||
"attributes": [] | ||
}, | ||
{ | ||
"uuid": "72d370ab-d8ca-4e41-b956-91df94795b4e", | ||
"itemId": "Pouletbrüstli", | ||
"specification": "Bio", | ||
"attributes": [] | ||
} | ||
], | ||
"recently": [ | ||
{ | ||
"uuid": "fc8db30a-647e-4e6c-9d71-3b85d6a2d954", | ||
"itemId": "Ananas", | ||
"specification": "", | ||
"attributes": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"lists": [ | ||
{ | ||
"listUuid": "e542eef6-dba7-4c31-a52c-29e6ab9d83a5", | ||
"name": "Einkauf", | ||
"theme": "ch.publisheria.bring.theme.home" | ||
}, | ||
{ | ||
"listUuid": "b4776778-7f6c-496e-951b-92a35d3db0dd", | ||
"name": "Baumarkt", | ||
"theme": "ch.publisheria.bring.theme.home" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# serializer version: 1 | ||
# name: test_todo[todo.baumarkt-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': None, | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'todo', | ||
'entity_category': None, | ||
'entity_id': 'todo.baumarkt', | ||
'has_entity_name': True, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'labels': set({ | ||
}), | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': None, | ||
'original_icon': None, | ||
'original_name': 'Baumarkt', | ||
'platform': 'bring', | ||
'previous_unique_id': None, | ||
'supported_features': <TodoListEntityFeature: 71>, | ||
'translation_key': 'shopping_list', | ||
'unique_id': '00000000-00000000-00000000-00000000_b4776778-7f6c-496e-951b-92a35d3db0dd', | ||
'unit_of_measurement': None, | ||
}) | ||
# --- | ||
# name: test_todo[todo.baumarkt-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'Baumarkt', | ||
'supported_features': <TodoListEntityFeature: 71>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'todo.baumarkt', | ||
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '2', | ||
}) | ||
# --- | ||
# name: test_todo[todo.einkauf-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': None, | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'todo', | ||
'entity_category': None, | ||
'entity_id': 'todo.einkauf', | ||
'has_entity_name': True, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'labels': set({ | ||
}), | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': None, | ||
'original_icon': None, | ||
'original_name': 'Einkauf', | ||
'platform': 'bring', | ||
'previous_unique_id': None, | ||
'supported_features': <TodoListEntityFeature: 71>, | ||
'translation_key': 'shopping_list', | ||
'unique_id': '00000000-00000000-00000000-00000000_e542eef6-dba7-4c31-a52c-29e6ab9d83a5', | ||
'unit_of_measurement': None, | ||
}) | ||
# --- | ||
# name: test_todo[todo.einkauf-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'Einkauf', | ||
'supported_features': <TodoListEntityFeature: 71>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'todo.einkauf', | ||
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '2', | ||
}) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
"""Test todo entity notification action of the Bring! integration.""" | ||
|
||
import re | ||
from unittest.mock import AsyncMock | ||
|
||
from bring_api import BringNotificationType, BringRequestException | ||
import pytest | ||
|
||
from homeassistant.components.bring.const import ( | ||
ATTR_ITEM_NAME, | ||
ATTR_NOTIFICATION_TYPE, | ||
DOMAIN, | ||
SERVICE_PUSH_NOTIFICATION, | ||
) | ||
from homeassistant.config_entries import ConfigEntryState | ||
from homeassistant.const import ATTR_ENTITY_ID | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.exceptions import HomeAssistantError | ||
|
||
from tests.common import MockConfigEntry | ||
|
||
|
||
async def test_send_notification( | ||
hass: HomeAssistant, | ||
bring_config_entry: MockConfigEntry, | ||
mock_bring_client: AsyncMock, | ||
) -> None: | ||
"""Test send bring push notification.""" | ||
|
||
bring_config_entry.add_to_hass(hass) | ||
await hass.config_entries.async_setup(bring_config_entry.entry_id) | ||
await hass.async_block_till_done() | ||
|
||
assert bring_config_entry.state is ConfigEntryState.LOADED | ||
|
||
await hass.services.async_call( | ||
DOMAIN, | ||
SERVICE_PUSH_NOTIFICATION, | ||
service_data={ | ||
ATTR_NOTIFICATION_TYPE: "GOING_SHOPPING", | ||
}, | ||
target={ATTR_ENTITY_ID: "todo.einkauf"}, | ||
blocking=True, | ||
) | ||
|
||
mock_bring_client.notify.assert_called_once_with( | ||
"e542eef6-dba7-4c31-a52c-29e6ab9d83a5", | ||
BringNotificationType.GOING_SHOPPING, | ||
None, | ||
) | ||
|
||
|
||
async def test_send_notification_exception( | ||
hass: HomeAssistant, | ||
bring_config_entry: MockConfigEntry, | ||
mock_bring_client: AsyncMock, | ||
) -> None: | ||
"""Test send bring push notification with exception.""" | ||
|
||
bring_config_entry.add_to_hass(hass) | ||
await hass.config_entries.async_setup(bring_config_entry.entry_id) | ||
await hass.async_block_till_done() | ||
|
||
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", | ||
): | ||
await hass.services.async_call( | ||
DOMAIN, | ||
SERVICE_PUSH_NOTIFICATION, | ||
service_data={ | ||
ATTR_NOTIFICATION_TYPE: "GOING_SHOPPING", | ||
}, | ||
target={ATTR_ENTITY_ID: "todo.einkauf"}, | ||
blocking=True, | ||
) | ||
|
||
|
||
async def test_send_notification_service_validation_error( | ||
hass: HomeAssistant, | ||
bring_config_entry: MockConfigEntry, | ||
mock_bring_client: AsyncMock, | ||
) -> None: | ||
"""Test send bring push notification.""" | ||
|
||
bring_config_entry.add_to_hass(hass) | ||
await hass.config_entries.async_setup(bring_config_entry.entry_id) | ||
await hass.async_block_till_done() | ||
|
||
assert bring_config_entry.state is ConfigEntryState.LOADED | ||
mock_bring_client.notify.side_effect = ValueError | ||
with pytest.raises( | ||
HomeAssistantError, | ||
match=re.escape( | ||
"Failed to perform action bring.send_message. 'URGENT_MESSAGE' requires a value @ data['item']. Got None" | ||
), | ||
): | ||
await hass.services.async_call( | ||
DOMAIN, | ||
SERVICE_PUSH_NOTIFICATION, | ||
service_data={ATTR_NOTIFICATION_TYPE: "URGENT_MESSAGE", ATTR_ITEM_NAME: ""}, | ||
target={ATTR_ENTITY_ID: "todo.einkauf"}, | ||
blocking=True, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please break long strings around max 88 characters per line.