summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py1
-rw-r--r--tests/discoverables/test_yamaha.py126
-rw-r--r--tests/discoverables/yamaha_files/desc_RX-V481.xml92
-rw-r--r--tests/discoverables/yamaha_files/desc_incompatible_device.xml26
-rw-r--r--tests/discoverables/yamaha_files/desc_multiple_services_no_remote_control.xml25
-rw-r--r--tests/discoverables/yamaha_files/desc_multiple_services_remote_control_last.xml25
-rw-r--r--tests/discoverables/yamaha_files/desc_single_service.xml22
-rw-r--r--tests/test_xboxone.py60
-rw-r--r--tests/xboxone_files/discovery_responsebin0 -> 586 bytes
9 files changed, 377 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..05fea2a
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1 @@
+"""Tests for NetDisco."""
diff --git a/tests/discoverables/test_yamaha.py b/tests/discoverables/test_yamaha.py
new file mode 100644
index 0000000..6b51b96
--- /dev/null
+++ b/tests/discoverables/test_yamaha.py
@@ -0,0 +1,126 @@
+"""The tests for discovering Yamaha Receivers."""
+import unittest
+from unittest.mock import MagicMock
+import xml.etree.ElementTree as ElementTree
+
+from netdisco.discoverables.yamaha import Discoverable
+from netdisco.util import etree_to_dict
+
+LOCATION = 'http://192.168.XXX.XXX:80/desc.xml'
+
+
+class MockUPNPEntry(object):
+ """UPNPEntry backed by a description file."""
+
+ location = LOCATION
+
+ def __init__(self, name):
+ """Read and parse a MockUPNPEntry from a file."""
+ with open('tests/discoverables/yamaha_files/%s' % name,
+ encoding='utf-8') as content:
+ self.description = etree_to_dict(
+ ElementTree.fromstring(content.read())).get('root', {})
+
+
+class TestYamaha(unittest.TestCase):
+ """Test the Yamaha Discoverable."""
+
+ def test_info_from_entry_rx_v481(self):
+ self.assertEqual(
+ Discoverable(None).info_from_entry(
+ MockUPNPEntry("desc_RX-V481.xml")),
+ {
+ 'control_url':
+ 'http://192.168.XXX.XXX:80/YamahaRemoteControl/ctrl',
+ 'description_url':
+ 'http://192.168.XXX.XXX:80/YamahaRemoteControl/desc.xml',
+ 'host': '192.168.xxx.xxx',
+ 'model_name': 'RX-V481',
+ 'model_number': 'V481',
+ 'manufacturer': 'Yamaha Corporation',
+ 'name': 'RX-V481 XXXXXX',
+ 'port': 80,
+ 'serial': 'XXXXXXXX',
+ 'ssdp_description': 'http://192.168.XXX.XXX:80/desc.xml',
+ 'udn': 'uuid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
+ 'upnp_device_type':
+ 'urn:schemas-upnp-org:device:MediaRenderer:1',
+ })
+
+ def test_info_from_entry_single_service(self):
+ self.assertEqual(
+ Discoverable(None).info_from_entry(
+ MockUPNPEntry("desc_single_service.xml")),
+ {
+ 'control_url':
+ 'http://192.168.1.2:80/YamahaRemoteControl/single_ctrl',
+ 'description_url':
+ 'http://192.168.1.2:80/YamahaRemoteControl/single_desc.xml',
+ 'host': '192.168.xxx.xxx',
+ 'model_name': 'single service model name',
+ 'model_number': None,
+ 'manufacturer': None,
+ 'name': 'single service friendly name',
+ 'port': 80,
+ 'serial': None,
+ 'ssdp_description': 'http://192.168.XXX.XXX:80/desc.xml',
+ 'udn': None,
+ 'upnp_device_type': None,
+ })
+
+ def test_info_from_entry_multiple_services_remote_control_last(self):
+ self.assertEqual(
+ Discoverable(None).info_from_entry(MockUPNPEntry(
+ "desc_multiple_services_remote_control_last.xml")),
+ {
+ 'control_url':
+ 'http://192.168.1.2:80/YamahaRemoteControl/multi_ctrl',
+ 'description_url':
+ 'http://192.168.1.2:80/YamahaRemoteControl/multi_desc.xml',
+ 'host': '192.168.xxx.xxx',
+ 'model_name': 'multi service model name',
+ 'model_number': None,
+ 'manufacturer': None,
+ 'name': 'multi service friendly name',
+ 'port': 80,
+ 'serial': None,
+ 'ssdp_description': 'http://192.168.XXX.XXX:80/desc.xml',
+ 'udn': None,
+ 'upnp_device_type': None,
+ })
+
+ def test_info_from_entry_multiple_services_no_remote_control(self):
+ self.assertEqual(
+ Discoverable(None).info_from_entry(MockUPNPEntry(
+ "desc_multiple_services_no_remote_control.xml")),
+ {
+ 'control_url':
+ 'http://192.168.1.2:80/YamahaNewControl/ctrl',
+ 'description_url':
+ 'http://192.168.1.2:80/YamahaNewControl/desc.xml',
+ 'host': '192.168.xxx.xxx',
+ 'model_name': 'multi service model name',
+ 'model_number': None,
+ 'manufacturer': None,
+ 'name': 'multi service friendly name',
+ 'port': 80,
+ 'serial': None,
+ 'ssdp_description': 'http://192.168.XXX.XXX:80/desc.xml',
+ 'udn': None,
+ 'upnp_device_type': None,
+ })
+
+ def test_get_entries_incompatible_models(self):
+ supported_model = MockUPNPEntry(
+ "desc_multiple_services_no_remote_control.xml")
+ devices = [
+ supported_model,
+ MockUPNPEntry("desc_incompatible_device.xml")
+ ]
+
+ discoverable = Discoverable(None)
+ discoverable.INCOMPATIBLE_MODELS = ["aaa"]
+ discoverable.find_by_device_description = MagicMock(
+ return_value=devices)
+
+ self.assertEqual(discoverable.get_entries(), [supported_model])
diff --git a/tests/discoverables/yamaha_files/desc_RX-V481.xml b/tests/discoverables/yamaha_files/desc_RX-V481.xml
new file mode 100644
index 0000000..1919945
--- /dev/null
+++ b/tests/discoverables/yamaha_files/desc_RX-V481.xml
@@ -0,0 +1,92 @@
+<root xmlns="urn:schemas-upnp-org:device-1-0" xmlns:yamaha="urn:schemas-yamaha-com:device-1-0">
+<specVersion>
+<major>1</major>
+<minor>0</minor>
+</specVersion>
+<device>
+<dlna:X_DLNADOC xmlns:dlna="urn:schemas-dlna-org:device-1-0">DMR-1.50</dlna:X_DLNADOC>
+<deviceType>urn:schemas-upnp-org:device:MediaRenderer:1</deviceType>
+<friendlyName>RX-V481 XXXXXX</friendlyName>
+<manufacturer>Yamaha Corporation</manufacturer>
+<manufacturerURL>http://www.yamaha.com/</manufacturerURL>
+<modelDescription>AV Receiver</modelDescription>
+<modelName>RX-V481</modelName>
+<modelNumber>V481</modelNumber>
+<modelURL>http://www.yamaha.com/</modelURL>
+<serialNumber>XXXXXXXX</serialNumber>
+<UDN>uuid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</UDN>
+<iconList>
+<icon>
+<mimetype>image/jpeg</mimetype>
+<width>48</width>
+<height>48</height>
+<depth>24</depth>
+<url>/Icons/48x48.jpg</url>
+</icon>
+<icon>
+<mimetype>image/jpeg</mimetype>
+<width>120</width>
+<height>120</height>
+<depth>24</depth>
+<url>/Icons/120x120.jpg</url>
+</icon>
+<icon>
+<mimetype>image/png</mimetype>
+<width>48</width>
+<height>48</height>
+<depth>24</depth>
+<url>/Icons/48x48.png</url>
+</icon>
+<icon>
+<mimetype>image/png</mimetype>
+<width>120</width>
+<height>120</height>
+<depth>24</depth>
+<url>/Icons/120x120.png</url>
+</icon>
+</iconList>
+<serviceList>
+<service>
+<serviceType>urn:schemas-upnp-org:service:AVTransport:1</serviceType>
+<serviceId>urn:upnp-org:serviceId:AVTransport</serviceId>
+<SCPDURL>/AVTransport/desc.xml</SCPDURL>
+<controlURL>/AVTransport/ctrl</controlURL>
+<eventSubURL>/AVTransport/event</eventSubURL>
+</service>
+<service>
+<serviceType>urn:schemas-upnp-org:service:RenderingControl:1</serviceType>
+<serviceId>urn:upnp-org:serviceId:RenderingControl</serviceId>
+<SCPDURL>/RenderingControl/desc.xml</SCPDURL>
+<controlURL>/RenderingControl/ctrl</controlURL>
+<eventSubURL>/RenderingControl/event</eventSubURL>
+</service>
+<service>
+<serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>
+<serviceId>urn:upnp-org:serviceId:ConnectionManager</serviceId>
+<SCPDURL>/ConnectionManager/desc.xml</SCPDURL>
+<controlURL>/ConnectionManager/ctrl</controlURL>
+<eventSubURL>/ConnectionManager/event</eventSubURL>
+</service>
+</serviceList>
+<presentationURL>http://192.168.XXX.XXX/</presentationURL>
+</device>
+<yamaha:X_device>
+<yamaha:X_URLBase>http://192.168.XXX.XXX:80/</yamaha:X_URLBase>
+<yamaha:X_serviceList>
+<yamaha:X_service>
+<yamaha:X_specType>
+urn:schemas-yamaha-com:service:X_YamahaRemoteControl:1
+</yamaha:X_specType>
+<yamaha:X_controlURL>/YamahaRemoteControl/ctrl</yamaha:X_controlURL>
+<yamaha:X_unitDescURL>/YamahaRemoteControl/desc.xml</yamaha:X_unitDescURL>
+</yamaha:X_service>
+<yamaha:X_service>
+<yamaha:X_specType>
+urn:schemas-yamaha-com:service:X_YamahaExtendedControl:1
+</yamaha:X_specType>
+<yamaha:X_yxcControlURL>/YamahaExtendedControl/v1/</yamaha:X_yxcControlURL>
+<yamaha:X_yxcVersion>1131</yamaha:X_yxcVersion>
+</yamaha:X_service>
+</yamaha:X_serviceList>
+</yamaha:X_device>
+</root> \ No newline at end of file
diff --git a/tests/discoverables/yamaha_files/desc_incompatible_device.xml b/tests/discoverables/yamaha_files/desc_incompatible_device.xml
new file mode 100644
index 0000000..53127b7
--- /dev/null
+++ b/tests/discoverables/yamaha_files/desc_incompatible_device.xml
@@ -0,0 +1,26 @@
+<root xmlns="urn:schemas-upnp-org:device-1-0" xmlns:yamaha="urn:schemas-yamaha-com:device-1-0">
+<device>
+<friendlyName>multi service friendly name</friendlyName>
+<modelName>multi service model name</modelName>
+<modelNumber>aaa</modelNumber>
+</device>
+<yamaha:X_device>
+<yamaha:X_URLBase>http://192.168.1.2:80/</yamaha:X_URLBase>
+<yamaha:X_serviceList>
+<yamaha:X_service>
+<yamaha:X_specType>
+urn:schemas-yamaha-com:service:X_YamahaNewControl:1
+</yamaha:X_specType>
+<yamaha:X_controlURL>/YamahaNewControl/ctrl</yamaha:X_controlURL>
+<yamaha:X_unitDescURL>/YamahaNewControl/desc.xml</yamaha:X_unitDescURL>
+</yamaha:X_service>
+<yamaha:X_service>
+<yamaha:X_specType>
+urn:schemas-yamaha-com:service:X_YamahaExtendedControl:1
+</yamaha:X_specType>
+<yamaha:X_yxcControlURL>/YamahaExtendedControl/v1/</yamaha:X_yxcControlURL>
+<yamaha:X_yxcVersion>1131</yamaha:X_yxcVersion>
+</yamaha:X_service>
+</yamaha:X_serviceList>
+</yamaha:X_device>
+</root>
diff --git a/tests/discoverables/yamaha_files/desc_multiple_services_no_remote_control.xml b/tests/discoverables/yamaha_files/desc_multiple_services_no_remote_control.xml
new file mode 100644
index 0000000..7b7873b
--- /dev/null
+++ b/tests/discoverables/yamaha_files/desc_multiple_services_no_remote_control.xml
@@ -0,0 +1,25 @@
+<root xmlns="urn:schemas-upnp-org:device-1-0" xmlns:yamaha="urn:schemas-yamaha-com:device-1-0">
+<device>
+<friendlyName>multi service friendly name</friendlyName>
+<modelName>multi service model name</modelName>
+</device>
+<yamaha:X_device>
+<yamaha:X_URLBase>http://192.168.1.2:80/</yamaha:X_URLBase>
+<yamaha:X_serviceList>
+<yamaha:X_service>
+<yamaha:X_specType>
+urn:schemas-yamaha-com:service:X_YamahaNewControl:1
+</yamaha:X_specType>
+<yamaha:X_controlURL>/YamahaNewControl/ctrl</yamaha:X_controlURL>
+<yamaha:X_unitDescURL>/YamahaNewControl/desc.xml</yamaha:X_unitDescURL>
+</yamaha:X_service>
+<yamaha:X_service>
+<yamaha:X_specType>
+urn:schemas-yamaha-com:service:X_YamahaExtendedControl:1
+</yamaha:X_specType>
+<yamaha:X_yxcControlURL>/YamahaExtendedControl/v1/</yamaha:X_yxcControlURL>
+<yamaha:X_yxcVersion>1131</yamaha:X_yxcVersion>
+</yamaha:X_service>
+</yamaha:X_serviceList>
+</yamaha:X_device>
+</root> \ No newline at end of file
diff --git a/tests/discoverables/yamaha_files/desc_multiple_services_remote_control_last.xml b/tests/discoverables/yamaha_files/desc_multiple_services_remote_control_last.xml
new file mode 100644
index 0000000..0dc46b0
--- /dev/null
+++ b/tests/discoverables/yamaha_files/desc_multiple_services_remote_control_last.xml
@@ -0,0 +1,25 @@
+<root xmlns="urn:schemas-upnp-org:device-1-0" xmlns:yamaha="urn:schemas-yamaha-com:device-1-0">
+<device>
+<friendlyName>multi service friendly name</friendlyName>
+<modelName>multi service model name</modelName>
+</device>
+<yamaha:X_device>
+<yamaha:X_URLBase>http://192.168.1.2:80/</yamaha:X_URLBase>
+<yamaha:X_serviceList>
+<yamaha:X_service>
+<yamaha:X_specType>
+urn:schemas-yamaha-com:service:X_YamahaExtendedControl:1
+</yamaha:X_specType>
+<yamaha:X_yxcControlURL>/YamahaExtendedControl/v1/</yamaha:X_yxcControlURL>
+<yamaha:X_yxcVersion>1131</yamaha:X_yxcVersion>
+</yamaha:X_service>
+<yamaha:X_service>
+<yamaha:X_specType>
+urn:schemas-yamaha-com:service:X_YamahaRemoteControl:1
+</yamaha:X_specType>
+<yamaha:X_controlURL>/YamahaRemoteControl/multi_ctrl</yamaha:X_controlURL>
+<yamaha:X_unitDescURL>/YamahaRemoteControl/multi_desc.xml</yamaha:X_unitDescURL>
+</yamaha:X_service>
+</yamaha:X_serviceList>
+</yamaha:X_device>
+</root> \ No newline at end of file
diff --git a/tests/discoverables/yamaha_files/desc_single_service.xml b/tests/discoverables/yamaha_files/desc_single_service.xml
new file mode 100644
index 0000000..e0e8109
--- /dev/null
+++ b/tests/discoverables/yamaha_files/desc_single_service.xml
@@ -0,0 +1,22 @@
+<root xmlns="urn:schemas-upnp-org:device-1-0" xmlns:yamaha="urn:schemas-yamaha-com:device-1-0">
+<specVersion>
+<major>1</major>
+<minor>0</minor>
+</specVersion>
+<device>
+<friendlyName>single service friendly name</friendlyName>
+<modelName>single service model name</modelName>
+</device>
+<yamaha:X_device>
+<yamaha:X_URLBase>http://192.168.1.2:80/</yamaha:X_URLBase>
+<yamaha:X_serviceList>
+<yamaha:X_service>
+<yamaha:X_specType>
+urn:schemas-yamaha-com:service:X_YamahaRemoteControl:1
+</yamaha:X_specType>
+<yamaha:X_controlURL>/YamahaRemoteControl/single_ctrl</yamaha:X_controlURL>
+<yamaha:X_unitDescURL>/YamahaRemoteControl/single_desc.xml</yamaha:X_unitDescURL>
+</yamaha:X_service>
+</yamaha:X_serviceList>
+</yamaha:X_device>
+</root> \ No newline at end of file
diff --git a/tests/test_xboxone.py b/tests/test_xboxone.py
new file mode 100644
index 0000000..d2aeb3c
--- /dev/null
+++ b/tests/test_xboxone.py
@@ -0,0 +1,60 @@
+"""The tests for discovering Xbox gaming consoles via SmartGlass protocol."""
+import unittest
+from binascii import unhexlify
+
+from netdisco.smartglass import XboxSmartGlass
+
+
+class TestXboxOne(unittest.TestCase):
+ """Test the Xbox One Discoverable."""
+ def setUp(self):
+ """
+ Setup test class
+ """
+ with open('tests/xboxone_files/discovery_response', 'rb') as content:
+ packet = content.read()
+
+ if not packet:
+ raise Exception('Failed to read test data')
+
+ self.discovery_response = packet
+
+ def test_assemble_request(self):
+ """
+ Test discovery request assembly
+ """
+ packet = XboxSmartGlass.discovery_packet()
+
+ self.assertEqual(
+ packet,
+ unhexlify(b'dd00000a000000000000000400000002')
+ )
+
+ def test_parse_response(self):
+ """
+ Test discovery response parsing
+ """
+ response = XboxSmartGlass.parse_discovery_response(
+ self.discovery_response)
+
+ self.assertEqual(response['device_type'], 1)
+ self.assertEqual(response['flags'], 2)
+ self.assertEqual(response['name'], 'XboxOne')
+ self.assertEqual(response['uuid'],
+ 'DE305D54-75B4-431B-ADB2-EB6B9E546014')
+ self.assertEqual(response['last_error'], 0)
+ self.assertEqual(response['certificate'][:8], '30820203')
+ self.assertEqual(len(unhexlify(response['certificate'])), 519)
+
+ def test_verify_response(self):
+ """
+ Test discovery response verification
+ """
+ valid_parse = XboxSmartGlass.verify_packet(self.discovery_response)
+ invalid_length = XboxSmartGlass.verify_packet(unhexlify(b'41'))
+ invalid_magic = XboxSmartGlass.verify_packet(
+ unhexlify(b'aabbccddeeff00'))
+
+ self.assertIsNotNone(valid_parse)
+ self.assertIsNone(invalid_length)
+ self.assertIsNone(invalid_magic)
diff --git a/tests/xboxone_files/discovery_response b/tests/xboxone_files/discovery_response
new file mode 100644
index 0000000..2f5cf46
--- /dev/null
+++ b/tests/xboxone_files/discovery_response
Binary files differ