mirror of
https://github.com/home-assistant/core.git
synced 2025-05-21 14:27:07 +00:00

* reset to latest dev branch * Update homeassistant/components/simplefin/sensor.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * formatting tweak * Removed info errors * fix bad billing error message * addressing PR * addressing PR * reauth abort and already_confiugred added to strings.json * adding the reauth message * ruff * update reqs * reset to latest dev branch * Update homeassistant/components/simplefin/sensor.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * formatting tweak * Removed info errors * fix bad billing error message * addressing PR * addressing PR * reauth abort and already_confiugred added to strings.json * adding the reauth message * ruff * update reqs * Update homeassistant/components/simplefin/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Addressing a few PR comments - removing nix - and adding runtime data * updated comments * rename config flow * pulling reauth :( - inline stuff * inline more * fixed a tab issue * reverting changes * various PR updates and code removal * generator async add * Update homeassistant/components/simplefin/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * always callable * Update homeassistant/components/simplefin/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * no-verify * type * fixing missing domain * it looks like this file is gone now * typing * sorta pass * fix license * Update homeassistant/components/simplefin/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/simplefin/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * addressing PR * Update homeassistant/components/simplefin/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * move property to entity.py * moved stuff out to else block * Initial Snappshot Testing ... still have unadressed changes to make * Addressing PR Comments * pushing back to joost * removing non-needed file * added more asserts * reducing mocks - need to fix patch paths still * Changed patch to be more localized to config_flow * Removed unneeded fixture * Moved coordinator around * Cleaning up the code * Removed a NOQA" * Upping the number of asserts * cleanup * fixed abort call * incremental update - for Josot... changed a function signature and removed an annotatoin * no-verify * Added an abort test * ruff * increased coverage but it might not pass muster for JOOST * increased coverage but it might not pass muster for JOOST * Much nicer test now * tried to simplify * Fix nits --------- Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
95 lines
3.1 KiB
Python
95 lines
3.1 KiB
Python
"""Test SimpleFin Sensor with Snapshot data."""
|
|
|
|
from datetime import timedelta
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from freezegun.api import FrozenDateTimeFactory
|
|
import pytest
|
|
from simplefin4py.exceptions import SimpleFinAuthError, SimpleFinPaymentRequiredError
|
|
from syrupy import SnapshotAssertion
|
|
|
|
from homeassistant.const import STATE_UNAVAILABLE, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import entity_registry as er
|
|
|
|
from . import setup_integration
|
|
|
|
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
|
|
|
|
|
|
async def test_all_entities(
|
|
hass: HomeAssistant,
|
|
snapshot: SnapshotAssertion,
|
|
mock_config_entry: MockConfigEntry,
|
|
entity_registry: er.EntityRegistry,
|
|
mock_simplefin_client: AsyncMock,
|
|
) -> None:
|
|
"""Test all entities."""
|
|
with patch("homeassistant.components.simplefin.PLATFORMS", [Platform.SENSOR]):
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("side_effect"),
|
|
[
|
|
(SimpleFinAuthError),
|
|
(SimpleFinPaymentRequiredError),
|
|
],
|
|
)
|
|
async def test_update_errors(
|
|
hass: HomeAssistant,
|
|
snapshot: SnapshotAssertion,
|
|
mock_config_entry: MockConfigEntry,
|
|
entity_registry: er.EntityRegistry,
|
|
mock_simplefin_client: AsyncMock,
|
|
freezer: FrozenDateTimeFactory,
|
|
side_effect: Exception,
|
|
) -> None:
|
|
"""Test connection error."""
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
assert hass.states.get("sensor.the_bank_of_go_the_bank_balance").state == "7777.77"
|
|
assert hass.states.get("sensor.investments_my_checking_balance").state == "12345.67"
|
|
assert (
|
|
hass.states.get("sensor.the_bank_of_go_prime_savings_balance").state
|
|
== "9876.54"
|
|
)
|
|
assert (
|
|
hass.states.get("sensor.random_bank_costco_anywhere_visa_r_card_balance").state
|
|
== "-532.69"
|
|
)
|
|
assert hass.states.get("sensor.investments_dr_evil_balance").state == "1000000.00"
|
|
assert (
|
|
hass.states.get("sensor.investments_nerdcorp_series_b_balance").state
|
|
== "13579.24"
|
|
)
|
|
assert (
|
|
hass.states.get("sensor.mythical_randomsavings_unicorn_pot_balance").state
|
|
== "10000.00"
|
|
)
|
|
assert (
|
|
hass.states.get("sensor.mythical_randomsavings_castle_mortgage_balance").state
|
|
== "7500.00"
|
|
)
|
|
|
|
mock_simplefin_client.return_value.fetch_data.side_effect = side_effect
|
|
freezer.tick(timedelta(days=1))
|
|
async_fire_time_changed(hass)
|
|
await hass.async_block_till_done()
|
|
|
|
sensors = [
|
|
"sensor.the_bank_of_go_the_bank_balance",
|
|
"sensor.investments_my_checking_balance",
|
|
"sensor.the_bank_of_go_prime_savings_balance",
|
|
"sensor.random_bank_costco_anywhere_visa_r_card_balance",
|
|
"sensor.investments_dr_evil_balance",
|
|
"sensor.investments_nerdcorp_series_b_balance",
|
|
"sensor.mythical_randomsavings_unicorn_pot_balance",
|
|
"sensor.mythical_randomsavings_castle_mortgage_balance",
|
|
]
|
|
|
|
for sensor in sensors:
|
|
assert hass.states.get(sensor).state == STATE_UNAVAILABLE
|