Skip to content

Commit

Permalink
Permit Reg/Query API to run on different IPs/Ports. Resolves #10
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbonney committed Nov 8, 2018
1 parent cfeacf5 commit 53f71e9
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 28 deletions.
14 changes: 7 additions & 7 deletions GenericTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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']:
Expand Down
4 changes: 2 additions & 2 deletions IS0401Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions IS0402Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
4 changes: 2 additions & 2 deletions IS0501Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions IS0601Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions IS0701Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
32 changes: 26 additions & 6 deletions nmos-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand All @@ -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"),
Expand All @@ -100,35 +111,44 @@ 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"]
spec_path = CACHE_PATH + '/' + TEST_DEFINITIONS[test]["spec_key"]

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()
Expand Down
15 changes: 15 additions & 0 deletions static/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<testData["versions"].length; i++) {
versionDropdown.options[i] = new Option(testData["versions"][i], testData["versions"][i]);
}
versionDropdown.value = testData["default_version"];

// Update the input boxes and their labels
var input1 = document.getElementById("input1");
var input2 = document.getElementById("input2");
var secAPI = document.getElementById("secondary_api");
if (testData["input_labels"].length == 1) {
input1.innerHTML = testData["input_labels"][0] + ":";
input2.innerHTML = "";
secAPI.style.display = "none";
} else {
input1.innerHTML = testData["input_labels"][0] + ":";
input2.innerHTML = testData["input_labels"][1] + ":";
secAPI.style.display = "block";
}
}

document.addEventListener("DOMContentLoaded", function() {
Expand Down
20 changes: 17 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,30 @@ <h1>NMOS Test</h1>
{{ form.test.label }} {{ form.test }}
{{ form.hidden }}
</div><br/><br/>
<div class="input text input_data_fld">
<label id="input1"></label>
</div>
<div class="input text input_data_fld">
{{ form.ip.label }} {{ form.ip(size="15") }}
</div>
<div class="input text input_data_fld">
{{ form.port.label }} {{ form.port(size="5") }}
</div>
</div><br />
<div id="secondary_api">
<div class="input text input_data_fld">
<label id="input2"></label>
</div>
<div class="input text input_data_fld">
{{ form.ip_sec.label }} {{ form.ip_sec(size="15") }}
</div>
<div class="input text input_data_fld">
{{ form.port_sec.label }} {{ form.port_sec(size="5") }}
</div><br />
</div><br />
<div class="input dropdown input_data_fld" id="version_select">
{{ form.version.label }} {{ form.version }}
</div>
<br/>
<br/><br/>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}

Expand All @@ -62,7 +76,7 @@ <h1>NMOS Test</h1>
{% endfor %}
{% endif %}
{% endwith %}
<br/><br/>
<br/>
<div class="input submit input_data_fld">
<input type="submit" id="runbtn" value="Run" onclick="document.getElementById('runbtn').value='Executing test..';document.getElementById('runbtn').className += 'disabled';"/>
</div>
Expand Down

0 comments on commit 53f71e9

Please sign in to comment.