Improve Monzo tests (#117036)

This commit is contained in:
Joost Lekkerkerker 2024-05-18 13:20:08 +02:00 committed by GitHub
parent 4dad9c8859
commit b39028acf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 211 additions and 16 deletions

View file

@ -1,5 +1,41 @@
# serializer version: 1 # serializer version: 1
# name: test_all_entities # name: test_all_entities[sensor.current_account_balance-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.current_account_balance',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.MONETARY: 'monetary'>,
'original_icon': None,
'original_name': 'Balance',
'platform': 'monzo',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'balance',
'unique_id': 'acc_curr_balance',
'unit_of_measurement': 'GBP',
})
# ---
# name: test_all_entities[sensor.current_account_balance-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'attribution': 'Data provided by Monzo', 'attribution': 'Data provided by Monzo',
@ -15,7 +51,43 @@
'state': '1.23', 'state': '1.23',
}) })
# --- # ---
# name: test_all_entities.1 # name: test_all_entities[sensor.current_account_total_balance-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.current_account_total_balance',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.MONETARY: 'monetary'>,
'original_icon': None,
'original_name': 'Total balance',
'platform': 'monzo',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'total_balance',
'unique_id': 'acc_curr_total_balance',
'unit_of_measurement': 'GBP',
})
# ---
# name: test_all_entities[sensor.current_account_total_balance-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'attribution': 'Data provided by Monzo', 'attribution': 'Data provided by Monzo',
@ -31,7 +103,43 @@
'state': '3.21', 'state': '3.21',
}) })
# --- # ---
# name: test_all_entities.2 # name: test_all_entities[sensor.flex_balance-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.flex_balance',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.MONETARY: 'monetary'>,
'original_icon': None,
'original_name': 'Balance',
'platform': 'monzo',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'balance',
'unique_id': 'acc_flex_balance',
'unit_of_measurement': 'GBP',
})
# ---
# name: test_all_entities[sensor.flex_balance-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'attribution': 'Data provided by Monzo', 'attribution': 'Data provided by Monzo',
@ -47,7 +155,43 @@
'state': '1.23', 'state': '1.23',
}) })
# --- # ---
# name: test_all_entities.3 # name: test_all_entities[sensor.flex_total_balance-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.flex_total_balance',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.MONETARY: 'monetary'>,
'original_icon': None,
'original_name': 'Total balance',
'platform': 'monzo',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'total_balance',
'unique_id': 'acc_flex_total_balance',
'unit_of_measurement': 'GBP',
})
# ---
# name: test_all_entities[sensor.flex_total_balance-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'attribution': 'Data provided by Monzo', 'attribution': 'Data provided by Monzo',
@ -63,3 +207,55 @@
'state': '3.21', 'state': '3.21',
}) })
# --- # ---
# name: test_all_entities[sensor.savings_balance-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.savings_balance',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.MONETARY: 'monetary'>,
'original_icon': None,
'original_name': 'Balance',
'platform': 'monzo',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'pot_balance',
'unique_id': 'pot_savings_pot_balance',
'unit_of_measurement': 'GBP',
})
# ---
# name: test_all_entities[sensor.savings_balance-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by Monzo',
'device_class': 'monetary',
'friendly_name': 'Savings Balance',
'unit_of_measurement': 'GBP',
}),
'context': <ANY>,
'entity_id': 'sensor.savings_balance',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '1345.78',
})
# ---

View file

@ -38,7 +38,7 @@ async def test_full_flow(
}, },
) )
assert result["type"] == FlowResultType.EXTERNAL_STEP assert result["type"] is FlowResultType.EXTERNAL_STEP
assert result["url"] == ( assert result["url"] == (
f"{OAUTH2_AUTHORIZE}/?" f"{OAUTH2_AUTHORIZE}/?"
f"response_type=code&client_id={CLIENT_ID}&" f"response_type=code&client_id={CLIENT_ID}&"
@ -69,7 +69,7 @@ async def test_full_flow(
assert len(mock_setup.mock_calls) == 0 assert len(mock_setup.mock_calls) == 0
assert result["type"] == FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "await_approval_confirmation" assert result["step_id"] == "await_approval_confirmation"
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
@ -79,7 +79,7 @@ async def test_full_flow(
assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert len(mock_setup.mock_calls) == 1 assert len(mock_setup.mock_calls) == 1
assert result["type"] == FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == DOMAIN assert result["title"] == DOMAIN
assert "result" in result assert "result" in result
assert result["result"].unique_id == "600" assert result["result"].unique_id == "600"
@ -109,7 +109,7 @@ async def test_config_non_unique_profile(
}, },
) )
assert result["type"] == FlowResultType.EXTERNAL_STEP assert result["type"] is FlowResultType.EXTERNAL_STEP
assert result["url"] == ( assert result["url"] == (
f"{OAUTH2_AUTHORIZE}/?" f"{OAUTH2_AUTHORIZE}/?"
f"response_type=code&client_id={CLIENT_ID}&" f"response_type=code&client_id={CLIENT_ID}&"
@ -134,5 +134,5 @@ async def test_config_non_unique_profile(
}, },
) )
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result["type"] == FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"

View file

@ -18,12 +18,11 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import STATE_UNAVAILABLE from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant, State from homeassistant.core import HomeAssistant, State
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity_registry import EntityRegistry
from . import setup_integration from . import setup_integration
from .conftest import TEST_ACCOUNTS, TEST_POTS from .conftest import TEST_ACCOUNTS, TEST_POTS
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
EXPECTED_VALUE_GETTERS = { EXPECTED_VALUE_GETTERS = {
@ -66,10 +65,10 @@ async def test_sensor_default_enabled_entities(
monzo: AsyncMock, monzo: AsyncMock,
polling_config_entry: MockConfigEntry, polling_config_entry: MockConfigEntry,
hass_client_no_auth: ClientSessionGenerator, hass_client_no_auth: ClientSessionGenerator,
entity_registry: er.EntityRegistry,
) -> None: ) -> None:
"""Test entities enabled by default.""" """Test entities enabled by default."""
await setup_integration(hass, polling_config_entry) await setup_integration(hass, polling_config_entry)
entity_registry: EntityRegistry = er.async_get(hass)
for acc in TEST_ACCOUNTS: for acc in TEST_ACCOUNTS:
for sensor_description in ACCOUNT_SENSORS: for sensor_description in ACCOUNT_SENSORS:
@ -106,16 +105,16 @@ async def test_unavailable_entity(
async def test_all_entities( async def test_all_entities(
hass: HomeAssistant, hass: HomeAssistant,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
monzo: AsyncMock, monzo: AsyncMock,
polling_config_entry: MockConfigEntry, polling_config_entry: MockConfigEntry,
) -> None: ) -> None:
"""Test all entities.""" """Test all entities."""
await setup_integration(hass, polling_config_entry) await setup_integration(hass, polling_config_entry)
for acc in TEST_ACCOUNTS: await snapshot_platform(
for sensor in ACCOUNT_SENSORS: hass, entity_registry, snapshot, polling_config_entry.entry_id
entity_id = await async_get_entity_id(hass, acc["id"], sensor) )
assert hass.states.get(entity_id) == snapshot
async def test_update_failed( async def test_update_failed(