Skip to content

Commit

Permalink
add_sequence_item returns NcMethodResultId
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-r-thorpe committed Nov 2, 2024
1 parent 3b80b6f commit 9dcd93d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 32 deletions.
2 changes: 1 addition & 1 deletion nmostesting/IS12Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def set_sequence_item_override(self, test, property_id, index, value, oid, **kwa
NcObjectMethods.SET_SEQUENCE_ITEM.value,
{'id': property_id, 'index': index, 'value': value})

def add_sequence_item(self, test, property_id, value, oid, **kwargs):
def add_sequence_item_override(self, test, property_id, value, oid, **kwargs):
"""Add value to a sequence property. Raises NMOSTestException on error"""
return self.execute_command(test, oid,
NcObjectMethods.ADD_SEQUENCE_ITEM.value,
Expand Down
2 changes: 1 addition & 1 deletion nmostesting/IS14Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def set_sequence_item_override(self, test, property_id, index, value, role_path,
return self._do_request(test, "PATCH", methods_endpoint,
json={"arguments": {"id": property_id, "index": index, "value": value}})

def add_sequence_item(self, test, property_id, value, role_path, **kwargs):
def add_sequence_item_override(self, test, property_id, value, role_path, **kwargs):
"""Add value to a sequence property. Raises NMOSTestException on error"""
methods_endpoint = self._create_methods_endpoint(role_path, NcObjectMethods.ADD_SEQUENCE_ITEM.value)
return self._do_request(test, "PATCH", methods_endpoint,
Expand Down
9 changes: 8 additions & 1 deletion nmostesting/MS05Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def set_sequence_item_override(self, test, property_id, index, value, **kwargs):
"""Add value to a sequence property. Raises NMOSTestException on error"""
pass

def add_sequence_item(self, test, property_id, value, **kwargs):
def add_sequence_item_override(self, test, property_id, value, **kwargs):
"""Add value to a sequence property. Raises NMOSTestException on error"""
pass

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

def add_sequence_item(self, test, property_id, value, **kwargs):
"""Add value to a sequence property. Raises NMOSTestException on error"""
result = self.add_sequence_item_override(test, property_id, value, **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
75 changes: 46 additions & 29 deletions nmostesting/suites/MS0502Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ..GenericTest import NMOSTestException
from ..ControllerTest import ControllerTest, TestingFacadeException
from ..MS05Utils import NcDatatypeDescriptorEnum, NcDatatypeDescriptorPrimitive, NcDatatypeType, NcBlock, \
NcDatatypeDescriptorStruct, NcDatatypeDescriptorTypeDef, NcMethodResult, NcMethodResultError, \
NcDatatypeDescriptorStruct, NcDatatypeDescriptorTypeDef, NcMethodResult, NcMethodResultError, NcMethodResultXXX, \
NcParameterConstraintsNumber, NcParameterConstraintsString, NcPropertyConstraintsNumber, \
NcPropertyConstraintsString

Expand Down Expand Up @@ -277,12 +277,13 @@ def _check_parameter_constraints_number(self, test, constrained_property):
oid=constrained_property.oid,
role_path=constrained_property.role_path)
if not isinstance(method_result, NcMethodResultError):
index = method_result.value
self.ms05_utils.add_sequence_item(test,
constrained_property.descriptor.id.__dict__,
new_value,
oid=constrained_property.oid,
role_path=constrained_property.role_path)
index = method_result.value # new item will be added to end of sequence (at 'index' position)
method_result = self.ms05_utils.add_sequence_item(test,
constrained_property.descriptor.id.__dict__,
new_value,
oid=constrained_property.oid,
role_path=constrained_property.role_path)
if not isinstance(method_result, NcMethodResultError):
method_result = self.ms05_utils.set_sequence_item(test,
constrained_property.descriptor.id.__dict__,
index, new_value,
Expand Down Expand Up @@ -348,12 +349,13 @@ def _check_parameter_constraints_string(self, test, constrained_property):
oid=constrained_property.oid,
role_path=constrained_property.role_path)
if not isinstance(method_result, NcMethodResultError):
index = method_result.value
self.ms05_utils.add_sequence_item(test,
constrained_property.descriptor.id.__dict__,
new_value,
oid=constrained_property.oid,
role_path=constrained_property.role_path)
index = method_result.value # new item will be added to end of sequence (at 'index' position)
method_result = self.ms05_utils.add_sequence_item(test,
constrained_property.descriptor.id.__dict__,
new_value,
oid=constrained_property.oid,
role_path=constrained_property.role_path)
if not isinstance(method_result, NcMethodResultError):
method_result = self.ms05_utils.set_sequence_item(test,
constrained_property.descriptor.id.__dict__,
index,
Expand Down Expand Up @@ -836,32 +838,47 @@ def test_ms05_07(self, test):

def check_add_sequence_item(self, test, property_id, property_name, sequence_length, oid, role_path, context=""):
# Add a value to the end of the sequence
# Get the first item from this sequence (then we know it is of the correct type)
method_result = self.ms05_utils.get_sequence_item(test, property_id.__dict__, index=0,
oid=oid, role_path=role_path)

if not isinstance(method_result, NcMethodResultError):
new_item_value = method_result.value
# The new item will be added to end of the sequence
method_result = self.ms05_utils.get_sequence_length(test, property_id.__dict__,
oid=oid, role_path=role_path)
if not isinstance(method_result, NcMethodResultError):
new_item_index = method_result.value
method_result = self.ms05_utils.add_sequence_item(test, property_id.__dict__, new_item_value,
oid=oid, role_path=role_path)
# Check return type of addSequenceItem - should be NcMethodResultId
if not isinstance(method_result, NcMethodResultError):
if not isinstance(method_result, NcMethodResultXXX):
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Unexpected return type from addSequenceItem. "
return False
# add_sequence_item should return index of added item
if method_result.value != new_item_index:
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Unexpected index of added item: " \
f"Expected: {str(new_item_index)}, Actual: {str(method_result.value)}"
return False
# check the added item value
method_result = self.ms05_utils.get_sequence_item(test, property_id.__dict__, index=sequence_length,
oid=oid, role_path=role_path)
if isinstance(method_result, NcMethodResultError):
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Error getting sequence item: {str(method_result.errorMessage)} "
return False
new_item = method_result.value
self.ms05_utils.add_sequence_item(test, property_id.__dict__, new_item, oid=oid, role_path=role_path)

# check the value
method_result = self.ms05_utils.get_sequence_item(test, property_id.__dict__, index=sequence_length,
oid=oid, role_path=role_path)

if isinstance(method_result, NcMethodResultError):
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Error getting sequence item: {str(method_result.errorMessage)} "
f"{context}{property_name}: Sequence method error: {str(method_result.errorMessage)} "
return False

value = method_result.value
if value != new_item:
if method_result.value != new_item_value:
self.add_sequence_item_metadata.error = True
self.add_sequence_item_metadata.error_msg += \
f"{context}{property_name}: Expected: {str(new_item)}, Actual: {str(value)}, "
f"{context}{property_name}: Error adding sequence item: " \
f"Expected: {str(new_item_value)}, Actual: {str(method_result.value)}, "
self.add_sequence_item_metadata.checked = True

return True
Expand Down

0 comments on commit 9dcd93d

Please sign in to comment.