hass-core/tests/components/laundrify/test_init.py
xLarry abf9aab18f
Add laundrify integration (#65090)
* First version of laundrify integration

* Code cleanup

* Code cleanup after review #2

* Move coordinator to its own file

* Save devices as dict and implement available prop as fn

* Validate token on init, abort if already configured

* Some more cleanup after review

* Add strict type hints

* Minor changes after code review

* Remove OptionsFlow (use default poll interval instead)

* Fix CODEOWNERS to pass hassfest job

* Fix formatting to pass prettier job

* Fix mypy typing error

* Update internal device property after fetching data

* Call parental update handler and remove obsolete code

* Add coordinator tests and fix some config flow tests

* Refactor tests

* Refactor fixtures

* Device unavailable if polling fails
2022-05-21 15:18:01 -04:00

59 lines
2.1 KiB
Python

"""Test the laundrify init file."""
from laundrify_aio import exceptions
from homeassistant.components.laundrify.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from . import create_entry
async def test_setup_entry_api_unauthorized(
hass: HomeAssistant, laundrify_validate_token
):
"""Test that ConfigEntryAuthFailed is thrown when authentication fails."""
laundrify_validate_token.side_effect = exceptions.UnauthorizedException
config_entry = create_entry(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert config_entry.state == ConfigEntryState.SETUP_ERROR
assert not hass.data.get(DOMAIN)
async def test_setup_entry_api_cannot_connect(
hass: HomeAssistant, laundrify_validate_token
):
"""Test that ApiConnectionException is thrown when connection fails."""
laundrify_validate_token.side_effect = exceptions.ApiConnectionException
config_entry = create_entry(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert config_entry.state == ConfigEntryState.SETUP_RETRY
assert not hass.data.get(DOMAIN)
async def test_setup_entry_successful(hass: HomeAssistant):
"""Test entry can be setup successfully."""
config_entry = create_entry(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert config_entry.state == ConfigEntryState.LOADED
async def test_setup_entry_unload(hass: HomeAssistant):
"""Test unloading the laundrify entry."""
config_entry = create_entry(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.config_entries.async_unload(config_entry.entry_id)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert config_entry.state == ConfigEntryState.NOT_LOADED