too Chris' suggestions to improve interproperty constraint methods

added interproperty constraint check to ExternalReferences
stix2.1
Richard Piazza 2017-05-12 13:18:02 -04:00
parent 29871427b7
commit a95e91005c
2 changed files with 7 additions and 8 deletions

View File

@ -50,21 +50,16 @@ class _STIXBase(collections.Mapping):
# interproperty constraint methods
def _check_mutually_exclusive_properties(self, list_of_properties, at_least_one=True):
count = 0
current_properties = self.properties_populated()
for x in list_of_properties:
if x in current_properties:
count += 1
count = len(set(list_of_properties).intersection(current_properties))
# at_least_one allows for xor to be checked
if count > 1 or (at_least_one and count == 0):
raise MutuallyExclusivePropertiesError(self.__class__, list_of_properties)
def _check_at_least_one_property(self, list_of_properties):
current_properties = self.properties_populated()
for x in list_of_properties:
if x in current_properties:
return
raise AtLeastOnePropertyError(self.__class__, list_of_properties)
if not set(list_of_properties).intersection(current_properties):
raise AtLeastOnePropertyError(self.__class__, list_of_properties)
def _check_properties_dependency(self, list_of_properties, list_of_dependent_properties, values=[]):
failed_dependency_pairs = []

View File

@ -15,6 +15,10 @@ class ExternalReference(_STIXBase):
'external_id': StringProperty(),
}
def _check_object_constaints(self):
super(ExternalReference, self)._check_object_constaints()
self._check_at_least_one_property(["description", "external_id", "url"])
class KillChainPhase(_STIXBase):
_properties = {