Skip to content

Commit

Permalink
IS-13: test consistency with IS-04
Browse files Browse the repository at this point in the history
  • Loading branch information
pkeroulas committed Mar 4, 2024
1 parent 9d92412 commit 423bad2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
4 changes: 4 additions & 0 deletions nmostesting/NMOSTesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@
"specs": [{
"spec_key": "is-13",
"api_key": "annotation"
}, {
"spec_key": "is-04",
"api_key": "node",
"disable_fields": ["host", "port"]
}],
"class": IS1301Test.IS1301Test,
},
Expand Down
60 changes: 41 additions & 19 deletions nmostesting/suites/IS1301Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
from ..GenericTest import GenericTest, NMOSTestException
from ..TestHelper import compare_json

ANNOTATION_API_KEY = "annotation"

from ..import TestHelper
import re
import copy

ANNOTATION_API_KEY = "annotation"
NODE_API_KEY = "node"

RESOURCES = ["self", "devices", "senders", "receivers"]
OBJECTS = ["label", "description", "tags"]
Expand All @@ -46,6 +45,7 @@ class IS1301Test(GenericTest):
def __init__(self, apis, **kwargs):
GenericTest.__init__(self, apis, **kwargs)
self.annotation_url = self.apis[ANNOTATION_API_KEY]["url"]
self.node_url = f"{self.apis[ANNOTATION_API_KEY]['base_url']}/x-nmos/node/{self.apis[NODE_API_KEY]['version']}/"

def set_up_tests(self):
"""
Expand Down Expand Up @@ -73,7 +73,7 @@ def get_resource(self, url):
else:
return False, "GET Resquest FAIL"

def set_resource(self, url, new, prev):
def set_resource(self, url, node_url, new, prev):
""" Patch a resource with one ore several object values """
object = list(new.keys())[0]

Expand All @@ -86,22 +86,46 @@ def set_resource(self, url, new, prev):
else:
return False, "PATCH max Resquest FAIL"

# check that the version (timestamp) has increased
if get_ts_from_version(prev['version']) >= get_ts_from_version(resp['version']):
return False, "new version FAIL"

# check that PATCHed date is the same as returned
if new[object] is not None: # NOT a reset
if object == "tags" and not TestHelper.compare_json(resp[object], new[object]):
return False, f"new {object} FAIL"
elif resp[object] != new[object]:
return False, f"new {object} FAIL"

# TODO this is reflected in IS04
# validate that it is reflected in IS04
valid, node_resp = self.get_resource(node_url)
if not valid:
return False, "GET node FAIL"
if new[object] is not None: # NOT a reset
if object == "tags" and not TestHelper.compare_json(node_resp[object], new[object]):
return False, f"new node/.../{object} FAIL"
elif node_resp[object] != new[object]:
return False, f"new node/.../{object} FAIL"
if get_ts_from_version(node_resp['version']) != get_ts_from_version(resp['version']):
return False, "new node version FAIL"

return True, resp

def log(self, msg):
print(msg)

def get_url(self, base_url, middle, resource):
url = "{}{}{}".format(base_url, middle, resource)
if resource != "self": # get first of the list of devices, receivers, senders
valid, r = self.get_resource(url)
if valid:
print(f" Possible endpoint: {r}")
# FIXEME for node API where it r.id is the response,
index = r[0]
url = "{}{}{}".format(url, '/', index)
else:
return None
return url

def do_test(self, test, resource, object):
"""
Perform the test sequence for a resource:
Expand All @@ -114,15 +138,13 @@ def do_test(self, test, resource, object):
- Restore initial value
"""

url = "{}{}{}".format(self.annotation_url, 'node/', resource)
if resource != "self": # get first of the list of devices, receivers, senders
valid, r = self.get_resource(url)
if valid:
print(f" Possible endpoint: {r}")
index = r[0]
url = "{}{}{}".format(url, '/', index)
else:
return test.FAIL(f"Can't find any {resource}")
url = self.get_url(self.annotation_url, 'node/', resource)
if not url:
return test.FAIL(f"Can't get annotation url for {resource}")

node_url = self.get_url(self.node_url, '', resource)
if not url:
return test.FAIL(f"Can't get node url for {resource}")

msg = "save initial"
valid, r = self.get_resource(url)
Expand All @@ -136,7 +158,7 @@ def do_test(self, test, resource, object):
return test.FAIL(f"Can't {msg} {resource}/{object}")

msg = "reset to default and save"
valid, r = self.set_resource(url, {object: None}, prev)
valid, r = self.set_resource(url, node_url, {object: None}, prev)
if valid:
default = prev = r
self.log(f" {msg}: {r}")
Expand All @@ -145,7 +167,7 @@ def do_test(self, test, resource, object):

msg = "set max value and expected complete response"
value = TAGS_MAX_VALUE if object == "tags" else STRING_MAX_VALUE
valid, r = self.set_resource(url, {object: value}, prev)
valid, r = self.set_resource(url, node_url, {object: value}, prev)
if valid:
prev = r
self.log(f" {msg}: {r}")
Expand All @@ -154,7 +176,7 @@ def do_test(self, test, resource, object):

msg = "set >max value and expect truncated response"
value = TAGS_OVER_MAX_VALUE if object == "tags" else STRING_OVER_MAX_VALUE
valid, r = self.set_resource(url, {object: value}, prev)
valid, r = self.set_resource(url, node_url, {object: value}, prev)
if valid:
prev = r
self.log(f" {msg}: {r}")
Expand All @@ -166,7 +188,7 @@ def do_test(self, test, resource, object):
return test.FAIL(f"Can't {msg} {resource}/{object}")

msg = "reset again and compare"
valid, r = self.set_resource(url, {object: None}, prev)
valid, r = self.set_resource(url, node_url, {object: None}, prev)
if valid:
self.log(f" {msg}: {r}")
if object == "tags" and not TestHelper.compare_json(default[object], r[object]):
Expand All @@ -178,7 +200,7 @@ def do_test(self, test, resource, object):
return test.FAIL(f"Can't {msg} {resource}/{object}")

# restore initial for courtesy
self.set_resource(url, initial, prev)
self.set_resource(url, node_url, initial, prev)

return test.PASS()

Expand Down

0 comments on commit 423bad2

Please sign in to comment.