fix: Properly load AnalystData from dict

wip_analystdata
Raphaël Vinot 2024-05-06 15:24:04 +02:00
parent 10ca6f191a
commit 94a48a6fdd
2 changed files with 16 additions and 16 deletions

View File

@ -83,22 +83,23 @@ class AnalystDataBehaviorMixin(AbstractMISP):
return the_relationship
def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def]
if 'Note' in kwargs and kwargs.get('Note'):
for note in kwargs.pop('Note'):
# These members need a fully initialized class to be loaded properly
notes = kwargs.pop('Note', [])
opinions = kwargs.pop('Opinion', [])
relationships = kwargs.pop('Relationship', [])
super().from_dict(**kwargs)
for note in notes:
note.pop('object_uuid', None)
note.pop('object_type', None)
self.add_note(**note)
if 'Opinion' in kwargs and kwargs.get('Opinion'):
for opinion in kwargs.pop('Opinion'):
for opinion in opinions:
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'):
for relationship in relationships:
relationship.pop('object_uuid', None)
relationship.pop('object_type', None)
self.add_relationship(**relationship)
super().from_dict(**kwargs)
try:

View File

@ -3240,7 +3240,6 @@ class TestComprehensive(unittest.TestCase):
self.assertTrue(new_note.object_uuid == event.uuid)
event = self.user_misp_connector.get_event(event)
print(event.to_json(indent=2))
# The Note should be present on the event
self.assertTrue(event.notes[0].object_uuid == event.uuid)