Files
core/tests/components/paperless_ngx/conftest.py
T
Florian von Garrel 8c971904ca Add reauth and reconfigure to paperless (#145469)
* Add reauth and reconfigure

* Reauth and reconfigure in different functions

* Add duplicate check

* Add test for reconfigure duplicate

* Removed seconds config entry fixture
2025-05-25 14:03:13 +02:00

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_ONE
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="0KLG00V55WEVTJ0CJHM0GADNGH",
title="Paperless-ngx",
domain=DOMAIN,
data=USER_INPUT_ONE,
)
@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