Skip to content

Commit e586de1

Browse files
committed
Update tests.
1 parent 2a99342 commit e586de1

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

tests/test_api.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,29 @@ async def test_write_parameter(api):
350350
assert unk_param not in list(deconz_api.NetworkParameter)
351351
with pytest.raises(KeyError):
352352
await api.write_parameter(unk_param, 0x55aa)
353+
354+
355+
@pytest.mark.parametrize(
356+
"protocol_ver, firmware_version, flags",
357+
[
358+
(0x010A, 0x123405dd, 0x01),
359+
(0x010B, 0x123405dd, 0x04),
360+
(0x010A, 0x123407dd, 0x01),
361+
(0x010B, 0x123407dd, 0x01),
362+
],
363+
)
364+
@pytest.mark.asyncio
365+
async def test_version(protocol_ver, firmware_version, flags, api):
366+
api.read_parameter = mock.MagicMock()
367+
api.read_parameter.side_effect = asyncio.coroutine(
368+
mock.MagicMock(return_value=protocol_ver))
369+
api._command = mock.MagicMock()
370+
api._command.side_effect = asyncio.coroutine(
371+
mock.MagicMock(return_value=[firmware_version]))
372+
r = await api.version()
373+
assert r == firmware_version
374+
assert api._aps_data_ind_flags == flags
375+
376+
377+
def test_handle_version(api):
378+
api._handle_version([mock.sentinel.version])

tests/test_application.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ def addr_nwk(nwk):
4646
return addr
4747

4848

49+
@pytest.fixture
50+
def addr_nwk_and_ieee(nwk, ieee):
51+
addr = t.DeconzAddress()
52+
addr.address_mode = t.ADDRESS_MODE.NWK_AND_IEEE
53+
addr.address = nwk
54+
addr.ieee = ieee
55+
return addr
56+
57+
4958
def _test_rx(app, addr_ieee, addr_nwk, device, data):
5059
app.get_device = mock.MagicMock(return_value=device)
5160
app.devices = (EUI64(addr_ieee.address), )
@@ -96,6 +105,23 @@ def test_rx_ieee(app, addr_ieee, addr_nwk):
96105
)
97106

98107

108+
def test_rx_nwk_ieee(app, addr_ieee, addr_nwk_and_ieee):
109+
device = mock.MagicMock()
110+
app.handle_message = mock.MagicMock()
111+
_test_rx(app, addr_ieee, addr_nwk_and_ieee, device, mock.sentinel.args)
112+
assert app.handle_message.call_count == 1
113+
assert app.handle_message.call_args == (
114+
(
115+
device,
116+
mock.sentinel.profile_id,
117+
mock.sentinel.cluster_id,
118+
mock.sentinel.src_ep,
119+
mock.sentinel.dst_ep,
120+
mock.sentinel.args,
121+
),
122+
)
123+
124+
99125
def test_rx_wrong_addr_mode(app, addr_ieee, addr_nwk, caplog):
100126
device = mock.MagicMock()
101127
app.handle_message = mock.MagicMock()
@@ -160,7 +186,7 @@ async def test_form_network(app):
160186
async def test_startup(app, monkeypatch, version=0):
161187

162188
async def _version():
163-
return [version]
189+
return version
164190

165191
app.form_network = mock.MagicMock(
166192
side_effect=asyncio.coroutine(mock.MagicMock()))

0 commit comments

Comments
 (0)