mirror of
https://github.com/home-assistant/core.git
synced 2025-11-17 23:10:28 +00:00
* add paperless integration - config flow and initialisation * Add first sensors - documents, inbox, storage total and available * Add status sensors with error attributes * add status coordinator and organized code * Fixed None error * Organized code and moved requests to coordinator * Organized code * optimized code * Add statustype state strings * Error handling * Organized code * Add update sensor and one coordinator for integration * add sanity sensor and timer for version request * Add sensors and icons.json. better errorhandling * Add tests and error handling * FIxed tests * Add tests for coverage * Quality scale * Stuff * Improved code structure * Removed sensor platform and reauth / reconfigure flow * bump pypaperless to 4.1.0 * Optimized tests; update sensor as update platform; little optimizations * Code optimizations with update platform * Add sensor platform * Removed update platform * quality scale * removed unused const * Removed update snapshot; better code * Changed name of entry * Fixed bugs * Minor changes * Minor changed and renamed sensors * Sensors to measurement * Fixed snapshot; test data to json; minor changes * removed mypy errors * Changed translation * minor changes * Update homeassistant/components/paperless_ngx/strings.json --------- Co-authored-by: Josef Zweck <josef@zweck.dev> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
"""Test the Paperless-ngx integration initialization."""
|
|
|
|
from unittest.mock import AsyncMock
|
|
|
|
from pypaperless.exceptions import (
|
|
InitializationError,
|
|
PaperlessConnectionError,
|
|
PaperlessForbiddenError,
|
|
PaperlessInactiveOrDeletedError,
|
|
PaperlessInvalidTokenError,
|
|
)
|
|
import pytest
|
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import setup_integration
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_load_unload_config_entry(
|
|
hass: HomeAssistant,
|
|
mock_config_entry: MockConfigEntry,
|
|
) -> None:
|
|
"""Test loading and unloading the integration."""
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
|
|
|
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("side_effect", "expected_state", "expected_error_key"),
|
|
[
|
|
(PaperlessConnectionError(), ConfigEntryState.SETUP_RETRY, None),
|
|
(PaperlessInvalidTokenError(), ConfigEntryState.SETUP_ERROR, "invalid_api_key"),
|
|
(
|
|
PaperlessInactiveOrDeletedError(),
|
|
ConfigEntryState.SETUP_ERROR,
|
|
"user_inactive_or_deleted",
|
|
),
|
|
(PaperlessForbiddenError(), ConfigEntryState.SETUP_ERROR, "forbidden"),
|
|
(InitializationError(), ConfigEntryState.SETUP_ERROR, "cannot_connect"),
|
|
],
|
|
)
|
|
async def test_setup_config_error_handling(
|
|
hass: HomeAssistant,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_paperless: AsyncMock,
|
|
side_effect: Exception,
|
|
expected_state: ConfigEntryState,
|
|
expected_error_key: str,
|
|
) -> None:
|
|
"""Test all initialization error paths during setup."""
|
|
mock_paperless.initialize.side_effect = side_effect
|
|
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
assert mock_config_entry.state == expected_state
|
|
assert mock_config_entry.error_reason_translation_key == expected_error_key
|