Skip to content
Snippets Groups Projects
Commit 18233c89 authored by goei's avatar goei
Browse files

TMSS-207: Update testcases for subtask unittesting. Renamed...

TMSS-207: Update testcases for subtask unittesting. Renamed t_specify_observation to t_task. There were old call used which not existed any more.
parent fbea332a
No related branches found
No related tags found
1 merge request!175Resolve TMSS-207
...@@ -164,7 +164,7 @@ def create_qaplots_subtask_from_task_blueprint(task_blueprint: TaskBlueprint) -> ...@@ -164,7 +164,7 @@ def create_qaplots_subtask_from_task_blueprint(task_blueprint: TaskBlueprint) ->
qafile_subtasks = [st for st in task_blueprint.subtasks.all() if st.specifications_template.type.value == SubtaskType.Choices.QA_FILES.value] qafile_subtasks = [st for st in task_blueprint.subtasks.all() if st.specifications_template.type.value == SubtaskType.Choices.QA_FILES.value]
if not qafile_subtasks: if not qafile_subtasks:
raise ValueError("Cannot create %s subtask for task_blueprint id=%d because it has no qafile subtask(s)" % ( raise ValueError("Cannot create %s subtask for task_blueprint id=%d because it has no qafile subtask(s)" % (
SubtaskType.Choices.QA_FILES.value, task_blueprint.pk)) SubtaskType.Choices.QA_PLOTS.value, task_blueprint.pk))
qafile_subtask = qafile_subtasks[0] # TODO: decide what to do when there are multiple qafile subtasks? qafile_subtask = qafile_subtasks[0] # TODO: decide what to do when there are multiple qafile subtasks?
return create_qaplots_subtask_from_qafile_subtask(qafile_subtask) return create_qaplots_subtask_from_qafile_subtask(qafile_subtask)
......
...@@ -29,7 +29,7 @@ if(BUILD_TESTING) ...@@ -29,7 +29,7 @@ if(BUILD_TESTING)
lofar_add_test(t_tmss_session_auth) lofar_add_test(t_tmss_session_auth)
lofar_add_test(t_subtasks) lofar_add_test(t_subtasks)
lofar_add_test(t_parset_adapter) lofar_add_test(t_parset_adapter)
lofar_add_test(t_specify_observation) lofar_add_test(t_tasks)
set_tests_properties(t_tmssapp_scheduling_REST_API PROPERTIES TIMEOUT 300) set_tests_properties(t_tmssapp_scheduling_REST_API PROPERTIES TIMEOUT 300)
set_tests_properties(t_tmssapp_specification_REST_API PROPERTIES TIMEOUT 300) set_tests_properties(t_tmssapp_specification_REST_API PROPERTIES TIMEOUT 300)
......
#!/bin/sh
./runctest.sh t_specify_observation
\ No newline at end of file
...@@ -39,9 +39,44 @@ from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator ...@@ -39,9 +39,44 @@ from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator
from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.tmss.tmssapp import models
from lofar.sas.tmss.tmss.tmssapp.subtasks import connect_observation_subtask_to_preprocessing_subtask from lofar.sas.tmss.tmss.tmssapp.subtasks import *
# The following methods should be tested
# check_prerequities_for_subtask_creation
# create_subtasks_from_task_blueprint
# create_observation_control_subtask_from_task_blueprint
# create_qafile_subtask_from_task_blueprint
# create_qafile_subtask_from_observation_subtask
# create_qaplots_subtask_from_task_blueprint
# create_qaplots_subtask_from_qafile_subtask
# create_preprocessing_subtask_from_task_blueprint
#
# schedule_subtask
# check_prerequities_for_scheduling
# schedule_qafile_subtask
# schedule_qaplots_subtask
# schedule_observation_subtask
# schedule_pipeline_subtask
#
# create_and_schedule_subtasks_from_task_blueprint
class SubtasksTest(unittest.TestCase):
class SubTasksCreationFromSubTask(unittest.TestCase):
@staticmethod
def create_subtask_object(subtask_type_value, subtask_state_value):
"""
Helper function to create a subtask object for testing with given subtask value and subtask state value
as string (no object)
"""
template_type = models.SubtaskType.objects.get(value=subtask_type_value)
subtask_template_obj = SubTasksCreationFromSubTask.create_subtask_template(template_type)
subtask_state_obj = models.SubtaskState.objects.get(value=subtask_state_value)
subtask_data = Subtask_test_data(subtask_template=subtask_template_obj, state=subtask_state_obj)
return models.Subtask.objects.create(**subtask_data)
@staticmethod @staticmethod
def create_subtask_template(template_type: object): def create_subtask_template(template_type: object):
...@@ -49,45 +84,150 @@ class SubtasksTest(unittest.TestCase): ...@@ -49,45 +84,150 @@ class SubtasksTest(unittest.TestCase):
subtask_template_data['type'] = template_type subtask_template_data['type'] = template_type
return models.SubtaskTemplate.objects.create(**subtask_template_data) return models.SubtaskTemplate.objects.create(**subtask_template_data)
@staticmethod def test_create_qafile_subtask_from_observation_subtask_failed(self):
def create_subtask(template_type: object): """
subtask_template = SubtasksTest.create_subtask_template(template_type) Test if creation of subtask qafile failed due to wrong state or wrong type of the predecessor subtask
subtask_data = Subtask_test_data(subtask_template=subtask_template) Correct state should be 'defined' and correct type should be 'observation' (for this test of course it is not)
return models.Subtask.objects.create(**subtask_data) """
subtasks = [self.create_subtask_object("pipeline", "defined"),
def test_connect_observation_to_preprocessing_fails_on_wrong_subtask_type(self): self.create_subtask_object("observation", "defining"),
subtask_1 = self.create_subtask(models.SubtaskType.objects.get(value='observation')) self.create_subtask_object("observation", "defining") ]
subtask_2 = self.create_subtask(models.SubtaskType.objects.get(value='observation')) for subtask in subtasks:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
connect_observation_subtask_to_preprocessing_subtask(subtask_1, subtask_2) create_qafile_subtask_from_observation_subtask(subtask)
def test_connect_observation_to_preprocessing_succeeds_on_correct_subtask_type(self): def test_create_qafile_subtask_from_observation_subtask_succeed(self):
subtask_1 = self.create_subtask(models.SubtaskType.objects.get(value='observation')) """
subtask_2 = self.create_subtask(models.SubtaskType.objects.get(value='pipeline')) Test if creation of subtask qafile succeed
subtaskoutput = models.SubtaskOutput.objects.create(**SubtaskOutput_test_data(subtask=subtask_1)) Check if the created subtask has correct subtask state and value (TODO)
models.Dataproduct.objects.create(**Dataproduct_test_data(producer=subtaskoutput)) """
connect_observation_subtask_to_preprocessing_subtask(subtask_1, subtask_2) predecessor_subtask = self.create_subtask_object("observation", "defined")
subtask = create_qafile_subtask_from_observation_subtask(predecessor_subtask)
def test_connect_observation_to_preprocessing_produces_correct_dataproducts(self): # subtask object is None because QA file conversion is by default not enabled!!!!
subtask_1 = self.create_subtask(models.SubtaskType.objects.get(value='observation')) self.assertEqual(None, subtask)
subtask_2 = self.create_subtask(models.SubtaskType.objects.get(value='pipeline'))
subtaskoutput = models.SubtaskOutput.objects.create(**SubtaskOutput_test_data(subtask=subtask_1)) def test_create_qaplots_subtask_from_qafile_subtask_failed(self):
dataproducts = [] """
for f_in in ['whatever.ms', 'L1234_SB001.ms', 'L1234__SB002_XYZ.ms']: Test if creation of subtask qaplots failed due to wrong state or wrong type of the predecessor subtask
dataproducts.append(models.Dataproduct.objects.create(**Dataproduct_test_data(producer=subtaskoutput, Correct type should be 'qa_files' (for this test of course it is not)
filename=f_in))) """
connect_observation_subtask_to_preprocessing_subtask(subtask_1, subtask_2) subtasks = [self.create_subtask_object("pipeline", "defined"),
self.create_subtask_object("observation", "defining"),
# check that observation output dataproducts are input to pipeline self.create_subtask_object("observation", "defining") ]
for dp in dataproducts: for subtask in subtasks:
self.assertTrue(dp in subtask_2.inputs.first().dataproducts.all()) with self.assertRaises(ValueError):
create_qaplots_subtask_from_qafile_subtask(subtask)
# check that pipeline output dataproducts have appropriate names
out_filenames = [dataproduct.filename for dataproduct in subtask_2.outputs.first().dataproducts.all()] def test_create_qaplots_subtask_from_qafile_subtask_succeed(self):
for f_out in ['L%s_whatever.ms' % subtask_2.pk, 'L%s_SB001.ms' % subtask_2.pk, 'L%s__SB002_XYZ.ms' % subtask_2.pk]: """
self.assertTrue(f_out in out_filenames) Test if creation of subtask qaplots succeed
Check if the created subtask has correct subtask state and value (TODO)
"""
predecessor_subtask = self.create_subtask_object("qa_files", "defined")
subtask = create_qaplots_subtask_from_qafile_subtask(predecessor_subtask)
# subtask object is None because QA plots is by default not enabled!!!!
self.assertEqual(None, subtask)
class SubTasksCreationFromTaskBluePrint(unittest.TestCase):
@staticmethod
def create_task_blueprint_object(task_template_name="correlator schema", QA_enabled=False):
"""
Helper function to create a task blueprint object for testing with given task template name value
as string (no object)
"""
task_blueprint_data = TaskBlueprint_test_data()
task_blueprint_obj = models.TaskBlueprint.objects.create(**task_blueprint_data)
task_blueprint_obj.specifications_template.name = task_template_name
task_blueprint_obj.specifications_doc = {
"QA": {
"plots": {
"enabled": QA_enabled,
"autocorrelation": True,
"crosscorrelation": True
},
"file_conversion": {
"enabled": QA_enabled,
"nr_of_subbands": -1,
"nr_of_timestamps": 256
}
}
}
return task_blueprint_obj
def test_create_sequence_of_subtask_from_task_blueprint(self):
"""
Create multiple subtasks from a task blueprint, executed in correct order.
No exception should occur, check name, type and state of the subtask
"""
task_blueprint = self.create_task_blueprint_object()
subtask = create_observation_control_subtask_from_task_blueprint(task_blueprint)
self.assertEqual("defined", str(subtask.state))
self.assertEqual("observationcontrol schema", str(subtask.specifications_template.name))
self.assertEqual("observation", str(subtask.specifications_template.type))
# Next call requires an observation subtask already created
subtask = create_qafile_subtask_from_task_blueprint(task_blueprint)
# subtask object is None because QA file conversion is by default not enabled!!!!
self.assertEqual(None, subtask)
# Next call will fail due to no qa_files object
# ValueError: Cannot create qa_plots subtask for task_blueprint id=1 because it has no qafile subtask(s)
with self.assertRaises(ValueError):
subtask = create_qaplots_subtask_from_task_blueprint(task_blueprint)
# subtask = create_preprocessing_subtask_from_task_blueprint(task_blueprint)
def test_create_sequence_of_subtask_from_task_blueprint_with_QA_enabled(self):
"""
Create multiple subtasks from a task blueprint, executed in correct order.
QA plots and QA file conversion enabled
No exception should occur, check name, type and state of the subtasks
"""
# Enable QA plot and QA conversion
task_blueprint = self.create_task_blueprint_object(QA_enabled=True)
task_blueprint_preprocessing = self.create_task_blueprint_object("preprocessing schema")
subtask = create_observation_control_subtask_from_task_blueprint(task_blueprint)
self.assertEqual("defined", str(subtask.state))
self.assertEqual("observationcontrol schema", str(subtask.specifications_template.name))
self.assertEqual("observation", str(subtask.specifications_template.type))
# Next call requires an observation subtask already created
subtask = create_qafile_subtask_from_task_blueprint(task_blueprint)
self.assertEqual("defined", str(subtask.state))
self.assertEqual("QA file conversion", str(subtask.specifications_template.name))
self.assertEqual("qa_files", str(subtask.specifications_template.type))
# Next call requires an qaplots subtask already created
subtask = create_qaplots_subtask_from_task_blueprint(task_blueprint)
self.assertEqual("defined", str(subtask.state))
self.assertEqual("QA plots", str(subtask.specifications_template.name))
self.assertEqual("qa_plots", str(subtask.specifications_template.type))
# TODO: check why next call failed?
#subtask = create_preprocessing_subtask_from_task_blueprint(task_blueprint_preprocessing)
#self.assertEqual("defined", str(subtask.state))
def test_create_subtasks_from_task_blueprint_failure_on_schema(self):
"""
Test creation failure due to unknown schema (no correlator or preprocessing schema)
Check exception
"SubtaskCreationException: Cannot create subtasks for task id=1 because no generator exists for its schema name=unknown schema"
"""
task_blueprint = self.create_task_blueprint_object("unknown schema")
with self.assertRaises(SubtaskCreationException):
create_subtasks_from_task_blueprint(task_blueprint)
def test_create_subtasks_from_task_blueprint_succeed(self):
"""
"""
task_blueprint = self.create_task_blueprint_object(QA_enabled=True)
subtasks = create_subtasks_from_task_blueprint(task_blueprint)
self.assertEqual(3, len(subtasks))
# TODO Test the Schedule calls
if __name__ == "__main__": if __name__ == "__main__":
os.environ['TZ'] = 'UTC' os.environ['TZ'] = 'UTC'
unittest.main() unittest.main()
...@@ -39,7 +39,7 @@ from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator ...@@ -39,7 +39,7 @@ from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator
rest_data_creator = TMSSRESTTestDataCreator(BASE_URL, AUTH) rest_data_creator = TMSSRESTTestDataCreator(BASE_URL, AUTH)
from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.tmss.tmssapp import models
from lofar.sas.tmss.tmss.tmssapp.tasks import create_task_blueprint_from_task_draft_and_instantiate_subtasks_from_template from lofar.sas.tmss.tmss.tmssapp.tasks import *
class SpecifyObservationFromTaskDraftTest(unittest.TestCase): class SpecifyObservationFromTaskDraftTest(unittest.TestCase):
...@@ -51,7 +51,7 @@ class SpecifyObservationFromTaskDraftTest(unittest.TestCase): ...@@ -51,7 +51,7 @@ class SpecifyObservationFromTaskDraftTest(unittest.TestCase):
""" """
task_draft = models.TaskDraft.objects.get(id=1) task_draft = models.TaskDraft.objects.get(id=1)
res_task_draft = GET_and_assert_equal_expected_code(self, BASE_URL + '/task_draft/1/', 200) res_task_draft = GET_and_assert_equal_expected_code(self, BASE_URL + '/task_draft/1/', 200)
task_blueprint = create_task_blueprint_from_task_draft_and_instantiate_subtasks_from_template(task_draft) task_blueprint = create_task_blueprint_and_subtasks_and_schedule_subtasks_from_task_draft(task_draft)
self.assertEqual(task_draft.name, task_blueprint.draft.name) self.assertEqual(task_draft.name, task_blueprint.draft.name)
res_task_blueprint = GET_and_assert_equal_expected_code(self, BASE_URL + '/task_blueprint/1/', 200) res_task_blueprint = GET_and_assert_equal_expected_code(self, BASE_URL + '/task_blueprint/1/', 200)
self.assertEqual(len(res_task_blueprint['subtasks']), 3) self.assertEqual(len(res_task_blueprint['subtasks']), 3)
...@@ -59,7 +59,7 @@ class SpecifyObservationFromTaskDraftTest(unittest.TestCase): ...@@ -59,7 +59,7 @@ class SpecifyObservationFromTaskDraftTest(unittest.TestCase):
for subtask_url in res_task_blueprint['subtasks']: for subtask_url in res_task_blueprint['subtasks']:
res_subtask = GET_and_assert_equal_expected_code(self, subtask_url, 200) res_subtask = GET_and_assert_equal_expected_code(self, subtask_url, 200)
state_value = GET_and_assert_equal_expected_code(self, res_subtask['state'], 200)['value'] state_value = GET_and_assert_equal_expected_code(self, res_subtask['state'], 200)['value']
self.assertEqual(state_value, "defined") # TODO not all scheduled??? self.assertEqual(state_value, "scheduled")
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
# Run the unit test # Run the unit test
source python-coverage.sh source python-coverage.sh
python_coverage_test "*tmss*" t_specify_observation.py python_coverage_test "*tmss*" t_tasks.py
#!/bin/sh
./runctest.sh t_tasks
\ No newline at end of file
...@@ -282,7 +282,7 @@ def SubtaskInput_test_data(subtask: models.Subtask=None, producer: models.Subtas ...@@ -282,7 +282,7 @@ def SubtaskInput_test_data(subtask: models.Subtask=None, producer: models.Subtas
"tags":[]} "tags":[]}
def Subtask_test_data(task_blueprint: models.TaskBlueprint=None, subtask_template: models.SubtaskTemplate=None, def Subtask_test_data(task_blueprint: models.TaskBlueprint=None, subtask_template: models.SubtaskTemplate=None,
specifications_doc: dict=None, start_time=None, stop_time=None, cluster=None) -> dict: specifications_doc: dict=None, start_time=None, stop_time=None, cluster=None, state=None) -> dict:
if task_blueprint is None: if task_blueprint is None:
task_blueprint = models.TaskBlueprint.objects.create(**TaskBlueprint_test_data()) task_blueprint = models.TaskBlueprint.objects.create(**TaskBlueprint_test_data())
...@@ -302,9 +302,12 @@ def Subtask_test_data(task_blueprint: models.TaskBlueprint=None, subtask_templat ...@@ -302,9 +302,12 @@ def Subtask_test_data(task_blueprint: models.TaskBlueprint=None, subtask_templat
if cluster is None: if cluster is None:
cluster = models.Cluster.objects.create(name="dummy cluster", location="downstairs", tags=[]) cluster = models.Cluster.objects.create(name="dummy cluster", location="downstairs", tags=[])
if state is None:
state = models.SubtaskState.objects.get(value='defining')
return { "start_time": start_time, return { "start_time": start_time,
"stop_time": stop_time, "stop_time": stop_time,
"state": models.SubtaskState.objects.get(value='defining'), "state": state,
"specifications_doc": specifications_doc, "specifications_doc": specifications_doc,
"task_blueprint": task_blueprint, "task_blueprint": task_blueprint,
"specifications_template": subtask_template, "specifications_template": subtask_template,
......
...@@ -252,7 +252,8 @@ class TMSSRESTTestDataCreator(): ...@@ -252,7 +252,8 @@ class TMSSRESTTestDataCreator():
"requirements_doc": "{}", "requirements_doc": "{}",
"do_cancel": False, "do_cancel": False,
"draft": scheduling_unit_draft_url, "draft": scheduling_unit_draft_url,
"requirements_template": template_url} "requirements_template": template_url,
'task_blueprints': []}
def TaskBlueprint(self, name="my_TaskBlueprint", draft_url=None, template_url=None, scheduling_unit_blueprint_url=None): def TaskBlueprint(self, name="my_TaskBlueprint", draft_url=None, template_url=None, scheduling_unit_blueprint_url=None):
if draft_url is None: if draft_url is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment