Skip to content

Commit

Permalink
Merge pull request #97 from coreGreenberet/unicode_tests
Browse files Browse the repository at this point in the history
specifing encoding for loading the fake configuration
  • Loading branch information
coreGreenberet authored May 13, 2018
2 parents d421030 + 865547f commit 9df6fd7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 76 deletions.
1 change: 1 addition & 0 deletions homematicip.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="homematicip_cli_async.py" />
<Compile Include="tests\conftest.py" />
<Compile Include="tests\test_misc.py">
<SubType>Code</SubType>
</Compile>
Expand Down
65 changes: 38 additions & 27 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import pytest

from unittest.mock import MagicMock
from homematicip.async.connection import AsyncConnection


def AsyncMock(*args, **kwargs):
m = MagicMock(*args, **kwargs)

async def mock_coro(*args, **kwargs):
return m(*args, **kwargs)

mock_coro.mock = m
return mock_coro


@pytest.fixture
def fake_connection(event_loop):
_connection = AsyncConnection(event_loop)
_connection.api_call = AsyncMock(return_value='called')
return _connection

@pytest.fixture
def async_connection(event_loop):
_connection = AsyncConnection(event_loop)
yield _connection
_connection._websession.close()
import pytest
import json
from unittest.mock import MagicMock
from homematicip.async.connection import AsyncConnection
from homematicip.home import Home
from homematicip.base.base_connection import BaseConnection

def AsyncMock(*args, **kwargs):
m = MagicMock(*args, **kwargs)

async def mock_coro(*args, **kwargs):
return m(*args, **kwargs)

mock_coro.mock = m
return mock_coro

def fake_home_download_configuration():
return json.load(open("tests/json_data/home.json", encoding="UTF-8"))

@pytest.fixture
def fake_home():
home = Home()
home.download_configuration = fake_home_download_configuration
home._connection = BaseConnection()
home.get_current_state()
return home

@pytest.fixture
def fake_connection(event_loop):
_connection = AsyncConnection(event_loop)
_connection.api_call = AsyncMock(return_value='called')
return _connection

@pytest.fixture
def async_connection(event_loop):
_connection = AsyncConnection(event_loop)
yield _connection
_connection._websession.close()
16 changes: 8 additions & 8 deletions tests/json_data/home.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "3014F7110000000000000000",
"label": "Balkont\u00FCre",
"label": "Balkontüre",
"lastStatusUpdate": 1524516526498,
"manufacturerCode": 1,
"modelId": 258,
Expand Down Expand Up @@ -202,7 +202,7 @@
},
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "3014F7110000000000000003",
"label": "K\u00FCche",
"label": "Küche",
"lastStatusUpdate": 1524514836466,
"manufacturerCode": 1,
"modelId": 258,
Expand Down Expand Up @@ -354,7 +354,7 @@
},
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "3014F7110000000000000006",
"label": "Wohnungst\u00FCre",
"label": "Wohnungstüre",
"lastStatusUpdate": 1524516489316,
"manufacturerCode": 1,
"modelId": 258,
Expand Down Expand Up @@ -554,7 +554,7 @@
},
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "3014F7110000000000000010",
"label": "B\u00FCro",
"label": "Büro",
"lastStatusUpdate": 1524513613922,
"manufacturerCode": 1,
"modelId": 262,
Expand Down Expand Up @@ -758,7 +758,7 @@
},
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "3014F7110000000000000014",
"label": "K\u00FCche-Heizung",
"label": "Küche-Heizung",
"lastStatusUpdate": 1524513898337,
"manufacturerCode": 1,
"modelId": 269,
Expand Down Expand Up @@ -1841,7 +1841,7 @@
"humidityLimitEnabled": true,
"humidityLimitValue": 60,
"id": "00000000-0000-0000-0000-000000000010",
"label": "B\u00FCro",
"label": "Büro",
"lastStatusUpdate": 1524516454116,
"lowBat": false,
"maxTemperature": 30.0,
Expand Down Expand Up @@ -1949,7 +1949,7 @@
"dutyCycle": false,
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "00000000-0000-0000-0000-000000000009",
"label": "B\u00FCro",
"label": "Büro",
"lastStatusUpdate": 1524515854304,
"lowBat": false,
"metaGroupId": "00000000-0000-0000-0000-000000000008",
Expand Down Expand Up @@ -2300,7 +2300,7 @@
],
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "00000000-0000-0000-0000-000000000008",
"label": "B\u00FCro",
"label": "Büro",
"lastStatusUpdate": 1524516454116,
"lowBat": false,
"metaGroupId": null,
Expand Down
14 changes: 2 additions & 12 deletions tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@
import json
from datetime import datetime, timedelta, timezone

