Skip to content

Commit

Permalink
Explicitly reference parameter values in error messages. Add UNCLEAR …
Browse files Browse the repository at this point in the history
…test result for paths dependent on failed parameterized endpoints.
  • Loading branch information
jonathan-r-thorpe committed Apr 24, 2024
1 parent bb04845 commit 1717c91
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions nmostesting/GenericTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,11 @@ def do_test_no_matching_public_key_authorization(self, api_name):
return test.DISABLED("This test is only performed when an API supports Authorization and 'ENABLE_AUTH' "
"is True")

def generate_parameterized_endpoints(self, endpoint_path, params, param_index=0):
if params is None or param_index >= len(params):
return [endpoint_path]
def generate_parameterized_endpoints(self, endpoint_path, param_names, param_values=None, param_index=0):
if param_values is None:
param_values = {}
if param_names is None or param_index >= len(param_names):
return [(endpoint_path, param_values)]

root_path = endpoint_path.split("{")[0].rstrip("/")
parameter_path = re.findall("([^}]+}[^{]*)", endpoint_path)[0].rstrip("/")
Expand All @@ -606,9 +608,10 @@ def generate_parameterized_endpoints(self, endpoint_path, params, param_index=0)

endpoints = []
for entity in self.saved_entities[root_path]:
partial_endpoint = parameter_path.format(**{params[param_index].name: entity})
param_values[param_names[param_index].name] = entity
partial_endpoint = parameter_path.format(**{param_names[param_index].name: entity})
endpoints += self.generate_parameterized_endpoints("{}{}".format(partial_endpoint, post_param),
params, param_index+1)
param_names, param_values.copy(), param_index+1)
return endpoints

def do_test_api_resource(self, resource, response_code, api):
Expand All @@ -618,12 +621,16 @@ def do_test_api_resource(self, resource, response_code, api):
resource[0].rstrip("/")), self.auto_test_name(api))

endpoints = NMOSUtils.sampled_list(self.generate_parameterized_endpoints(resource[0], resource[1]['params']))
for endpoint in endpoints:
for endpoint, param_values in endpoints:
entity_valid, entity_message = self.check_api_resource(test, resource, response_code, api, endpoint)
if not entity_valid:
return test.FAIL("Error for {}: {}".format(endpoint, entity_message))
return test.FAIL("Error for {}: {}".format(param_values, entity_message)
if param_values else entity_message)
elif entity_message:
return test.WARNING("Warning for {}: {}".format(endpoint, entity_message))
return test.WARNING("Warning for {}: {}".format(param_values, entity_message)
if param_values else entity_message)
if len(endpoints) == 0:
return test.UNCLEAR("Unable to test endpoint.")
return test.PASS()

def check_api_resource(self, test, resource, response_code, api, path):
Expand Down

0 comments on commit 1717c91

Please sign in to comment.