Unit test for delete feature_group and trainingjob_version 03/11103/4
authorrajdeep11 <rajdeep.sin@samsung.com>
Mon, 15 May 2023 09:50:53 +0000 (15:20 +0530)
committerrajdeep11 <rajdeep.sin@samsung.com>
Wed, 17 May 2023 10:19:24 +0000 (15:49 +0530)
Issue-Id: AIMLFW-45

Change-Id: Ifbc77c0ad956d32b19ede9ba36003591966d4f88
Signed-off-by: rajdeep11 <rajdeep.sin@samsung.com>
tests/test_common_db_fun.py
tests/test_tm_apis.py
trainingmgr/trainingmgr_main.py

index 8a85388..471d491 100644 (file)
@@ -29,7 +29,7 @@ from trainingmgr.db.common_db_fun import get_data_extraction_in_progress_trainin
      get_all_versions_info_by_name, get_all_distinct_trainingjobs, \
      get_all_version_num_by_trainingjob_name, update_model_download_url, \
      add_update_trainingjob, get_all_jobs_latest_status_version, get_info_of_latest_version, \
-     add_featuregroup, get_feature_group_by_name_db, get_feature_groups_db
+     add_featuregroup, get_feature_group_by_name_db, get_feature_groups_db, delete_feature_group_by_name
 
 mimic_db = {
             "usecase_name": "Tester",
@@ -564,4 +564,21 @@ class Test_Common_Db_Fun:
             assert False
         except Exception as err:
             fxn_name="get_feature_groups"
-            assert str(err)=="Failed to execute query in {}DB Error".format(fxn_name)
\ No newline at end of file
+            assert str(err)=="Failed to execute query in {}DB Error".format(fxn_name)
+
+    def test_delete_feature_group_by_name(self):
+        checker=Check()
+        db_obj = db_helper_fg([[None]], check_success_obj=checker)
+        delete_feature_group_by_name(db_obj, "Tester")
+        assert checker.finished, 'delete_feature_group_by_name FAILED'
+    
+    def test_negative_delete_feature_group_by_name(self):
+        checker=Check()
+        try:
+            db_obj = db_helper([[None]], raise_exception=True,check_success_obj=checker)
+            delete_feature_group_by_name(db_obj, "Tester")
+            assert False
+        except Exception as err:
+            fxn_name="delete_feature_group"
+            assert str(err)=="Failed to execute query in {}DB Error".format(fxn_name)
+            assert checker.finished, 'Cursor Not Closed Properly for fxn {} | Negative Test'.format(fxn_name)
\ No newline at end of file
index 0557210..f454ca8 100644 (file)
@@ -955,4 +955,251 @@ class Test_get_feature_group_by_name:
         fg_name='testing'
         response=self.client.get('/featureGroup/{}'.format(fg_name))
         assert response.status_code == 500 , "status code is not equal"
-        assert response.data == expected_data
\ No newline at end of file
+        assert response.data == expected_data
+
+class Test_delete_list_of_feature_group:
+    @patch('trainingmgr.common.trainingmgr_config.TMLogger', return_value = TMLogger("tests/common/conf_log.yaml"))
+    def setup_method(self,mock1,mock2):
+        self.client = trainingmgr_main.APP.test_client(self)
+        self.logger = trainingmgr_main.LOGGER
+
+    mocked_TRAININGMGR_CONFIG_OBJ=mock.Mock(name="TRAININGMGR_CONFIG_OBJ")
+    attrs_TRAININGMGR_CONFIG_OBJ = {'my_ip.return_value': '123'}
+    mocked_TRAININGMGR_CONFIG_OBJ.configure_mock(**attrs_TRAININGMGR_CONFIG_OBJ)
+    resp=Response()
+    resp.status_code=status.HTTP_204_NO_CONTENT
+    the_result=[('testing', '', 'InfluxSource', True, '21.0.0.21', '12345', '', '', '', '')]
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.get_feature_group_by_name_db', return_value=the_result)
+    @patch('trainingmgr.trainingmgr_main.delete_feature_group_by_name')
+    @patch('trainingmgr.trainingmgr_main.delete_dme_filtered_data_job', return_value=resp)
+    @patch('trainingmgr.trainingmgr_main.TRAININGMGR_CONFIG_OBJ', return_value = mocked_TRAININGMGR_CONFIG_OBJ)
+    def test_delete_list_of_feature_group(self, mock1, mock2, mock3, mock4, mock5):
+        delete_req={"featuregroups_list":[{"featureGroup_name":"testing_hash"}]}
+        expected_response=b'{"success count": 1, "failure count": 0}'
+        response=self.client.delete('/featureGroup', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response, "response is not equal"
+        assert response.status_code==200, "status code not equal"
+    
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=False)
+    def test_negative_delete_list_of_feature_group(self, mock1):
+        delete_req=delete_req={"featuregroups_list":[{"featureGroup_name":"testing_hash"}]}
+        expected_response=b'{"Exception": "Wrong Request syntax"}'
+        response=self.client.delete('/featureGroup', data=json.dumps(delete_req), content_type="application/json")
+        print("response data", response.data)
+        assert response.data==expected_response
+        assert response.status_code==400, "status code not equal"
+    
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.isinstance', return_value=False)
+    def test_negative_delete_list_of_feature_group_2(self, mock1, mock2):
+        delete_req=delete_req={"featuregroups_list":[{"featureGroup_name":"testing_hash"}]}
+        expected_response=b'{"Exception": "not given as list"}'
+        response=self.client.delete('/featureGroup', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==400, "status code not equal"
+
+    def test_negative_delete_list_of_feature_group_3(self):
+        delete_req=delete_req={"featuregroups_list":[("featureGroup_name")]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/featureGroup', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+    
+    def test_negative_delete_list_of_feature_group_4(self):
+        delete_req=delete_req={"featuregroups_list":[{"version":"1"}]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/featureGroup', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+
+    @patch('trainingmgr.trainingmgr_main.get_feature_group_by_name_db', side_effect=Exception("Mocked Error"))
+    def test_negative_delete_list_of_feature_group_5(self, mock1):
+        delete_req=delete_req={"featuregroups_list":[{"featureGroup_name":"testing_hash"}]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/featureGroup', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+
+    @patch('trainingmgr.trainingmgr_main.get_feature_group_by_name_db', return_value=None)
+    def test_negative_delete_list_of_feature_group_6(self, mock1):
+        delete_req=delete_req={"featuregroups_list":[{"featureGroup_name":"testing_hash"}]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/featureGroup', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+
+    the_result2=[('testing', '', 'InfluxSource', True, '21.0.0.21', '12345', '', '', '', '')]
+    resp2=Response()
+    resp2.status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
+    @patch('trainingmgr.trainingmgr_main.get_feature_group_by_name_db', return_value=the_result2)
+    @patch('trainingmgr.trainingmgr_main.delete_feature_group_by_name', return_value=resp2)
+    def test_negative_delete_list_of_feature_group_7(self, mock1, mock2):
+        delete_req=delete_req={"featuregroups_list":[{"featureGroup_name":"testing_hash"}]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/featureGroup', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+
+class Test_delete_list_of_trainingjob_version:
+    @patch('trainingmgr.common.trainingmgr_config.TMLogger', return_value = TMLogger("tests/common/conf_log.yaml"))
+    def setup_method(self,mock1,mock2):
+        self.client = trainingmgr_main.APP.test_client(self)
+        self.logger = trainingmgr_main.LOGGER
+    
+    mocked_TRAININGMGR_CONFIG_OBJ=mock.Mock(name="TRAININGMGR_CONFIG_OBJ")
+    attrs_TRAININGMGR_CONFIG_OBJ = {'my_ip.return_value': '123'}
+    mocked_TRAININGMGR_CONFIG_OBJ.configure_mock(**attrs_TRAININGMGR_CONFIG_OBJ)
+    mocked_mm_sdk=mock.Mock(name="MM_SDK")
+    attrs_mm_sdk = {'is_bucket_present.return_value': True}
+    attrs_mm_sdk = {'delete_model_metric.return_value': True}
+    mocked_mm_sdk.configure_mock(**attrs_mm_sdk)
+    the_result=[('usecase7', 'auto test', '*', 'prediction with model name', 'Default', '{"arguments": {"epochs": "1", "usecase": "usecase7"}}', 'Enb=20 and Cellnum=6', datetime.datetime(2022, 9, 20,11, 40, 30), '7d09c0bf-7575-4475-86ff-5573fb3c4716', '{"DATA_EXTRACTION": "FINISHED", "DATA_EXTRACTION_AND_TRAINING": "FINISHED", "TRAINING": "FINISHED", "TRAINING_AND_TRAINED_MODEL": "FINISHED", "TRAINED_MODEL": "FINISHED"}', datetime.datetime(2022, 9, 20, 11, 42, 20), 1, True, 'Near RT RIC', '{"datalake_source": {"CassandraSource": {}}}', '{"datalake_source": {"CassandraSource": {}}}','http://10.0.0.47:32002/model/usecase7/1/Model.zip','','','','','')]
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.isinstance', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.TRAININGMGR_CONFIG_OBJ', return_value = mocked_TRAININGMGR_CONFIG_OBJ)
+    @patch('trainingmgr.trainingmgr_main.get_info_by_version', return_value=the_result)
+    @patch('trainingmgr.trainingmgr_main.get_one_word_status', return_value="FINISHED")
+    @patch('trainingmgr.trainingmgr_main.change_field_value_by_version')
+    @patch('trainingmgr.trainingmgr_main.MM_SDK', return_value = mocked_mm_sdk)
+    @patch('trainingmgr.trainingmgr_main.delete_trainingjob_version')
+    def test_delete_list_of_trainingjob_version(self, mock1, mock2, mock3, mock4, mock5, mock6, mock7, mock8):
+        delete_req={"list":[{"trainingjob_name":"testing_dme_02","version":1}]}
+        expected_res=b'{"success count": 1, "failure count": 0}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_res
+        assert response.status_code == 200 , "status code is not equal"
+    
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=False)
+    def test_negative_delete_list_of_trainingjob_version_1(self, mock1):
+        delete_req={"list":[{"trainingjob_name":"testing_dme_02","version":1}]}
+        expected_response=b'{"Exception": "Wrong Request syntax"}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        print("response data", response.data)
+        assert response.data==expected_response
+        assert response.status_code==400, "status code not equal"
+
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.isinstance', return_value=False)
+    def test_negative_delete_list_of_trainingjob_version_2(self, mock1, mock2):
+        delete_req={"list":[{"trainingjob_name":"testing_dme_02","version":1}]}
+        expected_response=b'{"Exception": "not given as list"}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        print("response data", response.data)
+        assert response.data==expected_response
+        assert response.status_code==400, "status code not equal"
+    
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    def test_negative_delete_list_of_trainingjob_version_3(self, mock1):
+        delete_req=delete_req={"list":[("trainingjob_name")]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+    
+    def test_negative_delete_list_of_trainingjob_version_4(self):
+        delete_req=delete_req={"list":[{"trainingjob_name":"testing_dme_02"}]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+    
+    mocked_TRAININGMGR_CONFIG_OBJ=mock.Mock(name="TRAININGMGR_CONFIG_OBJ")
+    attrs_TRAININGMGR_CONFIG_OBJ = {'my_ip.return_value': '123'}
+    mocked_TRAININGMGR_CONFIG_OBJ.configure_mock(**attrs_TRAININGMGR_CONFIG_OBJ)
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.isinstance', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.TRAININGMGR_CONFIG_OBJ', return_value = mocked_TRAININGMGR_CONFIG_OBJ)
+    @patch('trainingmgr.trainingmgr_main.get_info_by_version', side_effect=Exception("Mocked Error"))
+    def test_negative_delete_list_of_trainingjob_version_5(self, mock1, mock2, mock3,mock4):
+        delete_req=delete_req={"list":[{"trainingjob_name":"testing_dme_02","version":1}]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+    
+    mocked_TRAININGMGR_CONFIG_OBJ=mock.Mock(name="TRAININGMGR_CONFIG_OBJ")
+    attrs_TRAININGMGR_CONFIG_OBJ = {'my_ip.return_value': '123'}
+    mocked_TRAININGMGR_CONFIG_OBJ.configure_mock(**attrs_TRAININGMGR_CONFIG_OBJ)
+    the_result2=[('mynetwork', 'testing', '*', 'testing_pipeline', 'Default', '{"arguments": {"epochs": "1", "trainingjob_name": "mynetwork"}}', '', datetime.datetime(2023, 2, 9, 9, 2, 11, 13916), 'No data available', '{"DATA_EXTRACTION": "FINISHED", "DATA_EXTRACTION_AND_TRAINING": "IN_PROGRESS", "TRAINING": "NOT_STARTED", "TRAINING_AND_TRAINED_MODEL": "NOT_STARTED", "TRAINED_MODEL": "NOT_STARTED"}', datetime.datetime(2023, 2, 9, 9, 2, 11, 13916), 1, False, '2', '{"datalake_source": {"InfluxSource": {}}}', 'No data available.', '', 'liveCell', 'UEData', True)]
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.isinstance', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.TRAININGMGR_CONFIG_OBJ', return_value = mocked_TRAININGMGR_CONFIG_OBJ)
+    @patch('trainingmgr.trainingmgr_main.get_info_by_version', return_value=the_result2)
+    def test_negative_delete_list_of_trainingjob_version_6(self, mock1, mock2, mock3,mock4):
+        delete_req=delete_req={"list":[{"trainingjob_name":"testing_dme_02","version":1}]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+    
+    mocked_TRAININGMGR_CONFIG_OBJ=mock.Mock(name="TRAININGMGR_CONFIG_OBJ")
+    attrs_TRAININGMGR_CONFIG_OBJ = {'my_ip.return_value': '123'}
+    mocked_TRAININGMGR_CONFIG_OBJ.configure_mock(**attrs_TRAININGMGR_CONFIG_OBJ)
+    the_result3=[('mynetwork', 'testing', '*', 'testing_pipeline', 'Default', '{"arguments": {"epochs": "1", "trainingjob_name": "mynetwork"}}', '', datetime.datetime(2023, 2, 9, 9, 2, 11, 13916), 'No data available', '{"DATA_EXTRACTION": "FINISHED", "DATA_EXTRACTION_AND_TRAINING": "IN_PROGRESS", "TRAINING": "NOT_STARTED", "TRAINING_AND_TRAINED_MODEL": "NOT_STARTED", "TRAINED_MODEL": "NOT_STARTED"}', datetime.datetime(2023, 2, 9, 9, 2, 11, 13916), 1, False, '2', '{"datalake_source": {"InfluxSource": {}}}', 'No data available.', '', 'liveCell', 'UEData', False)]
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.isinstance', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.TRAININGMGR_CONFIG_OBJ', return_value = mocked_TRAININGMGR_CONFIG_OBJ)
+    @patch('trainingmgr.trainingmgr_main.get_info_by_version', return_value=the_result3)
+    @patch('trainingmgr.trainingmgr_main.get_one_word_status', return_value="wrong status")
+    def test_negative_delete_list_of_trainingjob_version_7(self, mock1, mock2, mock3,mock4, mock5):
+        delete_req=delete_req={"list":[{"trainingjob_name":"testing_dme_02","version":1}]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+    
+    mocked_TRAININGMGR_CONFIG_OBJ=mock.Mock(name="TRAININGMGR_CONFIG_OBJ")
+    attrs_TRAININGMGR_CONFIG_OBJ = {'my_ip.return_value': '123'}
+    mocked_TRAININGMGR_CONFIG_OBJ.configure_mock(**attrs_TRAININGMGR_CONFIG_OBJ)
+    the_result4=[('mynetwork', 'testing', '*', 'testing_pipeline', 'Default', '{"arguments": {"epochs": "1", "trainingjob_name": "mynetwork"}}', '', datetime.datetime(2023, 2, 9, 9, 2, 11, 13916), 'No data available', '{"DATA_EXTRACTION": "FINISHED", "DATA_EXTRACTION_AND_TRAINING": "IN_PROGRESS", "TRAINING": "NOT_STARTED", "TRAINING_AND_TRAINED_MODEL": "NOT_STARTED", "TRAINED_MODEL": "NOT_STARTED"}', datetime.datetime(2023, 2, 9, 9, 2, 11, 13916), 1, False, '2', '{"datalake_source": {"InfluxSource": {}}}', 'No data available.', '', 'liveCell', 'UEData', False)]
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.isinstance', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.TRAININGMGR_CONFIG_OBJ', return_value = mocked_TRAININGMGR_CONFIG_OBJ)
+    @patch('trainingmgr.trainingmgr_main.get_info_by_version', return_value=the_result4)
+    @patch('trainingmgr.trainingmgr_main.get_one_word_status', return_value="FINISHED")
+    @patch('trainingmgr.trainingmgr_main.change_field_value_by_version',side_effect=Exception("Mocked Error"))
+    def test_negative_delete_list_of_trainingjob_version_8(self, mock1, mock2, mock3,mock4, mock5, mock6):
+        delete_req=delete_req={"list":[{"trainingjob_name":"testing_dme_02","version":1}]}
+        expected_response=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_response
+        assert response.status_code==200, "status code not equal"
+
+    mocked_TRAININGMGR_CONFIG_OBJ=mock.Mock(name="TRAININGMGR_CONFIG_OBJ")
+    attrs_TRAININGMGR_CONFIG_OBJ = {'my_ip.return_value': '123'}
+    mocked_TRAININGMGR_CONFIG_OBJ.configure_mock(**attrs_TRAININGMGR_CONFIG_OBJ)
+    mocked_mm_sdk=mock.Mock(name="MM_SDK")
+    attrs_mm_sdk = {'is_bucket_present.return_value': True}
+    attrs_mm_sdk = {'delete_model_metric.return_value': True}
+    mocked_mm_sdk.configure_mock(**attrs_mm_sdk)
+    the_result=[('usecase7', 'auto test', '*', 'prediction with model name', 'Default', '{"arguments": {"epochs": "1", "usecase": "usecase7"}}', 'Enb=20 and Cellnum=6', datetime.datetime(2022, 9, 20,11, 40, 30), '7d09c0bf-7575-4475-86ff-5573fb3c4716', '{"DATA_EXTRACTION": "FINISHED", "DATA_EXTRACTION_AND_TRAINING": "FINISHED", "TRAINING": "FINISHED", "TRAINING_AND_TRAINED_MODEL": "FINISHED", "TRAINED_MODEL": "FINISHED"}', datetime.datetime(2022, 9, 20, 11, 42, 20), 1, True, 'Near RT RIC', '{"datalake_source": {"CassandraSource": {}}}', '{"datalake_source": {"CassandraSource": {}}}','http://10.0.0.47:32002/model/usecase7/1/Model.zip','','','','','')]
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.isinstance', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.TRAININGMGR_CONFIG_OBJ', return_value = mocked_TRAININGMGR_CONFIG_OBJ)
+    @patch('trainingmgr.trainingmgr_main.get_info_by_version', return_value=the_result)
+    @patch('trainingmgr.trainingmgr_main.get_one_word_status', return_value="FINISHED")
+    @patch('trainingmgr.trainingmgr_main.change_field_value_by_version')
+    @patch('trainingmgr.trainingmgr_main.MM_SDK', return_value = mocked_mm_sdk)
+    @patch('trainingmgr.trainingmgr_main.delete_trainingjob_version', side_effect=Exception("Mocked Error"))
+    def test_negative_delete_list_of_trainingjob_version_9(self, mock1, mock2, mock3, mock4, mock5, mock6, mock7, mock8):
+        delete_req={"list":[{"trainingjob_name":"testing_dme_02","version":1}]}
+        expected_res=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_res
+        assert response.status_code == 200 , "status code is not equal"
+
+    mocked_TRAININGMGR_CONFIG_OBJ=mock.Mock(name="TRAININGMGR_CONFIG_OBJ")
+    attrs_TRAININGMGR_CONFIG_OBJ = {'my_ip.return_value': '123'}
+    mocked_TRAININGMGR_CONFIG_OBJ.configure_mock(**attrs_TRAININGMGR_CONFIG_OBJ)
+    @patch('trainingmgr.trainingmgr_main.check_key_in_dictionary', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.isinstance', return_value=True)
+    @patch('trainingmgr.trainingmgr_main.TRAININGMGR_CONFIG_OBJ', return_value = mocked_TRAININGMGR_CONFIG_OBJ)
+    @patch('trainingmgr.trainingmgr_main.get_info_by_version', return_value=None)
+    def test_negative_delete_list_of_trainingjob_version_10(self, mock1, mock2, mock3, mock4):
+        delete_req={"list":[{"trainingjob_name":"testing_dme_02","version":1}]}
+        expected_res=b'{"success count": 0, "failure count": 1}'
+        response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json")
+        assert response.data==expected_res
+        assert response.status_code == 200 , "status code is not equal"
+    
\ No newline at end of file
index e8cf9ca..15d12ea 100644 (file)
@@ -1091,10 +1091,8 @@ def delete_list_of_trainingjob_version():
         all exception are provided with exception message and HTTP status code.
     """
     LOGGER.debug('request comes for deleting:' + json.dumps(request.json))
-    try:
-        check_key_in_dictionary(["list"], request.json)
-    except Exception as err:
-        raise APIException(status.HTTP_400_BAD_REQUEST, str(err)) from None
+    if not check_key_in_dictionary(["list"], request.json):
+        raise APIException(status.HTTP_400_BAD_REQUEST, "Wrong Request syntax") from None
 
     list_of_trainingjob_version = request.json['list']
     if not isinstance(list_of_trainingjob_version, list):
@@ -1110,11 +1108,9 @@ def delete_list_of_trainingjob_version():
             LOGGER.debug(str(my_dict) + "did not pass dictionary")
             continue
 
-        try:
-            check_key_in_dictionary(["trainingjob_name", "version"], my_dict)
-        except Exception as err:
+        if not check_key_in_dictionary(["trainingjob_name", "version"], my_dict):
             not_possible_to_delete.append(my_dict)
-            LOGGER.debug(str(err))
+            LOGGER.debug("key trainingjob_name or version not in the request")
             continue
 
         trainingjob_name = my_dict['trainingjob_name']
@@ -1502,11 +1498,9 @@ def delete_list_of_feature_group():
         all exception are provided with exception message and HTTP status code.
     """
     LOGGER.debug('request comes for deleting:' + json.dumps(request.json))
-    try:
-        check_key_in_dictionary(["featuregroups_list"], request.json)
-    except Exception as err:
+    if not check_key_in_dictionary(["featuregroups_list"], request.json):
         LOGGER.debug("exception in check_key_in_dictionary")
-        raise APIException(status.HTTP_400_BAD_REQUEST, str(err)) from None
+        raise APIException(status.HTTP_400_BAD_REQUEST, "Wrong Request syntax") from None
 
     list_of_feature_groups = request.json['featuregroups_list']
     if not isinstance(list_of_feature_groups, list):
@@ -1522,11 +1516,9 @@ def delete_list_of_feature_group():
             LOGGER.debug(str(my_dict) + "did not pass dictionary")
             continue
         
-        try:
-            check_key_in_dictionary(["featureGroup_name"], my_dict)
-        except Exception as err:
+        if not check_key_in_dictionary(["featureGroup_name"], my_dict):
             not_possible_to_delete.append(my_dict)
-            LOGGER.debug(str(err))
+            LOGGER.debug("key featureGroup_name is not present in the request")
             continue
 
         featuregroup_name = my_dict['featureGroup_name']
@@ -1545,7 +1537,11 @@ def delete_list_of_feature_group():
                 if dme :
                     dme_host=results[0][4]
                     dme_port=results[0][5]
-                    delete_dme_filtered_data_job(TRAININGMGR_CONFIG_OBJ, featuregroup_name, dme_host, dme_port)
+                    resp=delete_dme_filtered_data_job(TRAININGMGR_CONFIG_OBJ, featuregroup_name, dme_host, dme_port)
+                    if(resp.status_code !=status.HTTP_204_NO_CONTENT):
+                        not_possible_to_delete.append(my_dict)  
+                        LOGGER.debug("Cannot delete the dme_data_job"+ featuregroup_name)
+                        continue
                 possible_to_delete.append(my_dict)
             except Exception as err:
                 not_possible_to_delete.append(my_dict)