It is only deletes if it the last project referencing it.
Depends on this change at common: https://osm.etsi.org/gerrit/9134
Change-Id: Id167c0ae3309212b97f59d47a9f3cee7f53fd263
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
# do not remove reference, but order via kafka to delete it
if session["project_id"] and session["project_id"]:
other_projects_referencing = next((p for p in db_content["_admin"]["projects_read"]
- if p not in session["project_id"]), None)
+ if p not in session["project_id"] and p != "ANY"), None)
# check if there are projects referencing it (apart from ANY, that means, public)....
if other_projects_referencing:
# remove references but not delete
- update_dict_pull = {"_admin.projects_read.{}".format(p): None for p in session["project_id"]}
- update_dict_pull.update({"_admin.projects_write.{}".format(p): None for p in session["project_id"]})
- self.db.set_one(self.topic, filter_q, update_dict=None, pull=update_dict_pull)
+ update_dict_pull = {"_admin.projects_read": session["project_id"],
+ "_admin.projects_write": session["project_id"]}
+ self.db.set_one(self.topic, filter_q, update_dict=None, pull_list=update_dict_pull)
return None
else:
can_write = next((p for p in db_content["_admin"]["projects_write"] if p == "ANY" or
# remove reference from project_read if there are more projects referencing it. If it last one,
# do not remove reference, but delete
other_projects_referencing = next((p for p in item_content["_admin"]["projects_read"]
- if p not in session["project_id"]), None)
+ if p not in session["project_id"] and p != "ANY"), None)
# check if there are projects referencing it (apart from ANY, that means, public)....
if other_projects_referencing:
# remove references but not delete
- update_dict_pull = {"_admin.projects_read.{}".format(p): None for p in session["project_id"]}
- update_dict_pull.update({"_admin.projects_write.{}".format(p): None for p in session["project_id"]})
- self.db.set_one(self.topic, filter_q, update_dict=None, pull=update_dict_pull)
+ update_dict_pull = {"_admin.projects_read": session["project_id"],
+ "_admin.projects_write": session["project_id"]}
+ self.db.set_one(self.topic, filter_q, update_dict=None, pull_list=update_dict_pull)
return None
else:
can_write = next((p for p in item_content["_admin"]["projects_write"] if p == "ANY" or
self.assertEqual(self.db.set_one.call_args[0][1]["_id"], cid, "Wrong CIM identifier")
self.assertEqual(self.db.set_one.call_args[1]["update_dict"], None,
"Wrong read-only projects update")
- self.assertEqual(self.db.set_one.call_args[1]["pull"], {"_admin.projects_read." + test_pid: None,
- "_admin.projects_write." + test_pid: None},
+ self.assertEqual(self.db.set_one.call_args[1]["pull_list"],
+ {"_admin.projects_read": (test_pid,), "_admin.projects_write": (test_pid,)},
"Wrong read/write projects update")
self.topic._send_msg.assert_not_called()
with self.subTest(i=2):
self.assertEqual(db_s1_args[0][1]["_id"], did, "Wrong DB ID")
self.assertIn(p_id, db_s1_args[0][1]["_admin.projects_write.cont"], "Wrong DB filter")
self.assertIsNone(db_s1_args[1]["update_dict"], "Wrong DB update dictionary")
- self.assertIn("_admin.projects_read." + p_id, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
- self.assertIn("_admin.projects_write." + p_id, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
+ self.assertEqual(db_s1_args[1]["pull_list"],
+ {"_admin.projects_read": (p_id,), "_admin.projects_write": (p_id,)},
+ "Wrong DB pull_list dictionary")
self.fs.file_delete.assert_not_called()
return
self.assertEqual(db_s1_args[0][1]["_id"], did, "Wrong DB ID")
self.assertIn(p_id, db_s1_args[0][1]["_admin.projects_write.cont"], "Wrong DB filter")
self.assertIsNone(db_s1_args[1]["update_dict"], "Wrong DB update dictionary")
- self.assertIn("_admin.projects_read." + p_id, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
- self.assertIn("_admin.projects_write." + p_id, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
+ self.assertEqual(db_s1_args[1]["pull_list"],
+ {"_admin.projects_read": (p_id,), "_admin.projects_write": (p_id,)},
+ "Wrong DB pull_list dictionary")
self.fs.file_delete.assert_not_called()
return
self.assertEqual(db_s1_args[0][0], self.nsr_topic.topic, "Wrong DB topic")
self.assertEqual(db_s1_args[0][1]["_id"], self.nsr_id, "Wrong DB ID")
self.assertIsNone(db_s1_args[1]["update_dict"], "Wrong DB update dictionary")
- self.assertIn("_admin.projects_read." + p_other, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
- self.assertIn("_admin.projects_write." + p_other, db_s1_args[1]["pull"], "Wrong DB pull dictionary")
+ self.assertEqual(db_s1_args[1]["pull_list"],
+ {"_admin.projects_read": [p_other], "_admin.projects_write": [p_other]},
+ "Wrong DB pull_list dictionary")
self.fs.file_delete.assert_not_called()
with self.subTest(i=4, t='Delete with force and admin'):
self.db.del_one.reset_mock()