Skip to content

Commit

Permalink
invoke_method returns NcMethodResult
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-r-thorpe committed Nov 1, 2024
1 parent 12c6f3a commit bd4099c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion nmostesting/IS12Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def set_property_override(self, test, property_id, argument, oid, **kwargs):
NcObjectMethods.GENERIC_SET.value,
{'id': property_id, 'value': argument})

def invoke_method(self, test, method_id, argument, oid, **kwargs):
def invoke_method_override(self, test, method_id, argument, oid, **kwargs):
"""Invoke method on Node. Raises NMOSTestException on error"""
return self.execute_command(test, oid,
method_id,
Expand Down
2 changes: 1 addition & 1 deletion nmostesting/IS14Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def set_property_override(self, test, property_id, argument, role_path, **kwargs
property_value_endpoint = self._create_property_value_endpoint(role_path, property_id)
return self._do_request(test, "PUT", property_value_endpoint, json={"value": argument})

def invoke_method(self, test, method_id, argument, role_path, **kwargs):
def invoke_method_override(self, test, method_id, argument, role_path, **kwargs):
"""Invoke method on Node. Raises NMOSTestException on error"""
methods_endpoint = self._create_methods_endpoint(role_path, method_id)
return self._do_request(test, "PATCH", methods_endpoint, json={"arguments": argument})
Expand Down
9 changes: 8 additions & 1 deletion nmostesting/MS05Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_property_override(self, test, property_id, **kwargs):
def set_property_override(self, test, property_id, argument, **kwargs):
pass

def invoke_method(self, test, method_id, argument, **kwargs):
def invoke_method_override(self, test, method_id, argument, **kwargs):
pass

def get_sequence_item(self, test, property_id, index, **kwargs):
Expand Down Expand Up @@ -115,6 +115,13 @@ def set_property(self, test, property_id, argument, **kwargs):
role_path=kwargs.get("role_path"))
return NcMethodResult.factory(result)

def invoke_method(self, test, method_id, argument, **kwargs):
"""Invoke method on Node. Raises NMOSTestException on error"""
result = self.invoke_method_override(test, method_id, argument, **kwargs)
self.reference_datatype_schema_validate(test, result, NcMethodResult.__name__,
role_path=kwargs.get("role_path"))
return NcMethodResult.factory(result)

def query_device_model(self, test):
""" Query Device Model from the Node under test.
self.device_model_metadata set on Device Model validation error.
Expand Down
37 changes: 16 additions & 21 deletions nmostesting/suites/MS0502Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,27 +773,22 @@ def _do_check_methods_test(self, test, question):
self.invoke_methods_metadata.error_msg = ""

for method in selected_methods:
try:
self.invoke_methods_metadata.checked = True

parameters = self._create_compatible_parameters(test, method.descriptor.parameters)

result = self.ms05_utils.invoke_method(test, method.descriptor.id.__dict__, parameters,
oid=method.oid, role_path=method.role_path)

# check for deprecated status codes for deprecated methods
if method.descriptor.isDeprecated and result["status"] != 299:
self.invoke_methods_metadata.error = True
self.invoke_methods_metadata.error_msg += \
f"Deprecated method returned incorrect status code {method.name} : {result.status}"
except NMOSTestException as e:
# ignore 4xx errors
self.ms05_utils.reference_datatype_schema_validate(test, e.args[0].detail, "NcMethodResult",
method.role_path)
if e.args[0].detail["status"] >= 500:
self.invoke_methods_metadata.error = True
self.invoke_methods_metadata.error_msg += \
f"Error invoking method {method.name} : {e.args[0].detail}"
self.invoke_methods_metadata.checked = True

parameters = self._create_compatible_parameters(test, method.descriptor.parameters)

method_result = self.ms05_utils.invoke_method(test, method.descriptor.id.__dict__, parameters,
oid=method.oid, role_path=method.role_path)

# check for deprecated status codes for deprecated methods
if method.descriptor.isDeprecated and method_result.status != 299:
self.invoke_methods_metadata.error = True
self.invoke_methods_metadata.error_msg += \
f"Deprecated method returned incorrect status code {method.name} : {method_result.status}"
if isinstance(method_result, NcMethodResultError) and method_result.status >= 500:
self.invoke_methods_metadata.error = True
self.invoke_methods_metadata.error_msg += \
f"Error invoking method {method.name} : {method_result.errorMessage}"
if self.invoke_methods_metadata.error:
return test.FAIL(self.invoke_methods_metadata.error_msg)

Expand Down

0 comments on commit bd4099c

Please sign in to comment.