1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-01 03:36:05 +01:00
Files
core/tests/components/webdav/test_init.py
T
2026-06-16 21:49:44 +02:00

86 lines
2.3 KiB
Python

"""Test WebDAV component setup."""
from unittest.mock import AsyncMock
from aiowebdav2.exceptions import (
AccessDeniedError,
ConnectionExceptionError,
NoConnectionError,
UnauthorizedError,
)
import pytest
from homeassistant.components.webdav.const import CONF_BACKUP_PATH, DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME
from homeassistant.core import HomeAssistant
from . import setup_integration
from tests.common import MockConfigEntry
@pytest.mark.parametrize(
("error", "expected_message", "expected_state"),
[
(
UnauthorizedError("Unauthorized"),
"Invalid username or password",
ConfigEntryState.SETUP_ERROR,
),
(
AccessDeniedError("/access_denied"),
"Access denied to /access_denied",
ConfigEntryState.SETUP_ERROR,
),
(
ConnectionExceptionError(ConnectionError("Connection refused")),
"Connection refused",
ConfigEntryState.SETUP_RETRY,
),
(
NoConnectionError("webdav.demo"),
"No connection with webdav.demo",
ConfigEntryState.SETUP_RETRY,
),
(
TimeoutError(),
"",
ConfigEntryState.SETUP_RETRY,
),
],
ids=[
"UnauthorizedError",
"AccessDeniedError",
"ConnectionExceptionError",
"NoConnectionError",
"TimeoutError",
],
)
async def test_error_during_setup(
hass: HomeAssistant,
webdav_client: AsyncMock,
caplog: pytest.LogCaptureFixture,
error: Exception,
expected_message: str,
expected_state: ConfigEntryState,
) -> None:
"""Test handling of various errors during setup."""
webdav_client.check.side_effect = error
config_entry = MockConfigEntry(
title="user@webdav.demo",
domain=DOMAIN,
data={
CONF_URL: "https://webdav.demo",
CONF_USERNAME: "user",
CONF_PASSWORD: "supersecretpassword",
CONF_BACKUP_PATH: "/backups",
},
entry_id="01JKXV07ASC62D620DGYNG2R8H",
)
await setup_integration(hass, config_entry)
assert expected_message in caplog.text
assert config_entry.state is expected_state