47
tests/test_init.py
Normal file
47
tests/test_init.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Test AdGuard Control Hub initialization."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from custom_components.adguard_control_hub.const import DOMAIN
|
||||
|
||||
|
||||
async def test_setup_entry(hass: HomeAssistant, mock_config_entry, mock_adguard_api) -> None:
|
||||
"""Test successful setup of entry."""
|
||||
with patch(
|
||||
"custom_components.adguard_control_hub.AdGuardHomeAPI"
|
||||
) as mock_api_class:
|
||||
mock_api_class.return_value = mock_adguard_api
|
||||
|
||||
entry = hass.config_entries.async_add(mock_config_entry)
|
||||
|
||||
with patch("custom_components.adguard_control_hub.PLATFORMS", []):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state == ConfigEntryState.LOADED
|
||||
assert DOMAIN in hass.data
|
||||
|
||||
|
||||
async def test_unload_entry(hass: HomeAssistant, mock_config_entry, mock_adguard_api) -> None:
|
||||
"""Test successful unload of entry."""
|
||||
with patch(
|
||||
"custom_components.adguard_control_hub.AdGuardHomeAPI"
|
||||
) as mock_api_class:
|
||||
mock_api_class.return_value = mock_adguard_api
|
||||
|
||||
entry = hass.config_entries.async_add(mock_config_entry)
|
||||
|
||||
with patch("custom_components.adguard_control_hub.PLATFORMS", []):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state == ConfigEntryState.LOADED
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state == ConfigEntryState.NOT_LOADED
|
||||
Reference in New Issue
Block a user