Skip to content

Commit dd55b52

Browse files
authored
Merge pull request #14 from 2Fake/development
Fix #12
2 parents bcae1ea + 73f37a6 commit dd55b52

File tree

4 files changed

+54
-42
lines changed

4 files changed

+54
-42
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
"Operating System :: OS Independent",
2323
],
2424
install_requires=[
25-
"httpx>=0.14,<0.15",
25+
"httpx>=0.14,<0.17",
2626
"protobuf",
2727
"zeroconf>=0.27.0",
2828
],
2929
setup_requires=[
3030
"pytest-runner"
3131
],
3232
tests_require=[
33-
"asynctest",
33+
"asynctest;python_version<'3.8'",
3434
"pytest",
3535
"pytest-asyncio",
3636
"pytest-cov",

tests/test_device.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44

55
import pytest
66
import zeroconf
7-
from asynctest import CoroutineMock
7+
8+
try:
9+
from unittest.mock import AsyncMock
10+
except ImportError:
11+
from asynctest import CoroutineMock as AsyncMock
812

913
from devolo_plc_api.device_api.deviceapi import DeviceApi
10-
from devolo_plc_api.plcnet_api.plcnetapi import PlcNetApi
1114
from devolo_plc_api.exceptions.device import DeviceNotFound
15+
from devolo_plc_api.plcnet_api.plcnetapi import PlcNetApi
1216

1317

1418
class TestDevice:
1519

1620
@pytest.mark.asyncio
1721
async def test__gather_apis(self, mocker, mock_device):
18-
with patch("devolo_plc_api.device.Device._get_device_info", new=CoroutineMock()), \
19-
patch("devolo_plc_api.device.Device._get_plcnet_info", new=CoroutineMock()):
22+
with patch("devolo_plc_api.device.Device._get_device_info", new=AsyncMock()), \
23+
patch("devolo_plc_api.device.Device._get_plcnet_info", new=AsyncMock()):
2024
spy_device_info = mocker.spy(mock_device, "_get_device_info")
2125
spy_plcnet_info = mocker.spy(mock_device, "_get_plcnet_info")
2226
await mock_device._gather_apis()
@@ -27,7 +31,7 @@ async def test__gather_apis(self, mocker, mock_device):
2731
@pytest.mark.asyncio
2832
@pytest.mark.usefixtures("mock_device_api")
2933
async def test__get_device_info(self, mock_device):
30-
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()):
34+
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=AsyncMock()):
3135
device_info = self.device_info['_dvl-deviceapi._tcp.local.']
3236
await mock_device._get_device_info()
3337

@@ -41,15 +45,15 @@ async def test__get_device_info(self, mock_device):
4145
@pytest.mark.asyncio
4246
@pytest.mark.usefixtures("mock_device_api")
4347
async def test__get_device_info_timeout(self, mock_device):
44-
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()), \
45-
patch("asyncio.wait_for", new=CoroutineMock(side_effect=asyncio.TimeoutError())), \
48+
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=AsyncMock()), \
49+
patch("asyncio.wait_for", new=AsyncMock(side_effect=asyncio.TimeoutError())), \
4650
pytest.raises(DeviceNotFound):
4751
await mock_device._get_device_info()
4852

4953
@pytest.mark.asyncio
5054
@pytest.mark.usefixtures("mock_plcnet_api")
5155
async def test__get_plcnet_info(self, mock_device):
52-
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()):
56+
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=AsyncMock()):
5357
device_info = self.device_info['_dvl-plcnetapi._tcp.local.']
5458
await mock_device._get_plcnet_info()
5559

@@ -60,8 +64,8 @@ async def test__get_plcnet_info(self, mock_device):
6064
@pytest.mark.asyncio
6165
@pytest.mark.usefixtures("mock_device_api")
6266
async def test__get_plcnet_info_timeout(self, mock_device):
63-
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()), \
64-
patch("asyncio.wait_for", new=CoroutineMock(side_effect=asyncio.TimeoutError())), \
67+
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=AsyncMock()), \
68+
patch("asyncio.wait_for", new=AsyncMock(side_effect=asyncio.TimeoutError())), \
6569
pytest.raises(DeviceNotFound):
6670
await mock_device._get_plcnet_info()
6771

tests/test_deviceapi.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from unittest.mock import patch
22

33
import pytest
4-
from asynctest import CoroutineMock
54
from google.protobuf.json_format import MessageToDict
65
from httpx import AsyncClient, Client, Response
76

