hass-core/tests/components/pyload/test_init.py
Mr. Bubbles 28fb361c64
Add config flow to pyLoad integration (#120135)
* Add config flow to pyLoad integration

* address issues

* remove suggested values

* Fix exception

* abort import flow on error

* readd repair issues on error

* fix ruff

* changes

* changes

* exception hints
2024-06-23 12:34:32 +02:00

63 lines
1.8 KiB
Python

"""Test pyLoad init."""
from unittest.mock import MagicMock
from pyloadapi.exceptions import CannotConnect, InvalidAuth, ParserError
import pytest
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
async def test_entry_setup_unload(
hass: HomeAssistant,
config_entry: MockConfigEntry,
mock_pyloadapi: MagicMock,
) -> None:
"""Test integration setup and unload."""
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED
await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.NOT_LOADED
@pytest.mark.parametrize(
("side_effect"),
[CannotConnect, ParserError],
)
async def test_config_entry_setup_errors(
hass: HomeAssistant,
config_entry: MockConfigEntry,
mock_pyloadapi: MagicMock,
side_effect: Exception,
) -> None:
"""Test config entry not ready."""
mock_pyloadapi.login.side_effect = side_effect
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_config_entry_setup_invalid_auth(
hass: HomeAssistant,
config_entry: MockConfigEntry,
mock_pyloadapi: MagicMock,
) -> None:
"""Test config entry authentication."""
mock_pyloadapi.login.side_effect = InvalidAuth
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.SETUP_ERROR