Skip to content

Commit

Permalink
Second commit - with some coverage but errors abount
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeftor committed Aug 16, 2024
1 parent 1a602d8 commit c9a5138
Show file tree
Hide file tree
Showing 8 changed files with 1,209 additions and 72 deletions.
1 change: 1 addition & 0 deletions homeassistant/components/monarchmoney/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def _async_update_data(self) -> Any:
@property
def accounts(self) -> Any:
"""Return accounts."""

return self.data["accounts"]

def get_account_for_id(self, account_id: str) -> Any | None:
Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/monarchmoney/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def __init__(

# Parse out some fields
institution = account["institution"]["name"]
provider = account["credential"]["dataProvider"]

provider = account.get("dataProvider", "Manual input")
if account.get("credential") is not None:
provider = account["credential"].get("dataProvider", provider)

self._attr_attribution = f"Data provided by Monarch Money API via {provider}"

Expand Down
2 changes: 0 additions & 2 deletions homeassistant/components/monarchmoney/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
from . import MonarchMoneyConfigEntry
from .const import LOGGER
from .entity import MonarchMoneyEntity
from ..tuya.const import unit_alias
from ...helpers.config_validation import currency


def _type_to_icon(account: Any) -> str:
Expand Down
12 changes: 12 additions & 0 deletions tests/components/monarchmoney/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
"""Tests for the Monarch Money integration."""

from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry


async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
"""Fixture for setting up the component."""
config_entry.add_to_hass(hass)

await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
47 changes: 32 additions & 15 deletions tests/components/monarchmoney/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Common fixtures for the Monarch Money tests."""

from collections.abc import Generator
from unittest.mock import AsyncMock, patch, PropertyMock
import json
from typing import Any
from unittest.mock import AsyncMock, PropertyMock, patch

import pytest

from homeassistant.const import CONF_TOKEN
from tests.common import MockConfigEntry
from homeassistant.components.monarchmoney.const import DOMAIN
from homeassistant.const import CONF_TOKEN

from tests.common import MockConfigEntry, load_fixture


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
Expand All @@ -17,6 +21,7 @@ def mock_setup_entry() -> Generator[AsyncMock]:
) as mock_setup_entry:
yield mock_setup_entry


@pytest.fixture
async def mock_config_entry() -> MockConfigEntry:
"""Fixture for mock config entry."""
Expand All @@ -28,20 +33,32 @@ async def mock_config_entry() -> MockConfigEntry:


@pytest.fixture
def mock_api() -> Generator[AsyncMock]:
def mock_config_api() -> Generator[AsyncMock]:
"""Mock the MonarchMoney class."""
with patch("homeassistant.components.monarchmoney.config_flow.MonarchMoney", autospec=True) as mock_class:

account_data: dict[str, Any] = json.loads(load_fixture("get_accounts.json", DOMAIN))

with (
patch(
"homeassistant.components.monarchmoney.config_flow.MonarchMoney",
autospec=True,
) as mock_class,
patch("homeassistant.components.monarchmoney.MonarchMoney", new=mock_class),
):
instance = mock_class.return_value
type(instance).token = PropertyMock(return_value="mocked_token")
instance.login = AsyncMock(return_value=None)
instance.get_subscription_details = AsyncMock(return_value={
'subscription': {
'id': '123456789',
'paymentSource': 'STRIPE',
'referralCode': 'go3dpvrdmw',
'isOnFreeTrial': False,
'hasPremiumEntitlement': True,
'__typename': 'HouseholdSubscription'
instance.get_subscription_details = AsyncMock(
return_value={
"subscription": {
"id": "123456789",
"paymentSource": "STRIPE",
"referralCode": "go3dpvrdmw",
"isOnFreeTrial": False,
"hasPremiumEntitlement": True,
"__typename": "HouseholdSubscription",
}
}
})
yield mock_class
)
instance.get_accounts = AsyncMock(return_value=account_data)
yield mock_class
Loading

0 comments on commit c9a5138

Please sign in to comment.