* add bring integration * fix typings and remove from strictly typed - wait for python-bring-api to be ready for strictly typed * make entity unique to user and list - before it was only list, therefore the same list imported by two users would have failed * simplify bring attribute Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * cleanup and code simplification * remove empty fields in manifest * __init__.py aktualisieren Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * __init__.py aktualisieren Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * strings.json aktualisieren Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * streamline async calls * use coordinator refresh * fix order in update call and simplify bring list * simplify the config_flow * Update homeassistant/components/bring/manifest.json Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com> * add unit testing for __init__.py * cleanup comments * use dict instead of list * Update homeassistant/components/bring/todo.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * clean up * update attribute name * update more attribute name * improve unit tests - remove patch and use mock in conftest * clean up tests even more * more unit test inprovements * remove optional type * minor unit test cleanup * Update .coveragerc Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""Unit tests for the bring integration."""
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.bring import (
|
|
BringAuthException,
|
|
BringParseException,
|
|
BringRequestException,
|
|
)
|
|
from homeassistant.components.bring.const import DOMAIN
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def setup_integration(
|
|
hass: HomeAssistant,
|
|
bring_config_entry: MockConfigEntry,
|
|
) -> None:
|
|
"""Mock setup of the bring integration."""
|
|
bring_config_entry.add_to_hass(hass)
|
|
await hass.config_entries.async_setup(bring_config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
async def test_load_unload(
|
|
hass: HomeAssistant,
|
|
mock_bring_client: Mock,
|
|
bring_config_entry: MockConfigEntry,
|
|
) -> None:
|
|
"""Test loading and unloading of the config entry."""
|
|
await setup_integration(hass, bring_config_entry)
|
|
|
|
entries = hass.config_entries.async_entries(DOMAIN)
|
|
assert len(entries) == 1
|
|
|
|
assert bring_config_entry.state == ConfigEntryState.LOADED
|
|
|
|
assert await hass.config_entries.async_unload(bring_config_entry.entry_id)
|
|
assert bring_config_entry.state == ConfigEntryState.NOT_LOADED
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("exception", "status"),
|
|
[
|
|
(BringRequestException, ConfigEntryState.SETUP_RETRY),
|
|
(BringAuthException, ConfigEntryState.SETUP_ERROR),
|
|
(BringParseException, ConfigEntryState.SETUP_RETRY),
|
|
],
|
|
)
|
|
async def test_init_failure(
|
|
hass: HomeAssistant,
|
|
mock_bring_client: Mock,
|
|
status: ConfigEntryState,
|
|
exception: Exception,
|
|
bring_config_entry: MockConfigEntry | None,
|
|
) -> None:
|
|
"""Test an initialization error on integration load."""
|
|
mock_bring_client.login.side_effect = exception
|
|
await setup_integration(hass, bring_config_entry)
|
|
assert bring_config_entry.state == status
|