Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
- Fix types
- Add mock token value
  • Loading branch information
jason0x43 committed Jun 14, 2020
1 parent 763d2ad commit a722340
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 28 deletions.
Empty file added stubs/asynctest/__init__.pyi
Empty file.
2 changes: 2 additions & 0 deletions stubs/asynctest/mock/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from unittest.mock import *
from unittest.mock import Mock as CoroutineMock
7 changes: 0 additions & 7 deletions tests/async_mock.py

This file was deleted.

14 changes: 14 additions & 0 deletions tests/async_mock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys

if sys.version_info[:2] < (3, 8):
from asynctest.mock import (
Mock,
NonCallableMock,
CoroutineMock as AsyncMock,
call,
patch,
)
else:
from unittest.mock import Mock, NonCallableMock, call, patch

__all__ = ["Mock", "AsyncMock", "NonCallableMock", "call", "patch"]
File renamed without changes.
5 changes: 2 additions & 3 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
from homeassistant.core import HomeAssistant

from tests.async_mock import Mock, NonCallableMock, call, patch
from tests.types import GetHub


@patch("custom_components.hubitat.entities.get_hub")
@patch("custom_components.hubitat.entities.entity_registry")
async def test_entity_migration(get_hub: GetHub, entity_registry) -> None:
async def test_entity_migration(get_hub: Mock, entity_registry: Mock) -> None:
mock_device_1 = NonCallableMock(type="switch", attributes=["state"])
mock_device_2 = NonCallableMock(type="fan", attributes=["state"])
MockHub = Mock(spec=Hub)
Expand Down Expand Up @@ -63,7 +62,7 @@ def _is_switch(device: Device) -> bool:

@patch("custom_components.hubitat.entities.get_hub")
@patch("custom_components.hubitat.entities.HubitatEventEmitter")
async def test_add_event_emitters(HubitatEventEmitter, get_hub) -> None:
async def test_add_event_emitters(HubitatEventEmitter: Mock, get_hub: Mock) -> None:
mock_device_1 = NonCallableMock(type="switch", attributes=["state"])
mock_device_2 = NonCallableMock(type="button", attributes=["state"])
MockHub = Mock(spec=Hub)
Expand Down
44 changes: 26 additions & 18 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
from hubitatmaker.const import ATTR_LOCK_CODES
from hubitatmaker.types import Attribute

from tests.async_mock import MagicMock
from tests.async_mock import Mock


def test_normal_lock_codes() -> None:
hub = MagicMock()
device = MagicMock()
device.attributes = {
ATTR_LOCK_CODES: Attribute(
{
"name": ATTR_LOCK_CODES,
"currentValue": '{"1":{"name":"Test","code":"1234"}}',
}
)
}
hub = Mock()
hub.configure_mock(token="abc1235Qbxyz")

device = Mock()
device.configure_mock(
attributes={
ATTR_LOCK_CODES: Attribute(
{
"name": ATTR_LOCK_CODES,
"currentValue": '{"1":{"name":"Test","code":"1234"}}',
}
)
}
)

from custom_components.hubitat.lock import HubitatLock

Expand All @@ -23,13 +27,17 @@ def test_normal_lock_codes() -> None:


def test_encrypted_lock_codes() -> None:
hub = MagicMock()
device = MagicMock()
device.attributes = {
ATTR_LOCK_CODES: Attribute(
{"name": ATTR_LOCK_CODES, "currentValue": "abc1235Qbxyz"}
)
}
hub = Mock()
hub.configure_mock(token="abc1235Qbxyz")

device = Mock()
device.configure_mock(
attributes={
ATTR_LOCK_CODES: Attribute(
{"name": ATTR_LOCK_CODES, "currentValue": "abc1235Qbxyz"}
)
}
)

from custom_components.hubitat.lock import HubitatLock

Expand Down

0 comments on commit a722340

Please sign in to comment.