Skip to content

Commit

Permalink
Fix empty ports response (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 authored Mar 7, 2024
1 parent fba10ee commit 1601719
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion axis/vapix/models/port_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def decode(cls, bytes_data: bytes) -> Self:
api_version=data["apiVersion"],
context=data["context"],
method=data["method"],
data=Port.decode_to_dict(data["data"]["items"]),
data=Port.decode_to_dict(data["data"].get("items", [])),
)


Expand Down
17 changes: 17 additions & 0 deletions tests/test_port_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ async def test_get_ports(respx_mock, io_port_management):
}


async def test_get_empty_ports_response(respx_mock, io_port_management):
"""Test get_ports call."""
respx_mock.post("/axis-cgi/io/portmanagement.cgi").respond(
json=GET_EMPTY_PORTS_RESPONSE,
)
await io_port_management.update()
assert io_port_management.initialized
assert len(io_port_management.values()) == 0


async def test_set_ports(respx_mock, io_port_management):
"""Test set_ports call."""
route = respx_mock.post("/axis-cgi/io/portmanagement.cgi")
Expand Down Expand Up @@ -171,6 +181,13 @@ async def test_get_supported_versions(respx_mock, io_port_management):
},
}

GET_EMPTY_PORTS_RESPONSE = {
"apiVersion": "1.0",
"context": "Axis library",
"method": "getPorts",
"data": {"numberOfPorts": 0},
}

GET_SUPPORTED_VERSIONS_RESPONSE = {
"apiVersion": "1.0",
"context": "",
Expand Down

0 comments on commit 1601719

Please sign in to comment.