Touch up ObjectReferenceProperty checks
- reword "_refs" error - check with isinstance instead of __class__.__name__stix2.1
parent
0e658255a8
commit
8a33cb7716
|
@ -768,12 +768,12 @@ def CustomObservable(type='x-custom-observable', properties={}):
|
||||||
}
|
}
|
||||||
# Check properties ending in "_ref/s" are ObjectReferenceProperties
|
# Check properties ending in "_ref/s" are ObjectReferenceProperties
|
||||||
for prop_name, prop in properties.items():
|
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 "
|
raise ValueError("'%s' is named like an object reference property but "
|
||||||
"is not an ObjectReferenceProperty." % prop_name)
|
"is not an ObjectReferenceProperty." % prop_name)
|
||||||
elif (prop_name.endswith('_refs') and (prop.__class__.__name__ != 'ListProperty'
|
elif (prop_name.endswith('_refs') and (not isinstance(prop, ListProperty)
|
||||||
or prop.contained.__class__.__name__ != 'ObjectReferenceProperty')):
|
or not isinstance(prop.contained, ObjectReferenceProperty))):
|
||||||
raise ValueError("'%s' is named like an object reference property but "
|
raise ValueError("'%s' is named like an object reference list property but "
|
||||||
"is not a ListProperty containing ObjectReferenceProperty." % prop_name)
|
"is not a ListProperty containing ObjectReferenceProperty." % prop_name)
|
||||||
|
|
||||||
_properties.update(properties)
|
_properties.update(properties)
|
||||||
|
|
|
@ -169,7 +169,7 @@ def test_custom_observable_object_invalid_refs_property():
|
||||||
})
|
})
|
||||||
class NewObs():
|
class NewObs():
|
||||||
pass
|
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():
|
def test_custom_observable_object_invalid_refs_list_property():
|
||||||
|
@ -179,7 +179,7 @@ def test_custom_observable_object_invalid_refs_list_property():
|
||||||
})
|
})
|
||||||
class NewObs():
|
class NewObs():
|
||||||
pass
|
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():
|
def test_custom_observable_object_invalid_valid_refs():
|
||||||
|
|
Loading…
Reference in New Issue