conftest.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import pytest
  2. from unittest.mock import AsyncMock
  3. from pytest_homeassistant_custom_component.common import MockConfigEntry
  4. from custom_components.zlock_slots.const import DOMAIN, CONF_LOCK_ENTITY_IDS
  5. pytest_plugins = ["pytest_homeassistant_custom_component"]
  6. LOCK_ENTITY_ID = "lock.front_door"
  7. ALARM_TYPE_ENTITY = "sensor.front_door_alarm_type"
  8. ALARM_LEVEL_ENTITY = "sensor.front_door_alarm_level"
  9. class FakeUserData:
  10. def __init__(self, user_id: int, active: bool = True):
  11. self.user_id = user_id
  12. self.active = active
  13. class FakeAccessControl:
  14. def __init__(self, users=None):
  15. self._users = list(users or [])
  16. self.set_user = AsyncMock()
  17. async def get_users_cached(self):
  18. return list(self._users)
  19. class FakeNode:
  20. def __init__(self, users=None):
  21. self.access_control = FakeAccessControl(users)
  22. @pytest.fixture(autouse=True)
  23. def auto_enable_custom_integrations(enable_custom_integrations):
  24. yield
  25. @pytest.fixture
  26. def mock_node():
  27. return FakeNode(users=[
  28. FakeUserData(1, active=True),
  29. FakeUserData(2, active=False),
  30. ])
  31. @pytest.fixture
  32. def config_entry():
  33. return MockConfigEntry(
  34. domain=DOMAIN,
  35. data={CONF_LOCK_ENTITY_IDS: [LOCK_ENTITY_ID]},
  36. options={},
  37. entry_id="test_entry",
  38. )