diff --git a/QA/QA_Service/test/t_qa_service.py b/QA/QA_Service/test/t_qa_service.py index 618aa84f68632767606eefa3b24ae98e485bf295..456aa9d0949677689fc3c722c2382364dcf5ce7e 100755 --- a/QA/QA_Service/test/t_qa_service.py +++ b/QA/QA_Service/test/t_qa_service.py @@ -93,7 +93,6 @@ class TestQAService(unittest.TestCase): def setUpClass(cls) -> None: cls.TEST_UUID = uuid.uuid1() cls.TEST_OTDB_ID = 999999 - cls.TEST_TMSS_ID = 2000001#+999999 cls.tmp_exchange = TemporaryExchange("%s_%s" % (cls.__name__, cls.TEST_UUID)) cls.tmp_exchange.open() @@ -505,7 +504,9 @@ class TestQAService(unittest.TestCase): the intermediate steps are tested in other tests/modules. ''' logger.info(' -- test_05_qa_service_for_expected_behaviour_on_tmss_events -- ') - import requests + + from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator + from lofar.sas.tmss.tmss.tmssapp.subtasks import create_observation_to_qafile_subtask, create_qafile_to_qaplots_subtask # override the mock behaviour from setUp for this specific test def mocked_wrap_command_for_docker(cmd, image_name=None, image_label=None): @@ -513,9 +514,8 @@ class TestQAService(unittest.TestCase): # by a call to the create_test_hypercube which fakes the ms2hdf5 conversion for this test. if 'ms2hdf5' in cmd: # the create_test_hypercube executable should be available in the PATH environment - hdf5_path = QAService.h5_lustre_filepath(self.TEST_TMSS_ID) - mocked_cmd = ['create_test_hypercube', '-s 4', '-S 8', '-t 16', - '-o', str(self.TEST_TMSS_ID), hdf5_path] + hdf5_path = os.path.join(cmd[cmd.index('--output_dir')+1], cmd[cmd.index('--output_filename')+1]) + mocked_cmd = ['create_test_hypercube', '-s 4', '-S 8', '-t 16', hdf5_path] logger.info('''mocked_wrap_command_for_docker returning mocked command to create test h5 file: '%s', instead of original command: '%s' ''', ' '.join(mocked_cmd), ' '.join(cmd)) return mocked_cmd @@ -544,14 +544,25 @@ class TestQAService(unittest.TestCase): # start the QAService (the object under test) qaservice = QAService(exchange=self.tmp_exchange.address) + tmss_client = self.tmss_test_env.create_tmss_client() - with qaservice, BusListenerJanitor(qaservice.filtering_otdbbuslistener), BusListenerJanitor(qaservice.filtering_tmssbuslistener), BusListenerJanitor(qaservice.commands_buslistener): + with qaservice, tmss_client, BusListenerJanitor(qaservice.filtering_otdbbuslistener), BusListenerJanitor(qaservice.filtering_tmssbuslistener), BusListenerJanitor(qaservice.commands_buslistener): # start listening for QA event messages from the QAService with BusListenerJanitor(SynchronizationQABusListener(exchange=self.tmp_exchange.address)) as qa_listener: + tdc = TMSSRESTTestDataCreator(django_api_url=self.tmss_test_env.django_server.url, + auth=(self.tmss_test_env.client_credentials.dbcreds.user, + self.tmss_test_env.client_credentials.dbcreds.password)) + specifications_template_url = tdc.post_data_and_get_url(tdc.SubtaskTemplate(subtask_type_url=tdc.django_api_url+'/subtask_type/qa_files/'), '/subtask_template/') + subtask_url = tdc.post_data_and_get_url(tdc.Subtask(specifications_template_url=specifications_template_url), '/subtask/') + subtask_id = subtask_url.split('/')[-2] + + specifications_template_url2 = tdc.post_data_and_get_url(tdc.SubtaskTemplate(subtask_type_url=tdc.django_api_url+'/subtask_type/qa_plots/'), '/subtask_template/') + subtask_url2 = tdc.post_data_and_get_url(tdc.Subtask(specifications_template_url=specifications_template_url2), '/subtask/') + subtask_id2 = subtask_url2.split('/')[-2] + # trigger a qa process by setting the tmss subtask to scheduled # this will result in the QAService actually doing its magic - with self.tmss_test_env.create_tmss_client() as client: - client.set_subtask_status(self.TEST_TMSS_ID, 'scheduled') + tmss_client.set_subtask_status(subtask_id, 'scheduled') # start waiting until ConvertedMS2Hdf5 event message received (or timeout) qa_listener.converted_event.wait(30) @@ -560,7 +571,7 @@ class TestQAService(unittest.TestCase): self.assertTrue(qa_listener.converted_event.is_set()) # check the converted_msg_content - self.assertTrue('otdb_id' in qa_listener.converted_msg_content) + self.assertTrue('subtask_id' in qa_listener.converted_msg_content) self.assertTrue('hdf5_file_path' in qa_listener.converted_msg_content) @@ -572,9 +583,10 @@ class TestQAService(unittest.TestCase): self.assertTrue(qa_listener.clustered_event.is_set()) # check the clustered_msg_content - self.assertTrue('otdb_id' in qa_listener.clustered_msg_content) + self.assertTrue('subtask_id' in qa_listener.clustered_msg_content) self.assertTrue('hdf5_file_path' in qa_listener.clustered_msg_content) + tmss_client.set_subtask_status(subtask_id2, 'scheduled') # start waiting until CreatedInspectionPlots event message received (or timeout) qa_listener.plotted_event.wait(30)