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 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', [])
opinions = kwargs.pop('Opinion', [])
relationships = kwargs.pop('Relationship', [])
super().from_dict(**kwargs)
for note in notes:
note.pop('object_uuid', None) note.pop('object_uuid', None)
note.pop('object_type', None) note.pop('object_type', None)
self.add_note(**note) self.add_note(**note)
if 'Opinion' in kwargs and kwargs.get('Opinion'): for opinion in opinions:
for opinion in kwargs.pop('Opinion'):
opinion.pop('object_uuid', None) opinion.pop('object_uuid', None)
opinion.pop('object_type', None) opinion.pop('object_type', None)
self.add_opinion(**opinion) self.add_opinion(**opinion)
if 'Relationship' in kwargs and kwargs.get('Relationship'): for relationship in relationships:
for relationship in kwargs.pop('Relationship'):
relationship.pop('object_uuid', None) relationship.pop('object_uuid', None)
relationship.pop('object_type', None) relationship.pop('object_type', None)
self.add_relationship(**relationship) self.add_relationship(**relationship)
super().from_dict(**kwargs)
try: try:

View File

@ -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)