From a127318a8ede9a48388e4017201863679b09b903 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= <raphael@vinot.info>
Date: Mon, 22 Jun 2020 14:27:03 +0200
Subject: [PATCH] chg: Add a few test cases

---
 tests/testlive_comprehensive.py | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/tests/testlive_comprehensive.py b/tests/testlive_comprehensive.py
index c2f8240..f4552e9 100644
--- a/tests/testlive_comprehensive.py
+++ b/tests/testlive_comprehensive.py
@@ -536,6 +536,26 @@ class TestComprehensive(unittest.TestCase):
             # Delete event
             self.admin_misp_connector.delete_event(first)
 
+    def test_delete_with_update(self):
+        try:
+            first = self.create_simple_event()
+            obj = MISPObject('file')
+            obj.add_attribute('filename', 'foo')
+            first.add_object(obj)
+            first = self.user_misp_connector.add_event(first)
+
+            first.attributes[0].deleted = True
+            deleted_attribute = self.user_misp_connector.update_attribute(first.attributes[0], pythonify=True)
+            self.assertTrue(deleted_attribute.deleted)
+
+            # FIXME: https://github.com/MISP/MISP/issues/6024
+            # first.objects[0].deleted = True
+            # deleted_object = self.user_misp_connector.update_object(first.objects[0], pythonify=True)
+            # self.assertTrue(deleted_object.deleted)
+        finally:
+            # Delete event
+            self.admin_misp_connector.delete_event(first)
+
     def test_delete_by_uuid(self):
         try:
             first = self.create_simple_event()
@@ -1822,6 +1842,10 @@ class TestComprehensive(unittest.TestCase):
         first = self.create_simple_event()
         o = first.add_object(name='file')
         o.add_attribute('filename', value='foo2.exe')
+        second_object = MISPObject('file')
+        second_object.add_attribute("tlsh", value='92a4b4a3d342a21fe1147474c19c9ab6a01717713a0248a2bb15affce77c1c14a79b93',
+                                    category="Payload delivery", to_ids=True, distribution=4, sharing_group_id=sharing_group.id)
+
         try:
             first = self.user_misp_connector.add_event(first)
             first = self.admin_misp_connector.change_sharing_group_on_entity(first, sharing_group.id, pythonify=True)
@@ -1832,6 +1856,15 @@ class TestComprehensive(unittest.TestCase):
             first_attribute = self.admin_misp_connector.change_sharing_group_on_entity(first.attributes[0], sharing_group.id, pythonify=True)
             self.assertEqual(first_attribute.distribution, 4)
             self.assertEqual(first_attribute.sharing_group_id, int(sharing_group.id))
+            # manual create
+            second_object = self.admin_misp_connector.add_object(first.id, second_object, pythonify=True)
+            self.assertEqual(second_object.attributes[0].sharing_group_id, int(sharing_group.id))
+            # manual update
+            # FIXME: https://github.com/MISP/MISP/issues/6025
+            # first_object.add_attribute("tlsh", value='92a4b4a3d342a21fe1147474c19c9ab6a01717713a0248a2bb15affce77c1c14a79b93',
+            #                            category="Payload delivery", to_ids=True, distribution=4, sharing_group_id=sharing_group.id)
+            # first_object = self.admin_misp_connector.update_object(first_object, pythonify=True)
+            # self.assertEqual(first_object.attributes[-1].sharing_group_id, sharing_group.id)
         finally:
             # Delete event
             self.admin_misp_connector.delete_event(first)