from conftest import fake_home_download_configuration

dt = datetime.now(timezone.utc).astimezone()
utc_offset = dt.utcoffset() // timedelta(seconds=1)

def fake_home_download_configuration():
return json.load(open("tests/json_data/home.json"))


@pytest.fixture
def fake_home():
home = Home()
home.download_configuration = fake_home_download_configuration
home._connection = BaseConnection()
home.get_current_state()
return home

def test_shutter_device(fake_home):
d = fake_home.search_device_by_id('3014F7110000000000000001')
assert isinstance(d, ShutterContact)
Expand Down
20 changes: 4 additions & 16 deletions tests/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,15 @@

import pytest

from homematicip.home import Home
from homematicip.base.base_connection import BaseConnection
from homematicip.group import *
import json
from datetime import datetime, timedelta, timezone

from conftest import fake_home_download_configuration

dt = datetime.now(timezone.utc).astimezone()
utc_offset = dt.utcoffset() // timedelta(seconds=1)

def fake_home_download_configuration():
return json.load(open("tests/json_data/home.json"))


@pytest.fixture
def fake_home():
home = Home()
home.download_configuration = fake_home_download_configuration
home._connection = BaseConnection()
home.get_current_state()
return home

def test_meta_group(fake_home):
g = fake_home.search_group_by_id('00000000-0000-0000-0000-000000000020')
assert isinstance(g, MetaGroup)
Expand Down Expand Up @@ -106,7 +94,7 @@ def test_security_group(fake_home):
assert g.dutyCycle == False
assert g.homeId == "00000000-0000-0000-0000-000000000001"
assert g.id == "00000000-0000-0000-0000-000000000009"
assert g.label == "B\u00FCro"
assert g.label == "Büro"
assert g.lastStatusUpdate == datetime(2018, 4, 23, 20, 37, 34, 304000) + timedelta(0,utc_offset)
assert g.lowBat == False
assert g.metaGroup.id == "00000000-0000-0000-0000-000000000008"
Expand All @@ -117,7 +105,7 @@ def test_security_group(fake_home):
assert g.unreach == False
assert g.windowState == "CLOSED"

assert str(g) == ('SECURITY B\u00FCro: windowState(CLOSED) motionDetected(None) presenceDetected(None) sabotage(False)'
assert str(g) == ('SECURITY Büro: windowState(CLOSED) motionDetected(None) presenceDetected(None) sabotage(False)'
' smokeDetectorAlarmType(IDLE_OFF) dutyCycle(False) lowBat(False)')

def test_switching_group(fake_home):
Expand Down
15 changes: 2 additions & 13 deletions tests/test_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@
from homematicip.EventHook import EventHook
import json
from datetime import datetime, timedelta, timezone
from conftest import fake_home_download_configuration


dt = datetime.now(timezone.utc).astimezone()
utc_offset = dt.utcoffset() // timedelta(seconds=1)

def fake_home_download_configuration():
return json.load(open("tests/json_data/home.json"))


@pytest.fixture
def fake_home():
home = Home()
home.download_configuration = fake_home_download_configuration
home._connection = BaseConnection()
home.get_current_state()
return home


def test_update_event(fake_home: Home):
fake_handler = Mock()
fake_home.on_update(fake_handler.method)
Expand Down

0 comments on commit 9df6fd7

Please sign in to comment.