From 8a33cb7716bd8d567dc1e1e66f8c4a6e2164662f Mon Sep 17 00:00:00 2001 From: clenk Date: Wed, 30 Aug 2017 16:15:05 -0400 Subject: [PATCH] Touch up ObjectReferenceProperty checks - reword "_refs" error - check with isinstance instead of __class__.__name__ --- stix2/observables.py | 8 ++++---- stix2/test/test_custom.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) 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():