summaryrefslogtreecommitdiff
path: root/tests/discoverables
diff options
context:
space:
mode:
authorRuben Undheim <ruben.undheim@gmail.com>2018-12-21 21:01:06 +0100
committerRuben Undheim <ruben.undheim@gmail.com>2018-12-21 21:01:06 +0100
commitd41ea366e7c2e51c9f7e68092d89e3f0be580362 (patch)
tree949fd6476faf99d225a5787356a48b54b8b15192 /tests/discoverables
Import python-netdisco_2.2.0.orig.tar.gz
[dgit import orig python-netdisco_2.2.0.orig.tar.gz]
Diffstat (limited to 'tests/discoverables')
-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
6 files changed, 316 insertions, 0 deletions
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