Skip to content

Commit b6ef77d

Browse files
committed
Fix Indicator.negate tests
1 parent 3797a08 commit b6ef77d

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

stix/indicator/indicator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,22 @@ def add_object(self, object_):
722722
observable = Observable(object_)
723723
self.add_observable(observable)
724724

725+
def _finalize_obj(self, entity_obj):
726+
"""Omits the `negate` field if it is not equal to True.
727+
"""
728+
if self.negate:
729+
entity_obj.negate = True
730+
elif hasattr(entity_obj, 'negate'):
731+
entity_obj.negate = None
732+
733+
def _finalize_dict(self, entity_dict):
734+
"""Omits the `negate` field if it is not equal to True.
735+
"""
736+
if self.negate:
737+
entity_dict['negate'] = True
738+
elif 'negate' in entity_dict:
739+
del entity_dict['negate']
740+
725741

726742
def check_operator(composite_indicator_exp, value):
727743
allowed = CompositeIndicatorExpression.OPERATORS

stix/test/indicator_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def test_negate(self):
3737
d2 = self.klass.from_dict(d).to_dict()
3838
self.assertTrue('negate' not in d2)
3939

40+
o2 = self.klass.from_dict(d).to_obj()
41+
self.assertTrue(o2.negate is None)
42+
4043

4144
def test_indicator_types(self):
4245
d = {

0 commit comments

Comments
 (0)