mirror of https://github.com/MISP/PyMISP
fix: Properly load AnalystData from dict
parent
10ca6f191a
commit
94a48a6fdd
|
@ -83,22 +83,23 @@ class AnalystDataBehaviorMixin(AbstractMISP):
|
||||||
return the_relationship
|
return the_relationship
|
||||||
|
|
||||||
def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def]
|
def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def]
|
||||||
if 'Note' in kwargs and kwargs.get('Note'):
|
# These members need a fully initialized class to be loaded properly
|
||||||
for note in kwargs.pop('Note'):
|
notes = kwargs.pop('Note', [])
|
||||||
note.pop('object_uuid', None)
|
opinions = kwargs.pop('Opinion', [])
|
||||||
note.pop('object_type', None)
|
relationships = kwargs.pop('Relationship', [])
|
||||||
self.add_note(**note)
|
|
||||||
if 'Opinion' in kwargs and kwargs.get('Opinion'):
|
|
||||||
for opinion in kwargs.pop('Opinion'):
|
|
||||||
opinion.pop('object_uuid', None)
|
|
||||||
opinion.pop('object_type', None)
|
|
||||||
self.add_opinion(**opinion)
|
|
||||||
if 'Relationship' in kwargs and kwargs.get('Relationship'):
|
|
||||||
for relationship in kwargs.pop('Relationship'):
|
|
||||||
relationship.pop('object_uuid', None)
|
|
||||||
relationship.pop('object_type', None)
|
|
||||||
self.add_relationship(**relationship)
|
|
||||||
super().from_dict(**kwargs)
|
super().from_dict(**kwargs)
|
||||||
|
for note in notes:
|
||||||
|
note.pop('object_uuid', None)
|
||||||
|
note.pop('object_type', None)
|
||||||
|
self.add_note(**note)
|
||||||
|
for opinion in opinions:
|
||||||
|
opinion.pop('object_uuid', None)
|
||||||
|
opinion.pop('object_type', None)
|
||||||
|
self.add_opinion(**opinion)
|
||||||
|
for relationship in relationships:
|
||||||
|
relationship.pop('object_uuid', None)
|
||||||
|
relationship.pop('object_type', None)
|
||||||
|
self.add_relationship(**relationship)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -3240,7 +3240,6 @@ class TestComprehensive(unittest.TestCase):
|
||||||
self.assertTrue(new_note.object_uuid == event.uuid)
|
self.assertTrue(new_note.object_uuid == event.uuid)
|
||||||
|
|
||||||
event = self.user_misp_connector.get_event(event)
|
event = self.user_misp_connector.get_event(event)
|
||||||
print(event.to_json(indent=2))
|
|
||||||
# The Note should be present on the event
|
# The Note should be present on the event
|
||||||
self.assertTrue(event.notes[0].object_uuid == event.uuid)
|
self.assertTrue(event.notes[0].object_uuid == event.uuid)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue