* Initial commit * Second commit - with some coverage but errors abount * Updated testing coverage * Should be just about ready for PR * Adding some error handling for wonky acocunts * Adding USD hardcoded as this is all that is currently supported i believe * updating snapshots * updating entity descrition a little * Addign cashflow in * adding aggregate sensors * tweak icons * refactor some type stuff as well as initialize the pr comment addressing process * remove empty fields from manifest * Update homeassistant/components/monarchmoney/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * move stuff * get logging out of try block * get logging out of try block * using Subscription ID as stored in config entry for unique id soon * new unique id * giving cashflow a better unique id * Moving subscription id stuff into setup of coordinator * Update homeassistant/components/monarchmoney/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * ruff ruff * ruff ruff * split ot value and balance sensors... need to go tos leep * removed icons * Moved summary into a data class * efficenty increase * Update homeassistant/components/monarchmoney/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/monarchmoney/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/monarchmoney/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/monarchmoney/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * refactor continues * removed a comment * forgot to add a little bit of info * updated snapshot * Updates to monarch money using the new typed/wrapper setup * backing lib update * fixing manifest * fixing manifest * fixing manifest * Version 0.2.0 * fixing some types * more type fixes * cleanup and bump * no check * i think i got it all * the last thing * update domain name * i dont know what is in this commit * The Great Renaming * Moving to dict style accounting - as per request * updating backing deps * Update homeassistant/components/monarch_money/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/monarch_money/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/monarch_money/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/monarch_money/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/monarch_money/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * some changes * fixing capitalizaton * test test test * Adding dupe test * addressing pr stuff * forgot snapshot * Fix * Fix * Update homeassistant/components/monarch_money/sensor.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
"""Common fixtures for the Monarch Money tests."""
|
|
|
|
from collections.abc import Generator
|
|
import json
|
|
from typing import Any
|
|
from unittest.mock import AsyncMock, PropertyMock, patch
|
|
|
|
import pytest
|
|
from typedmonarchmoney.models import (
|
|
MonarchAccount,
|
|
MonarchCashflowSummary,
|
|
MonarchSubscription,
|
|
)
|
|
|
|
from homeassistant.components.monarch_money.const import DOMAIN
|
|
from homeassistant.const import CONF_TOKEN
|
|
|
|
from tests.common import MockConfigEntry, load_fixture, load_json_object_fixture
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
|
"""Override async_setup_entry."""
|
|
with patch(
|
|
"homeassistant.components.monarch_money.async_setup_entry", return_value=True
|
|
) as mock_setup_entry:
|
|
yield mock_setup_entry
|
|
|
|
|
|
@pytest.fixture
|
|
async def mock_config_entry() -> MockConfigEntry:
|
|
"""Fixture for mock config entry."""
|
|
return MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data={CONF_TOKEN: "fake_token_of_doom"},
|
|
unique_id="222260252323873333",
|
|
version=1,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_api() -> Generator[AsyncMock]:
|
|
"""Mock the MonarchMoney class."""
|
|
|
|
account_json: dict[str, Any] = load_json_object_fixture("get_accounts.json", DOMAIN)
|
|
account_data = [MonarchAccount(data) for data in account_json["accounts"]]
|
|
account_data_dict: dict[str, MonarchAccount] = {
|
|
acc["id"]: MonarchAccount(acc) for acc in account_json["accounts"]
|
|
}
|
|
|
|
cashflow_json: dict[str, Any] = json.loads(
|
|
load_fixture("get_cashflow_summary.json", DOMAIN)
|
|
)
|
|
cashflow_summary = MonarchCashflowSummary(cashflow_json)
|
|
subscription_details = MonarchSubscription(
|
|
json.loads(load_fixture("get_subscription_details.json", DOMAIN))
|
|
)
|
|
|
|
with (
|
|
patch(
|
|
"homeassistant.components.monarch_money.config_flow.TypedMonarchMoney",
|
|
autospec=True,
|
|
) as mock_class,
|
|
patch(
|
|
"homeassistant.components.monarch_money.TypedMonarchMoney", new=mock_class
|
|
),
|
|
):
|
|
instance = mock_class.return_value
|
|
type(instance).token = PropertyMock(return_value="mocked_token")
|
|
instance.login = AsyncMock(return_value=None)
|
|
instance.multi_factor_authenticate = AsyncMock(return_value=None)
|
|
instance.get_subscription_details = AsyncMock(return_value=subscription_details)
|
|
instance.get_accounts = AsyncMock(return_value=account_data)
|
|
instance.get_accounts_as_dict_with_id_key = AsyncMock(
|
|
return_value=account_data_dict
|
|
)
|
|
instance.get_cashflow_summary = AsyncMock(return_value=cashflow_summary)
|
|
instance.get_subscription_details = AsyncMock(return_value=subscription_details)
|
|
yield mock_class
|