mirror of
https://github.com/home-assistant/core.git
synced 2025-11-29 04:28:18 +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>
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
"""Common fixtures for the Paperless-ngx tests."""
|
|
|
|
from collections.abc import Generator
|
|
import json
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
from pypaperless.models import Statistic
|
|
import pytest
|
|
|
|
from homeassistant.components.paperless_ngx.const import DOMAIN
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import setup_integration
|
|
from .const import USER_INPUT
|
|
|
|
from tests.common import MockConfigEntry, load_fixture
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_statistic_data() -> Generator[MagicMock]:
|
|
"""Return test statistic data."""
|
|
return json.loads(load_fixture("test_data_statistic.json", DOMAIN))
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_statistic_data_update() -> Generator[MagicMock]:
|
|
"""Return updated test statistic data."""
|
|
return json.loads(load_fixture("test_data_statistic_update.json", DOMAIN))
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def mock_paperless(mock_statistic_data: MagicMock) -> Generator[AsyncMock]:
|
|
"""Mock the pypaperless.Paperless client."""
|
|
with (
|
|
patch(
|
|
"homeassistant.components.paperless_ngx.coordinator.Paperless",
|
|
autospec=True,
|
|
) as paperless_mock,
|
|
patch(
|
|
"homeassistant.components.paperless_ngx.config_flow.Paperless",
|
|
new=paperless_mock,
|
|
),
|
|
):
|
|
paperless = paperless_mock.return_value
|
|
|
|
paperless.base_url = "http://paperless.example.com/"
|
|
paperless.host_version = "2.3.0"
|
|
paperless.initialize.return_value = None
|
|
paperless.statistics = AsyncMock(
|
|
return_value=Statistic.create_with_data(
|
|
paperless, data=mock_statistic_data, fetched=True
|
|
)
|
|
)
|
|
|
|
yield paperless
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_entry() -> MockConfigEntry:
|
|
"""Return the default mocked config entry."""
|
|
return MockConfigEntry(
|
|
entry_id="paperless_ngx_test",
|
|
title="Paperless-ngx",
|
|
domain=DOMAIN,
|
|
data=USER_INPUT,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
async def init_integration(
|
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_paperless: MagicMock
|
|
) -> MockConfigEntry:
|
|
"""Set up the Paperless-ngx integration for testing."""
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
return mock_config_entry
|