Repository: amwa-tv/nmos-testing
Issue: IS-05 test needed: Verify that each sender's and receiver's staged transport parameters meet the constraints

I just got bitten by this -- my staged parameters violate the constraints, and since the API client didn't specify any transport parameters, the server rejected the request as invalid. Oops.

I don't think you can do the same thing for the active parameters, however -- a parameter might be constrained to "auto", but the active parameter has to reflect the actual value.

Changed files:
IS0402Test.py, IS0501Test.py, GenericTest.py

diff --git a/GenericTest.py b/GenericTest.py
index 36f8c9c..530392b 100644
--- a/GenericTest.py
+++ b/GenericTest.py
@@ -224,7 +224,7 @@ class GenericTest(object):
             return False, "Incorrect CORS headers: {}".format(response.headers)
 
         try:
-            jsonschema.validate(response.json(), schema)
+            jsonschema.validate(response.json(), schema, format_checker=jsonschema.draft4_format_checker)
         except jsonschema.ValidationError:
             return False, "Response schema validation error"
         except json.decoder.JSONDecodeError:
diff --git a/IS0402Test.py b/IS0402Test.py
index 3f3c3f9..405bee2 100644
--- a/IS0402Test.py
+++ b/IS0402Test.py
@@ -19,7 +19,7 @@ import socket
 import uuid
 import json
 from copy import deepcopy
-from jsonschema import ValidationError, Draft4Validator
+from jsonschema import ValidationError, Draft4Validator, draft4_format_checker
 import re
 
 from zeroconf_monkey import ServiceBrowser, Zeroconf
@@ -1523,7 +1523,7 @@ class IS0402Test(GenericTest):
                 # Validate received data against schema
                 for message in received_messages:
                     try:
-                        Draft4Validator(schema).validate(json.loads(message))
+                        Draft4Validator(schema, format_checker=draft4_format_checker).validate(json.loads(message))
                     except ValidationError as e:
                         return test.FAIL("Received event message is invalid: {}".format(str(e)))
 
@@ -1562,7 +1562,7 @@ class IS0402Test(GenericTest):
                 # Validate received data against schema
                 for message in received_messages:
                     try:
-                        Draft4Validator(schema).validate(json.loads(message))
+                        Draft4Validator(schema, format_checker=draft4_format_checker).validate(json.loads(message))
                     except ValidationError as e:
                         return test.FAIL("Received event message is invalid: {}".format(str(e)))
 
@@ -1608,7 +1608,7 @@ class IS0402Test(GenericTest):
                 # Validate received data against schema
                 for message in received_messages:
                     try:
-                        Draft4Validator(schema).validate(json.loads(message))
+                        Draft4Validator(schema, format_checker=draft4_format_checker).validate(json.loads(message))
                     except ValidationError as e:
                         return test.FAIL("Received event message is invalid: {}".format(str(e)))
 
@@ -1646,7 +1646,7 @@ class IS0402Test(GenericTest):
                 # Validate received data against schema
                 for message in received_messages:
                     try:
-                        Draft4Validator(schema).validate(json.loads(message))
+                        Draft4Validator(schema, format_checker=draft4_format_checker).validate(json.loads(message))
                     except ValidationError as e:
                         return test.FAIL("Received event message is invalid: {}".format(str(e)))
 
diff --git a/IS0501Test.py b/IS0501Test.py
index 10bc877..c23a7e7 100644
--- a/IS0501Test.py
+++ b/IS0501Test.py
@@ -16,7 +16,7 @@
 
 
 import uuid
-from jsonschema import ValidationError, SchemaError, Draft4Validator
+from jsonschema import ValidationError, SchemaError, Draft4Validator, draft4_format_checker
 
 from TestResult import Test
 from GenericTest import GenericTest
@@ -835,7 +835,7 @@ class IS0501Test(GenericTest):
 
         schema = self.get_schema(CONN_API_KEY, "POST", "/bulk/" + port + "s", 200)
         try:
-            Draft4Validator(schema).validate(r.json())
+            Draft4Validator(schema, format_checker=draft4_format_checker).validate(r.json())
         except ValidationError as e:
             return False, "Response to post at {} did not validate against schema: {}".format(url, str(e))
         except:
@@ -874,7 +874,7 @@ class IS0501Test(GenericTest):
             if valid:
                 schema = self.get_schema(CONN_API_KEY, "PATCH", "/single/" + port + "s/{" + port + "Id}/staged", 200)
                 try:
-                    Draft4Validator(schema).validate(response)
+                    Draft4Validator(schema, format_checker=draft4_format_checker).validate(response)
                 except ValidationError as e:
                     return False, "Response to empty patch to {} does not comply with schema: {}".format(url, str(e))
             else:
@@ -906,8 +906,9 @@ class IS0501Test(GenericTest):
                             except IndexError:
                                 return False, "Number of 'legs' in constraints does not match the number in " \\
                                               "transport_params"
+                            schema["items"]["$schema"] = "http://json-schema.org/draft-04/schema#"
                             try:
-                                Draft4Validator(schema['items']).validate(params)
+                                Draft4Validator(schema["items"], format_checker=draft4_format_checker).validate(params)
                             except ValidationError as e:
                                 return False, "Staged endpoint does not comply with constraints in leg {}: " \\
                                               "{}".format(count, str(e))