Skip to content

Commit

Permalink
tests: replace custom MockConfigEntry with the official `hass.MockCon…
Browse files Browse the repository at this point in the history
…figEntry` (#105)
  • Loading branch information
palazzem authored Nov 3, 2023
1 parent 77beef0 commit 95cc159
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ repos:
rev: v1.5.1
hooks:
- id: mypy
exclude: tests/hass/
exclude: tests/|tests/hass/
additional_dependencies: [types-requests]
30 changes: 14 additions & 16 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

from custom_components.econnect_metronet import async_setup
from custom_components.econnect_metronet.alarm_control_panel import EconnectAlarm
from custom_components.econnect_metronet.config_flow import EconnectConfigFlow
from custom_components.econnect_metronet.const import DOMAIN
from custom_components.econnect_metronet.coordinator import AlarmCoordinator
from custom_components.econnect_metronet.devices import AlarmDevice

from .fixtures import responses as r
from .helpers import MockConfigEntry

pytest_plugins = ["tests.hass.fixtures"]

Expand Down Expand Up @@ -141,19 +143,15 @@ def config_entry():
This config entry is designed to emulate the behavior of a real config entry for
testing purposes.
"""

class MockConfigEntry:
def __init__(self):
# Config at install-time
self.data = {
"username": "test_user",
"password": "test_password",
"system_base_url": "https://example.com",
"domain": "econnect_metronet",
}

# Options at configuration-time
self.entry_id = "test_entry_id"
self.options = {}

return MockConfigEntry()
return MockConfigEntry(
version=EconnectConfigFlow.VERSION,
domain=DOMAIN,
entry_id="test_entry_id",
options={},
data={
"username": "test_user",
"password": "test_password",
"domain": "econnect_metronet",
"system_base_url": "https://example.com",
},
)
11 changes: 11 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
from .hass.common import MockConfigEntry as BaseMockConfigEntry


class MockConfigEntry(BaseMockConfigEntry):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Make settings overridable
self.data = kwargs.get("data", {})
self.options = kwargs.get("options", {})


def _(mock_path: str) -> str:
"""Helper to simplify Mock path strings.
Expand Down

0 comments on commit 95cc159

Please sign in to comment.