hass-core/tests/components/discovergy/conftest.py
Jan-Philipp Benecke 7d0f5733c2
Improve the code quality of the Discovergy integration (#94165)
* Remove option flow, refactor and improve the code quality after review in PR #54280

* Remove coordinator.py from coverage report

* Some minor improvements for unit tests

* Remove _LOGGER

* Use pytest.fixture and some more improvments

* Add back empty __init__

* Fix docstring

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-06-11 12:51:43 +02:00

33 lines
1,000 B
Python

"""Fixtures for Discovergy integration tests."""
from unittest.mock import AsyncMock, Mock, patch
import pytest
from homeassistant.components.discovergy import DOMAIN
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
from tests.components.discovergy.const import GET_METERS
@pytest.fixture
def mock_meters() -> Mock:
"""Patch libraries."""
with patch("pydiscovergy.Discovergy.get_meters") as discovergy:
discovergy.side_effect = AsyncMock(return_value=GET_METERS)
yield discovergy
@pytest.fixture
async def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Return a MockConfigEntry for testing."""
entry = MockConfigEntry(
domain=DOMAIN,
title="user@example.org",
unique_id="user@example.org",
data={CONF_EMAIL: "user@example.org", CONF_PASSWORD: "supersecretpassword"},
)
entry.add_to_hass(hass)
return entry