Touch up ObjectReferenceProperty checks

- reword "_refs" error
- check with isinstance instead of __class__.__name__
stix2.1
clenk 2017-08-30 16:15:05 -04:00
parent 0e658255a8
commit 8a33cb7716
2 changed files with 6 additions and 6 deletions

View File

@ -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)

View File

@ -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():