From 865547fb030cdce69989105f1e932e61090ad48a Mon Sep 17 00:00:00 2001 From: coreGreenberet Date: Sun, 13 May 2018 09:54:03 +0200 Subject: [PATCH] specifing encoding for loading the fake configuration --- homematicip.pyproj | 1 + tests/conftest.py | 65 +++++++++++++++++++++++---------------- tests/json_data/home.json | 16 +++++----- tests/test_devices.py | 14 ++------- tests/test_groups.py | 20 +++--------- tests/test_home.py | 15 ++------- 6 files changed, 55 insertions(+), 76 deletions(-) diff --git a/homematicip.pyproj b/homematicip.pyproj index 47ce81ee..076a4ac2 100644 --- a/homematicip.pyproj +++ b/homematicip.pyproj @@ -79,6 +79,7 @@ Code + Code diff --git a/tests/conftest.py b/tests/conftest.py index eb71b137..343b7569 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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() diff --git a/tests/json_data/home.json b/tests/json_data/home.json index 45d1a7e1..bba7e8e1 100644 --- a/tests/json_data/home.json +++ b/tests/json_data/home.json @@ -49,7 +49,7 @@ }, "homeId": "00000000-0000-0000-0000-000000000001", "id": "3014F7110000000000000000", - "label": "Balkont\u00FCre", + "label": "Balkontüre", "lastStatusUpdate": 1524516526498, "manufacturerCode": 1, "modelId": 258, @@ -202,7 +202,7 @@ }, "homeId": "00000000-0000-0000-0000-000000000001", "id": "3014F7110000000000000003", - "label": "K\u00FCche", + "label": "Küche", "lastStatusUpdate": 1524514836466, "manufacturerCode": 1, "modelId": 258, @@ -354,7 +354,7 @@ }, "homeId": "00000000-0000-0000-0000-000000000001", "id": "3014F7110000000000000006", - "label": "Wohnungst\u00FCre", + "label": "Wohnungstüre", "lastStatusUpdate": 1524516489316, "manufacturerCode": 1, "modelId": 258, @@ -554,7 +554,7 @@ }, "homeId": "00000000-0000-0000-0000-000000000001", "id": "3014F7110000000000000010", - "label": "B\u00FCro", + "label": "Büro", "lastStatusUpdate": 1524513613922, "manufacturerCode": 1, "modelId": 262, @@ -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, @@ -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, @@ -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", @@ -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, diff --git a/tests/test_devices.py b/tests/test_devices.py index 6af589c6..bc33a234 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -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) diff --git a/tests/test_groups.py b/tests/test_groups.py index 8d8f0138..a5ee2890 100644 --- a/tests/test_groups.py +++ b/tests/test_groups.py @@ -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) @@ -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" @@ -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): diff --git a/tests/test_home.py b/tests/test_home.py index c1439790..46d789f7 100644 --- a/tests/test_home.py +++ b/tests/test_home.py @@ -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)