Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman committed Mar 22, 2024
1 parent 55121ed commit cf0341f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<u:DeletePortMappingResponse xmlns:u0="urn:schemas-upnp-org:service:WANIPConnection:1">
</u:DeletePortMappingResponse>
</s:Body>
</s:Envelope>
38 changes: 35 additions & 3 deletions tests/test_upnp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,14 @@ async def test_parse_response_no_service_type_version_2(self) -> None:

@pytest.mark.asyncio
async def test_unknown_out_argument(self) -> None:
"""Test calling an actino and handling an unknown out-argument."""
"""Test calling an action and handling an unknown out-argument."""
requester = UpnpTestRequester(RESPONSE_MAP)
link_service = "http://dlna_dmr:1234/device.xml"
device_url = "http://dlna_dmr:1234/device.xml"
service_type = "urn:schemas-upnp-org:service:RenderingControl:1"
test_action = "GetVolume"

factory = UpnpFactory(requester)
device = await factory.async_create_device(link_service)
device = await factory.async_create_device(device_url)
service = device.service(service_type)
action = service.action(test_action)

Expand All @@ -549,6 +549,38 @@ async def test_unknown_out_argument(self) -> None:
except UpnpError:
pass

factory = UpnpFactory(requester, non_strict=True)
device = await factory.async_create_device(device_url)
service = device.service(service_type)
action = service.action(test_action)

try:
action.parse_response(service_type, {}, response)
except UpnpError:
assert False

@pytest.mark.asyncio
async def test_response_invalid_xml_namespaces(self) -> None:
"""Test parsing response with invalid XML namespaces."""
requester = UpnpTestRequester(RESPONSE_MAP)
device_url = "http://igd:1234/device.xml"
service_type = "urn:schemas-upnp-org:service:RenderingControl:1"
test_action = "DeletePortMapping"

# Test strict mode.
factory = UpnpFactory(requester)
device = await factory.async_create_device(device_url)
service = device.service(service_type)
action = service.action(test_action)

response = read_file("igd/action_WANPIPConnection_DeletePortMapping.xml")
try:
action.parse_response(service_type, {}, response)
assert False
except UpnpError:
pass

# Test non-strict mode.
factory = UpnpFactory(requester, non_strict=True)
device = await factory.async_create_device(link_service)
service = device.service(service_type)
Expand Down

0 comments on commit cf0341f

Please sign in to comment.