hass-core/tests/components/simplefin/conftest.py
Jeef 0213f1c5c0
Add SimpleFIN integration (#108336)
* 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>
2024-07-10 12:44:04 +02:00

83 lines
2.4 KiB
Python

"""Test fixtures for SimpleFIN."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from simplefin4py import FinancialData
from simplefin4py.exceptions import SimpleFinInvalidClaimTokenError
from homeassistant.components.simplefin import CONF_ACCESS_URL
from homeassistant.components.simplefin.const import DOMAIN
from tests.common import MockConfigEntry, load_fixture
MOCK_ACCESS_URL = "https://i:am@yomama.house.com"
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Mock setting up a config entry."""
with patch(
"homeassistant.components.simplefin.async_setup_entry", return_value=True
) as mock_setup:
yield mock_setup
@pytest.fixture
async def mock_config_entry() -> MockConfigEntry:
"""Fixture for MockConfigEntry."""
return MockConfigEntry(
domain=DOMAIN,
data={CONF_ACCESS_URL: MOCK_ACCESS_URL},
version=1,
)
@pytest.fixture
def mock_claim_setup_token() -> str:
"""Fixture to mock the claim_setup_token method of SimpleFin."""
with patch(
"homeassistant.components.simplefin.config_flow.SimpleFin.claim_setup_token",
) as mock_claim_setup_token:
mock_claim_setup_token.return_value = "https://i:am@yomama.comma"
yield
@pytest.fixture
def mock_decode_claim_token_invalid_then_good() -> str:
"""Fixture to mock the decode_claim_token method of SimpleFin."""
return_values = [SimpleFinInvalidClaimTokenError, "valid_return_value"]
with patch(
"homeassistant.components.simplefin.config_flow.SimpleFin.decode_claim_token",
new_callable=lambda: MagicMock(side_effect=return_values),
):
yield
@pytest.fixture
def mock_simplefin_client() -> Generator[AsyncMock]:
"""Mock a SimpleFin client."""
with (
patch(
"homeassistant.components.simplefin.SimpleFin",
autospec=True,
) as mock_client,
patch(
"homeassistant.components.simplefin.config_flow.SimpleFin",
new=mock_client,
),
):
mock_client.claim_setup_token.return_value = MOCK_ACCESS_URL
client = mock_client.return_value
fixture_data = load_fixture("fin_data.json", DOMAIN)
fin_data = FinancialData.from_json(fixture_data)
assert fin_data.accounts != []
client.fetch_data.return_value = fin_data
client.access_url = MOCK_ACCESS_URL
yield mock_client