From 53f71e9cb2bd667f1752b8859b4ba5d0f368d8be Mon Sep 17 00:00:00 2001 From: Andrew Bonney Date: Thu, 8 Nov 2018 10:37:02 +0000 Subject: [PATCH] Permit Reg/Query API to run on different IPs/Ports. Resolves #10 --- GenericTest.py | 14 +++++++------- IS0401Test.py | 4 ++-- IS0402Test.py | 4 ++-- IS0501Test.py | 4 ++-- IS0601Test.py | 4 ++-- IS0701Test.py | 4 ++-- ReadMe.md | 4 ++-- nmos-test.py | 32 ++++++++++++++++++++++++++------ static/js/script.js | 15 +++++++++++++++ templates/index.html | 20 +++++++++++++++++--- 10 files changed, 77 insertions(+), 28 deletions(-) diff --git a/GenericTest.py b/GenericTest.py index 6e37a27b..ffd50ce5 100644 --- a/GenericTest.py +++ b/GenericTest.py @@ -30,8 +30,7 @@ class GenericTest(object): Generic testing class. Can be inhereted from in order to perform detailed testing. """ - def __init__(self, base_url, apis, spec_versions, test_version, spec_path, omit_paths=None): - self.base_url = base_url + def __init__(self, apis, spec_versions, test_version, spec_path, omit_paths=None): self.apis = apis self.spec_versions = spec_versions self.test_version = test_version @@ -124,10 +123,10 @@ def validate_CORS(self, method, response): return False return True - def check_base_path(self, path, expectation): + def check_base_path(self, base_url, path, expectation): """Check that a GET to a path returns a JSON array containing a defined string""" test = Test("GET {}".format(path)) - valid, req = self.do_request("GET", self.base_url + path) + valid, req = self.do_request("GET", base_url + path) if not valid: return test.FAIL("Unable to connect to API: {}".format(req)) @@ -187,10 +186,11 @@ def basics(self): for api in self.apis: # This test isn't mandatory... Many systems will use the base path for other things - # results.append(self.check_base_path("/", "x-nmos/")) + # results.append(self.check_base_path(self.apis[api]["base_url"], "/", "x-nmos/")) - results.append(self.check_base_path("/x-nmos", api + "/")) - results.append(self.check_base_path("/x-nmos/{}".format(api), self.test_version + "/")) + results.append(self.check_base_path(self.apis[api]["base_url"], "/x-nmos", api + "/")) + results.append(self.check_base_path(self.apis[api]["base_url"], "/x-nmos/{}".format(api), + self.test_version + "/")) for resource in self.apis[api]["spec"].get_reads(): for response_code in resource[1]['responses']: diff --git a/IS0401Test.py b/IS0401Test.py index 6f9184d4..d49dbb32 100644 --- a/IS0401Test.py +++ b/IS0401Test.py @@ -33,8 +33,8 @@ class IS0401Test(GenericTest): """ Runs IS-04-01-Test """ - def __init__(self, base_url, apis, spec_versions, test_version, spec_path, registry): - GenericTest.__init__(self, base_url, apis, spec_versions, test_version, spec_path) + def __init__(self, apis, spec_versions, test_version, spec_path, registry): + GenericTest.__init__(self, apis, spec_versions, test_version, spec_path) self.registry = registry self.node_url = self.apis["node"]["url"] self.query_api_url = None diff --git a/IS0402Test.py b/IS0402Test.py index a8d6a76d..bf6ccd13 100644 --- a/IS0402Test.py +++ b/IS0402Test.py @@ -27,8 +27,8 @@ class IS0402Test(GenericTest): """ Runs IS-04-02-Test """ - def __init__(self, base_url, apis, spec_versions, test_version, spec_path): - GenericTest.__init__(self, base_url, apis, spec_versions, test_version, spec_path) + def __init__(self, apis, spec_versions, test_version, spec_path): + GenericTest.__init__(self, apis, spec_versions, test_version, spec_path) self.reg_url = self.apis["registration"]["url"] self.query_url = self.apis["query"]["url"] diff --git a/IS0501Test.py b/IS0501Test.py index 95d7dff4..0e229b24 100644 --- a/IS0501Test.py +++ b/IS0501Test.py @@ -33,12 +33,12 @@ class IS0501Test(GenericTest): Runs IS-05-01-Test """ - def __init__(self, base_url, apis, spec_versions, test_version, spec_path): + def __init__(self, apis, spec_versions, test_version, spec_path): # Don't auto-test /transportfile as it is permitted to generate a 404 when master_enable is false omit_paths = [ "/single/senders/{senderId}/transportfile" ] - GenericTest.__init__(self, base_url, apis, spec_versions, test_version, spec_path, omit_paths) + GenericTest.__init__(self, apis, spec_versions, test_version, spec_path, omit_paths) self.url = self.apis["connection"]["url"] self.senders = self.get_senders() self.receivers = self.get_receivers() diff --git a/IS0601Test.py b/IS0601Test.py index 6011d3fb..4b0c9724 100644 --- a/IS0601Test.py +++ b/IS0601Test.py @@ -19,5 +19,5 @@ class IS0601Test(GenericTest): """ Runs IS-06-01-Test """ - def __init__(self, base_url, apis, spec_versions, test_version, spec_path): - GenericTest.__init__(self, base_url, apis, spec_versions, test_version, spec_path) + def __init__(self, apis, spec_versions, test_version, spec_path): + GenericTest.__init__(self, apis, spec_versions, test_version, spec_path) diff --git a/IS0701Test.py b/IS0701Test.py index 1085262f..4bb2c9b8 100644 --- a/IS0701Test.py +++ b/IS0701Test.py @@ -19,5 +19,5 @@ class IS0701Test(GenericTest): """ Runs IS-07-01-Test """ - def __init__(self, base_url, apis, spec_versions, test_version, spec_path): - GenericTest.__init__(self, base_url, apis, spec_versions, test_version, spec_path) + def __init__(self, apis, spec_versions, test_version, spec_path): + GenericTest.__init__(self, apis, spec_versions, test_version, spec_path) diff --git a/ReadMe.md b/ReadMe.md index bb07479a..e9beb302 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -114,6 +114,6 @@ class MyNewSpecTest(GenericTest): """ Runs MyNewSpecTest """ - def __init__(self, base_url, apis, spec_versions, test_version, spec_path): - GenericTest.__init__(self, base_url, apis, spec_versions, test_version, spec_path) + def __init__(self, apis, spec_versions, test_version, spec_path): + GenericTest.__init__(self, apis, spec_versions, test_version, spec_path) ``` diff --git a/nmos-test.py b/nmos-test.py index a4d0b2ef..6c9a1ae5 100644 --- a/nmos-test.py +++ b/nmos-test.py @@ -45,26 +45,31 @@ "IS-04-01": {"name": "IS-04 Node API", "versions": ["v1.0", "v1.1", "v1.2", "v1.3"], "default_version": "v1.2", + "input_labels": ["Node API"], "spec_key": 'is-04', "class": IS0401Test.IS0401Test}, "IS-04-02": {"name": "IS-04 Registry APIs", "versions": ["v1.0", "v1.1", "v1.2", "v1.3"], "default_version": "v1.2", + "input_labels": ["Registration API", "Query API"], "spec_key": 'is-04', "class": IS0402Test.IS0402Test}, "IS-05-01": {"name": "IS-05 Connection Management API", "versions": ["v1.0", "v1.1"], "default_version": "v1.0", + "input_labels": ["Connection API"], "spec_key": 'is-05', "class": IS0501Test.IS0501Test}, "IS-06-01": {"name": "IS-06 Network Control API", "versions": ["v1.0"], "default_version": "v1.0", + "input_labels": ["Network API"], "spec_key": 'is-06', "class": IS0601Test.IS0601Test}, "IS-07-01": {"name": "IS-07 Event & Tally API", "versions": ["v1.0"], "default_version": "v1.0", + "input_labels": ["Event API"], "spec_key": 'is-07', "class": IS0701Test.IS0701Test} } @@ -79,6 +84,12 @@ class DataForm(Form): port = IntegerField(label="Port:", validators=[validators.NumberRange(min=0, max=65535, message="Please enter a valid port number " "(0-65535).")]) + ip_sec = StringField(label="IP:", validators=[validators.IPAddress(message="Please enter a valid IPv4 address."), + validators.optional()]) + port_sec = IntegerField(label="Port:", validators=[validators.NumberRange(min=0, max=65535, + message="Please enter a valid port " + "number (0-65535)."), + validators.optional()]) version = SelectField(label="API Version:", choices=[("v1.0", "v1.0"), ("v1.1", "v1.1"), ("v1.2", "v1.2"), @@ -100,8 +111,11 @@ def index_page(): test = request.form["test"] ip = request.form["ip"] port = request.form["port"] + ip_sec = request.form["ip_sec"] + port_sec = request.form["port_sec"] version = request.form["version"] base_url = "http://{}:{}".format(ip, str(port)) + base_url_sec = "http://{}:{}".format(ip_sec, str(port_sec)) if form.validate(): if test in TEST_DEFINITIONS: spec_versions = TEST_DEFINITIONS[test]["versions"] @@ -109,26 +123,32 @@ def index_page(): if test == "IS-04-01": apis = {"node": {"raml": "NodeAPI.raml", + "base_url": base_url, "url": "{}/x-nmos/node/{}/".format(base_url, version)}} - test_obj = IS0401Test.IS0401Test(base_url, apis, spec_versions, version, spec_path, REGISTRY) + test_obj = IS0401Test.IS0401Test(apis, spec_versions, version, spec_path, REGISTRY) elif test == "IS-04-02": apis = {"registration": {"raml": "RegistrationAPI.raml", + "base_url": base_url, "url": "{}/x-nmos/registration/{}/".format(base_url, version)}, "query": {"raml": "QueryAPI.raml", - "url": "{}/x-nmos/query/{}/".format(base_url, version)}} - test_obj = IS0402Test.IS0402Test(base_url, apis, spec_versions, version, spec_path) + "base_url": base_url_sec, + "url": "{}/x-nmos/query/{}/".format(base_url_sec, version)}} + test_obj = IS0402Test.IS0402Test(apis, spec_versions, version, spec_path) elif test == "IS-05-01": apis = {"connection": {"raml": "ConnectionAPI.raml", + "base_url": base_url, "url": "{}/x-nmos/connection/{}/".format(base_url, version)}} - test_obj = IS0501Test.IS0501Test(base_url, apis, spec_versions, version, spec_path) + test_obj = IS0501Test.IS0501Test(apis, spec_versions, version, spec_path) elif test == "IS-06-01": apis = {"netctrl": {"raml": "NetworkControlAPI.raml", + "base_url": base_url, "url": "{}/x-nmos/netctrl/{}/".format(base_url, version)}} - test_obj = IS0601Test.IS0601Test(base_url, apis, spec_versions, version, spec_path) + test_obj = IS0601Test.IS0601Test(apis, spec_versions, version, spec_path) elif test == "IS-07-01": apis = {"events": {"raml": "EventsAPI.raml", + "base_url": base_url, "url": "{}/x-nmos/events/{}/".format(base_url, version)}} - test_obj = IS0701Test.IS0701Test(base_url, apis, spec_versions, version, spec_path) + test_obj = IS0701Test.IS0701Test(apis, spec_versions, version, spec_path) if test_obj: result = test_obj.run_tests() diff --git a/static/js/script.js b/static/js/script.js index ba04a1e2..def93925 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -6,12 +6,27 @@ function updateDropdown() { var testData = hiddenData[testID]; + // Update the version dropdown var versionDropdown = document.getElementById("version"); versionDropdown.options.length = 0; for (var i=0; iNMOS Test {{ form.test.label }} {{ form.test }} {{ form.hidden }}

+
+ +
{{ form.ip.label }} {{ form.ip(size="15") }}
{{ form.port.label }} {{ form.port(size="5") }} -
+
+
+
+ +
+
+ {{ form.ip_sec.label }} {{ form.ip_sec(size="15") }} +
+
+ {{ form.port_sec.label }} {{ form.port_sec(size="5") }} +

+

-
+

{% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} @@ -62,7 +76,7 @@

NMOS Test

{% endfor %} {% endif %} {% endwith %} -

+