mirror of
https://github.com/home-assistant/core.git
synced 2025-12-20 02:48:57 +00:00
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
"""Tests for the ntfy integration."""
|
|
|
|
from unittest.mock import AsyncMock
|
|
|
|
from aiontfy.exceptions import (
|
|
NtfyConnectionError,
|
|
NtfyHTTPError,
|
|
NtfyTimeoutError,
|
|
NtfyUnauthorizedAuthenticationError,
|
|
)
|
|
import pytest
|
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
@pytest.mark.usefixtures("mock_aiontfy")
|
|
async def test_entry_setup_unload(
|
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
|
) -> None:
|
|
"""Test integration setup and unload."""
|
|
|
|
config_entry.add_to_hass(hass)
|
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert config_entry.state is ConfigEntryState.LOADED
|
|
|
|
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
|
|
|
assert config_entry.state is ConfigEntryState.NOT_LOADED
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("exception"),
|
|
[
|
|
NtfyUnauthorizedAuthenticationError(
|
|
40101, 401, "unauthorized", "https://ntfy.sh/docs/publish/#authentication"
|
|
),
|
|
NtfyHTTPError(418001, 418, "I'm a teapot", ""),
|
|
NtfyConnectionError,
|
|
NtfyTimeoutError,
|
|
],
|
|
)
|
|
async def test_config_entry_not_ready(
|
|
hass: HomeAssistant,
|
|
config_entry: MockConfigEntry,
|
|
mock_aiontfy: AsyncMock,
|
|
exception: Exception,
|
|
) -> None:
|
|
"""Test config entry not ready."""
|
|
|
|
mock_aiontfy.account.side_effect = exception
|
|
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
|