AMWA-TV / nmos-testing

Testing tool for the AMWA NMOS Specifications
https://specs.amwa.tv/nmos-testing/
Apache License 2.0
42 stars 48 forks source link

[IS-07-02] Check Device controls #807

Open garethsb opened 1 year ago

garethsb commented 1 year ago

Check Device.controls has an entry with "type": "urn:x-nmos:control:events/{version}" (i.e. api["version"]) and the appropriate "href" based on the api["url"] under test.

Originally posted by @garethsb in https://github.com/AMWA-TV/nmos-testing/issues/431#issuecomment-567010266

garethsb commented 1 year ago
def test_xx(self, test):
        """At least one Device is showing an IS-07 control advertisement matching the API under test"""

        valid, devices = self.do_request("GET", self.node_url + "devices")
        if not valid:
            return test.FAIL("Node API did not respond as expected: {}".format(devices))

        is07_devices = []
        found_api_match = False
        try:
            device_type = "urn:x-nmos:control:events/" + self.apis[EVENTS_API_KEY]["version"]
            for device in devices.json():
                controls = device["controls"]
                for control in controls:
                    if control["type"] == device_type:
                        is07_devices.append(control["href"])
                        if self.is07_utils.compare_urls(self.events_url, control["href"]) and \
                                self.authorization is control.get("authorization", False):
                            found_api_match = True
        except json.JSONDecodeError:
            return test.FAIL("Non-JSON response returned from Node API")
        except KeyError:
            return test.FAIL("One or more Devices were missing the 'controls' attribute")

        if len(is07_devices) > 0 and found_api_match:
            return test.PASS()
        elif len(is07_devices) > 0:
            return test.FAIL("Found one or more Device controls, but no href and authorization mode matched the "
                             "Events API under test")
        else:
            return test.FAIL("Unable to find any Devices which expose the control type '{}'".format(device_type))