X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Ftests%2Ftest_admin_topics.py;h=a26d57627e2a7eac8e2e9fe44ea6ef8b9e0b91ef;hp=a28953b5bcd211a43c933ca93eee5fa74e1047c0;hb=20e74d260242c91c9836efba6a9436a159c4decc;hpb=ad682a52ef94fa2662e2a0f6e3f81fb7c8f5e0fe diff --git a/osm_nbi/tests/test_admin_topics.py b/osm_nbi/tests/test_admin_topics.py index a28953b..a26d576 100755 --- a/osm_nbi/tests/test_admin_topics.py +++ b/osm_nbi/tests/test_admin_topics.py @@ -50,10 +50,11 @@ class Test_ProjectTopicAuth(TestCase): self.db = Mock(dbbase.DbBase()) self.fs = Mock(fsbase.FsBase()) self.msg = Mock(msgbase.MsgBase()) - self.auth = Mock(authconn.Authconn(None, None)) + self.auth = Mock(authconn.Authconn(None, None, None)) self.topic = ProjectTopicAuth(self.db, self.fs, self.msg, self.auth) self.fake_session = {"username": self.test_name, "project_id": (test_pid,), "method": None, "admin": True, "force": False, "public": False, "allow_show_user_project_role": True} + self.topic.check_quota = Mock(return_value=None) # skip quota def test_new_project(self): with self.subTest(i=1): @@ -210,10 +211,12 @@ class Test_RoleTopicAuth(TestCase): self.db = Mock(dbbase.DbBase()) self.fs = Mock(fsbase.FsBase()) self.msg = Mock(msgbase.MsgBase()) - self.auth = Mock(authconn.Authconn(None, None)) - self.topic = RoleTopicAuth(self.db, self.fs, self.msg, self.auth, self.test_operations) + self.auth = Mock(authconn.Authconn(None, None, None)) + self.auth.role_permissions = self.test_operations + self.topic = RoleTopicAuth(self.db, self.fs, self.msg, self.auth) self.fake_session = {"username": test_name, "project_id": (test_pid,), "method": None, "admin": True, "force": False, "public": False, "allow_show_user_project_role": True} + self.topic.check_quota = Mock(return_value=None) # skip quota def test_new_role(self): with self.subTest(i=1): @@ -370,10 +373,11 @@ class Test_UserTopicAuth(TestCase): self.db = Mock(dbbase.DbBase()) self.fs = Mock(fsbase.FsBase()) self.msg = Mock(msgbase.MsgBase()) - self.auth = Mock(authconn.Authconn(None, None)) + self.auth = Mock(authconn.Authconn(None, None, None)) self.topic = UserTopicAuth(self.db, self.fs, self.msg, self.auth) self.fake_session = {"username": test_name, "project_id": (test_pid,), "method": None, "admin": True, "force": False, "public": False, "allow_show_user_project_role": True} + self.topic.check_quota = Mock(return_value=None) # skip quota def test_new_user(self): uid1 = str(uuid4()) @@ -588,14 +592,16 @@ class Test_CommonVimWimSdn(TestCase): self.db = Mock(dbbase.DbBase()) self.fs = Mock(fsbase.FsBase()) self.msg = Mock(msgbase.MsgBase()) - self.auth = Mock(authconn.Authconn(None, None)) + self.auth = Mock(authconn.Authconn(None, None, None)) self.topic = CommonVimWimSdn(self.db, self.fs, self.msg, self.auth) # Use WIM schemas for testing because they are the simplest + self.topic._send_msg = Mock() self.topic.topic = "wims" self.topic.schema_new = validation.wim_account_new_schema self.topic.schema_edit = validation.wim_account_edit_schema self.fake_session = {"username": test_name, "project_id": (test_pid,), "method": None, "admin": True, "force": False, "public": False, "allow_show_user_project_role": True} + self.topic.check_quota = Mock(return_value=None) # skip quota def test_new_cvws(self): test_url = "http://0.0.0.0:0" @@ -726,10 +732,12 @@ class Test_CommonVimWimSdn(TestCase): self.assertEqual(self.db.get_one.call_args[0][1]["_id"], cid, "Wrong CIM identifier") self.assertEqual(self.db.set_one.call_args[0][0], self.topic.topic, "Wrong topic") 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"]["_admin.projects_read"], [ro_pid, rw_pid], + 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]["update_dict"]["_admin.projects_write"], [rw_pid], + 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): now = time() cvws["_admin"] = {"projects_read": [test_pid], "projects_write": [test_pid], "operations": []} @@ -740,10 +748,8 @@ class Test_CommonVimWimSdn(TestCase): self.assertEqual(self.db.get_one.call_args[0][1]["_id"], cid, "Wrong CIM identifier") self.assertEqual(self.db.set_one.call_args[0][0], self.topic.topic, "Wrong topic") self.assertEqual(self.db.set_one.call_args[0][1]["_id"], cid, "Wrong user identifier") - update_dict = self.db.set_one.call_args[1]["update_dict"] - self.assertEqual(update_dict["_admin.projects_read"], [], "Wrong read-only projects update") - self.assertEqual(update_dict["_admin.projects_write"], [], "Wrong read/write projects update") - self.assertEqual(update_dict["_admin.to_delete"], True, "Wrong deletion mark") + self.assertEqual(self.db.set_one.call_args[1]["update_dict"], {"_admin.to_delete": True}, + "Wrong _admin.to_delete update") operation = self.db.set_one.call_args[1]["push"]["_admin.operations"] self.assertEqual(operation["lcmOperationType"], "delete", "Wrong operation type") self.assertEqual(operation["operationState"], "PROCESSING", "Wrong operation state") @@ -751,16 +757,23 @@ class Test_CommonVimWimSdn(TestCase): self.assertIsNone(operation["operationParams"], "Wrong operation parameters") self.assertGreater(operation["startTime"], now, "Wrong operation start time") self.assertGreater(operation["statusEnteredTime"], now, "Wrong operation status enter time") + self.topic._send_msg.assert_called_once_with("delete", {"_id": cid, "op_id": cid + ":0"}, not_send_msg=None) with self.subTest(i=3): cvws["_admin"] = {"projects_read": [], "projects_write": [], "operations": []} self.db.get_one.return_value = cvws + self.topic._send_msg.reset_mock() + self.db.get_one.reset_mock() + self.db.del_one.reset_mock() self.fake_session["force"] = True # to force deletion + self.fake_session["admin"] = True # to force deletion + self.fake_session["project_id"] = [] # to force deletion oid = self.topic.delete(self.fake_session, cid) self.assertIsNone(oid, "Wrong operation identifier") self.assertEqual(self.db.get_one.call_args[0][0], self.topic.topic, "Wrong topic") self.assertEqual(self.db.get_one.call_args[0][1]["_id"], cid, "Wrong CIM identifier") self.assertEqual(self.db.del_one.call_args[0][0], self.topic.topic, "Wrong topic") self.assertEqual(self.db.del_one.call_args[0][1]["_id"], cid, "Wrong CIM identifier") + self.topic._send_msg.assert_called_once_with("deleted", {"_id": cid, "op_id": None}, not_send_msg=None) if __name__ == '__main__':