mirror of https://github.com/MISP/PyMISP
chg: [dev] add extend_event() test. chg typo in get_event()
parent
fb82b7affe
commit
a76a85b616
|
@ -210,7 +210,7 @@ class PyMISP:
|
|||
if deleted:
|
||||
data['deleted'] = deleted
|
||||
if extended:
|
||||
data['extended'] = deleted
|
||||
data['extended'] = extended
|
||||
if data:
|
||||
r = self._prepare_request('POST', f'events/view/{event_id}', data=data)
|
||||
else:
|
||||
|
@ -246,6 +246,17 @@ class PyMISP:
|
|||
e.load(updated_event)
|
||||
return e
|
||||
|
||||
def extend_event(self, event: MISPEvent, event_id: int, pythonify: bool=False) -> Union[dict, MISPEvent]:
|
||||
'''Extends an event on a MISP instance'''
|
||||
eid = self.__get_uuid_or_id_from_abstract_misp(event_id)
|
||||
r = self._prepare_request('POST', f'events/add/extends/{eid}', data=event)
|
||||
updated_event = self._check_json_response(r)
|
||||
if not (self.global_pythonify or pythonify) or 'errors' in updated_event:
|
||||
return updated_event
|
||||
e = MISPEvent()
|
||||
e.load(updated_event)
|
||||
return e
|
||||
|
||||
def delete_event(self, event: Union[MISPEvent, int, str, UUID]) -> dict:
|
||||
'''Delete an event from a MISP instance'''
|
||||
event_id = self.__get_uuid_or_id_from_abstract_misp(event)
|
||||
|
|
|
@ -812,6 +812,29 @@ class TestComprehensive(unittest.TestCase):
|
|||
self.admin_misp_connector.delete_event(first)
|
||||
self.admin_misp_connector.delete_event(second)
|
||||
|
||||
def test_extend_event(self):
|
||||
first = self.create_simple_event()
|
||||
first.info = 'parent event'
|
||||
first.add_tag('tlp:amber___test')
|
||||
first.set_date('2018-09-01')
|
||||
second = self.create_simple_event()
|
||||
second.info = 'event extension'
|
||||
second.add_tag('tlp:amber___test')
|
||||
second.set_date('2018-09-01')
|
||||
second.add_attribute('ip-src', '9.9.9.9')
|
||||
try:
|
||||
first = self.user_misp_connector.add_event(first)
|
||||
extended_event = self.user_misp_connector.extend_event(event=second, event_id=first.id, pythonify=True)
|
||||
self.assertTrue(isinstance(extended_event, MISPEvent), extended_event)
|
||||
extended_event = self.user_misp_connector.get_event(event=first.id, extended=True, pythonify=True)
|
||||
self.assertTrue(isinstance(extended_event, MISPEvent), extended_event)
|
||||
self.assertEqual(extended_event.extensionEvents[second.id]['info'], second.info)
|
||||
self.assertEqual(extended_event.extensionEvents[second.id]['info'], second.info)
|
||||
finally:
|
||||
# Delete event
|
||||
self.admin_misp_connector.delete_event(first)
|
||||
self.admin_misp_connector.delete_event(second)
|
||||
|
||||
def test_edit_attribute(self):
|
||||
first = self.create_simple_event()
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue