diff --git a/stix2/observables.py b/stix2/observables.py index 4c29785..c5290ff 100644 --- a/stix2/observables.py +++ b/stix2/observables.py @@ -768,12 +768,12 @@ def CustomObservable(type='x-custom-observable', properties={}): } # Check properties ending in "_ref/s" are ObjectReferenceProperties for prop_name, prop in properties.items(): - if prop_name.endswith('_ref') and prop.__class__.__name__ != 'ObjectReferenceProperty': + if prop_name.endswith('_ref') and not isinstance(prop, ObjectReferenceProperty): raise ValueError("'%s' is named like an object reference property but " "is not an ObjectReferenceProperty." % prop_name) - elif (prop_name.endswith('_refs') and (prop.__class__.__name__ != 'ListProperty' - or prop.contained.__class__.__name__ != 'ObjectReferenceProperty')): - raise ValueError("'%s' is named like an object reference property but " + elif (prop_name.endswith('_refs') and (not isinstance(prop, ListProperty) + or not isinstance(prop.contained, ObjectReferenceProperty))): + raise ValueError("'%s' is named like an object reference list property but " "is not a ListProperty containing ObjectReferenceProperty." % prop_name) _properties.update(properties) diff --git a/stix2/test/test_custom.py b/stix2/test/test_custom.py index 313a0a8..266cfd2 100644 --- a/stix2/test/test_custom.py +++ b/stix2/test/test_custom.py @@ -169,7 +169,7 @@ def test_custom_observable_object_invalid_refs_property(): }) class NewObs(): pass - assert "is named like an object reference property but is not a ListProperty containing ObjectReferenceProperty" in str(excinfo.value) + assert "is named like an object reference list property but is not a ListProperty containing ObjectReferenceProperty" in str(excinfo.value) def test_custom_observable_object_invalid_refs_list_property(): @@ -179,7 +179,7 @@ def test_custom_observable_object_invalid_refs_list_property(): }) class NewObs(): pass - assert "is named like an object reference property but is not a ListProperty containing ObjectReferenceProperty" in str(excinfo.value) + assert "is named like an object reference list property but is not a ListProperty containing ObjectReferenceProperty" in str(excinfo.value) def test_custom_observable_object_invalid_valid_refs():