Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sagemcom_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
UINT_MAX,
XMO_ACCESS_RESTRICTION_ERR,
XMO_AUTHENTICATION_ERR,
XMO_INVALID_PATH_ERR,
XMO_INVALID_SESSION_ERR,
XMO_LOGIN_RETRY_ERR,
XMO_MAX_SESSION_COUNT_ERR,
Expand Down Expand Up @@ -261,7 +262,7 @@ async def __post(self, url, data):
if action_error_desc == XMO_NON_WRITABLE_PARAMETER_ERR:
raise NonWritableParameterException(action_error)

if action_error_desc == XMO_UNKNOWN_PATH_ERR:
if action_error_desc in (XMO_INVALID_PATH_ERR, XMO_UNKNOWN_PATH_ERR):
raise UnknownPathException(action_error)

if action_error_desc == XMO_MAX_SESSION_COUNT_ERR:
Expand Down
1 change: 1 addition & 0 deletions sagemcom_api/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

XMO_ACCESS_RESTRICTION_ERR = "XMO_ACCESS_RESTRICTION_ERR"
XMO_AUTHENTICATION_ERR = "XMO_AUTHENTICATION_ERR"
XMO_INVALID_PATH_ERR = "XMO_INVALID_PATH_ERR"
XMO_INVALID_SESSION_ERR = "XMO_INVALID_SESSION_ERR"
XMO_NON_WRITABLE_PARAMETER_ERR = "XMO_NON_WRITABLE_PARAMETER_ERR"
XMO_NO_ERR = "XMO_NO_ERR"
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def xpath_value_response() -> dict[str, Any]:
return load_fixture("xpath_value.json")


@pytest.fixture
def xpath_invalid_path_response() -> dict[str, Any]:
"""Mock response for an invalid XPath error."""
return load_fixture("xpath_invalid_path.json")


@pytest.fixture
def mock_session_factory():
"""Create a factory for mock aiohttp ClientSession.
Expand Down
32 changes: 32 additions & 0 deletions tests/fixtures/xpath_invalid_path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"reply": {
"uid": 0,
"id": 0,
"error": {
"code": 16777236,
"description": "XMO_REQUEST_ACTION_ERR"
},
"actions": [
{
"uid": 1,
"id": 0,
"error": {
"code": 16777242,
"description": "XMO_INVALID_PATH_ERR"
},
"callbacks": [
{
"uid": 1,
"result": {
"code": 16777242,
"description": "XMO_INVALID_PATH_ERR"
},
"xpath": "Device/Unsupported/Path",
"parameters": {}
}
]
}
],
"events": []
}
}
26 changes: 25 additions & 1 deletion tests/unit/test_client_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from sagemcom_api.client import SagemcomClient
from sagemcom_api.enums import EncryptionMethod
from sagemcom_api.exceptions import AuthenticationException
from sagemcom_api.exceptions import AuthenticationException, UnknownPathException


@pytest.mark.asyncio
Expand Down Expand Up @@ -103,6 +103,30 @@ async def test_get_value_by_xpath_url_encoding(mock_session_factory, login_succe
# will be covered later


@pytest.mark.asyncio
async def test_get_value_by_xpath_invalid_path(mock_session_factory, xpath_invalid_path_response):
"""Test XMO_INVALID_PATH_ERR raises UnknownPathException with error details."""
mock_session = mock_session_factory([xpath_invalid_path_response])
client = SagemcomClient(
host="192.168.1.1",
username="admin",
password="admin",
authentication_method=EncryptionMethod.MD5,
session=mock_session,
)

with pytest.raises(UnknownPathException) as exc_info:
await client.get_value_by_xpath("Device/Unsupported/Path")

assert exc_info.value.args == (
{
"code": 16777242,
"description": "XMO_INVALID_PATH_ERR",
},
)
assert mock_session.post.call_count == 1


@pytest.mark.asyncio
async def test_login_with_preconfigured_fixture(mock_client_sha512):
"""Test login using pre-configured client fixture.
Expand Down