7+
try:
8+
from unittest.mock import AsyncMock
9+
except ImportError:
10+
from asynctest import CoroutineMock as AsyncMock
11+
812
from devolo_plc_api.device_api.deviceapi import DeviceApi
913
from devolo_plc_api.device_api.devolo_idl_proto_deviceapi_ledsettings_pb2 import LedSettingsGet, LedSettingsSetResponse
1014
from devolo_plc_api.device_api.devolo_idl_proto_deviceapi_wifinetwork_pb2 import (
@@ -31,8 +35,8 @@ def test_unsupported_feature(self, request):
3135
async def test_async_get_led_setting(self, request):
3236
led_setting_get = LedSettingsGet()
3337

34-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
35-
patch("httpx.Response.aread", new=CoroutineMock(return_value=led_setting_get.SerializeToString())):
38+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
39+
patch("httpx.Response.aread", new=AsyncMock(return_value=led_setting_get.SerializeToString())):
3640
device_api = DeviceApi(request.cls.ip,
3741
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
3842
AsyncClient(),
@@ -68,8 +72,8 @@ def test_get_led_setting(self, request):
6872
async def test_async_set_led_setting(self, request):
6973
led_setting_set = LedSettingsSetResponse()
7074

71-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=CoroutineMock(return_value=Response)), \
72-
patch("httpx.Response.aread", new=CoroutineMock(return_value=led_setting_set.SerializeToString())):
75+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=AsyncMock(return_value=Response)), \
76+
patch("httpx.Response.aread", new=AsyncMock(return_value=led_setting_set.SerializeToString())):
7377
device_api = DeviceApi(request.cls.ip,
7478
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
7579
AsyncClient(),
@@ -99,8 +103,8 @@ def test_set_led_setting(self, request):
99103
async def test_async_check_firmware_available(self, request):
100104
firmware_available = UpdateFirmwareCheck()
101105

102-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
103-
patch("httpx.Response.aread", new=CoroutineMock(return_value=firmware_available.SerializeToString())):
106+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
107+
patch("httpx.Response.aread", new=AsyncMock(return_value=firmware_available.SerializeToString())):
104108
device_api = DeviceApi(request.cls.ip,
105109
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
106110
AsyncClient(),
@@ -136,8 +140,8 @@ def test_check_firmware_available(self, request):
136140
async def test_async_start_firmware_update(self, request):
137141
firmware_update = UpdateFirmwareStart()
138142

139-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
140-
patch("httpx.Response.aread", new=CoroutineMock(return_value=firmware_update.SerializeToString())):
143+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
144+
patch("httpx.Response.aread", new=AsyncMock(return_value=firmware_update.SerializeToString())):
141145
device_api = DeviceApi(request.cls.ip,
142146
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
143147
AsyncClient(),
@@ -167,8 +171,8 @@ def test_start_firmware_update(self, request):
167171
async def test_async_get_wifi_connected_station(self, request):
168172
wifi_connected_stations_get = WifiConnectedStationsGet()
169173

170-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
171-
patch("httpx.Response.aread", new=CoroutineMock(return_value=wifi_connected_stations_get.SerializeToString())):
174+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
175+
patch("httpx.Response.aread", new=AsyncMock(return_value=wifi_connected_stations_get.SerializeToString())):
172176
device_api = DeviceApi(request.cls.ip,
173177
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
174178
AsyncClient(),
@@ -204,8 +208,8 @@ def test_get_wifi_connected_station(self, request):
204208
async def test_async_get_wifi_guest_access(self, request):
205209
wifi_guest_access_get = WifiGuestAccessGet()
206210

207-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
208-
patch("httpx.Response.aread", new=CoroutineMock(return_value=wifi_guest_access_get.SerializeToString())):
211+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
212+
patch("httpx.Response.aread", new=AsyncMock(return_value=wifi_guest_access_get.SerializeToString())):
209213
device_api = DeviceApi(request.cls.ip,
210214
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
211215
AsyncClient(),
@@ -241,8 +245,8 @@ def test_get_wifi_guest_access(self, request):
241245
async def test_async_set_wifi_guest_access(self, request):
242246
wifi_guest_access_set = WifiGuestAccessSetResponse()
243247

244-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=CoroutineMock(return_value=Response)), \
245-
patch("httpx.Response.aread", new=CoroutineMock(return_value=wifi_guest_access_set.SerializeToString())):
248+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=AsyncMock(return_value=Response)), \
249+
patch("httpx.Response.aread", new=AsyncMock(return_value=wifi_guest_access_set.SerializeToString())):
246250
device_api = DeviceApi(request.cls.ip,
247251
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
248252
AsyncClient(),
@@ -272,8 +276,8 @@ def test_set_wifi_guest_access(self, request):
272276
async def test_async_get_wifi_neighbor_access_points(self, request):
273277
wifi_neighbor_accesspoints_get = WifiNeighborAPsGet()
274278

275-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
276-
patch("httpx.Response.aread", new=CoroutineMock(return_value=wifi_neighbor_accesspoints_get.SerializeToString())):
279+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
280+
patch("httpx.Response.aread", new=AsyncMock(return_value=wifi_neighbor_accesspoints_get.SerializeToString())):
277281
device_api = DeviceApi(request.cls.ip,
278282
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
279283
AsyncClient(),
@@ -309,8 +313,8 @@ def test_get_wifi_neighbor_access_points(self, request):
309313
async def test_async_get_wifi_repeated_access_points(self, request):
310314
wifi_repeated_accesspoints_get = WifiRepeatedAPsGet()
311315

312-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
313-
patch("httpx.Response.aread", new=CoroutineMock(return_value=wifi_repeated_accesspoints_get.SerializeToString())):
316+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
317+
patch("httpx.Response.aread", new=AsyncMock(return_value=wifi_repeated_accesspoints_get.SerializeToString())):
314318
device_api = DeviceApi(request.cls.ip,
315319
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
316320
AsyncClient(),
@@ -346,8 +350,8 @@ def test_get_wifi_repeated_access_points(self, request):
346350
async def test_async_start_wps(self, request):
347351
wps = WifiWpsPbcStart()
348352

349-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
350-
patch("httpx.Response.aread", new=CoroutineMock(return_value=wps.SerializeToString())):
353+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
354+
patch("httpx.Response.aread", new=AsyncMock(return_value=wps.SerializeToString())):
351355
device_api = DeviceApi(request.cls.ip,
352356
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
353357
AsyncClient(),

tests/test_plcnetapi.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from unittest.mock import patch
22

33
import pytest
4-
from asynctest import CoroutineMock
54
from google.protobuf.json_format import MessageToDict
65
from httpx import AsyncClient, Client, Response
76

7+
try:
8+
from unittest.mock import AsyncMock
9+
except ImportError:
10+
from asynctest import CoroutineMock as AsyncMock
11+
812
from devolo_plc_api.plcnet_api.devolo_idl_proto_plcnetapi_getnetworkoverview_pb2 import GetNetworkOverview
913
from devolo_plc_api.plcnet_api.devolo_idl_proto_plcnetapi_identifydevice_pb2 import IdentifyDeviceResponse
1014
from devolo_plc_api.plcnet_api.devolo_idl_proto_plcnetapi_setuserdevicename_pb2 import SetUserDeviceNameResponse
@@ -17,8 +21,8 @@ class TestDeviceApi:
1721
async def test_async_get_network_overview(self, request):
1822
network_overview = GetNetworkOverview()
1923

20-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
21-
patch("httpx.Response.aread", new=CoroutineMock(return_value=network_overview.SerializeToString())):
24+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
25+
patch("httpx.Response.aread", new=AsyncMock(return_value=network_overview.SerializeToString())):
2226
plcnet_api = PlcNetApi(request.cls.ip,
2327
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
2428
AsyncClient(),
@@ -52,8 +56,8 @@ def test_get_network_overview(self, request):
5256
async def test_async_identify_device_start(self, request):
5357
identify_device = IdentifyDeviceResponse()
5458

55-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=CoroutineMock(return_value=Response)), \
56-
patch("httpx.Response.aread", new=CoroutineMock(return_value=identify_device.SerializeToString())):
59+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=AsyncMock(return_value=Response)), \
60+
patch("httpx.Response.aread", new=AsyncMock(return_value=identify_device.SerializeToString())):
5761
plcnet_api = PlcNetApi(request.cls.ip,
5862
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
5963
Client(),
@@ -81,8 +85,8 @@ def test_identify_device_start(self, request):
8185
async def test_async_identify_device_stop(self, request):
8286
identify_device = IdentifyDeviceResponse()
8387

84-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=CoroutineMock(return_value=Response)), \
85-
patch("httpx.Response.aread", new=CoroutineMock(return_value=identify_device.SerializeToString())):
88+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=AsyncMock(return_value=Response)), \
89+
patch("httpx.Response.aread", new=AsyncMock(return_value=identify_device.SerializeToString())):
8690
plcnet_api = PlcNetApi(request.cls.ip,
8791
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
8892
Client(),
@@ -110,8 +114,8 @@ def test_identify_device_stop(self, request):
110114
async def test_async_set_user_device_name(self, request):
111115
user_device_name_set = SetUserDeviceNameResponse()
112116

113-
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=CoroutineMock(return_value=Response)), \
114-
patch("httpx.Response.aread", new=CoroutineMock(return_value=user_device_name_set.SerializeToString())):
117+
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=AsyncMock(return_value=Response)), \
118+
patch("httpx.Response.aread", new=AsyncMock(return_value=user_device_name_set.SerializeToString())):
115119
plcnet_api = PlcNetApi(request.cls.ip,
116120
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Port'],
117121
Client(),

0 commit comments

Comments
 (0)