Skip to content
Snippets Groups Projects
Commit f459341d authored by Mario Raciti's avatar Mario Raciti
Browse files

TMSS-857: Fix re-add CycleReportTest which was deleted by mistake

parent 402ee0f6
No related branches found
No related tags found
3 merge requests!634WIP: COBALT commissioning delta,!516Resolve TMSS-857,!481Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.
...@@ -455,6 +455,108 @@ class SIPadapterTest(unittest.TestCase): ...@@ -455,6 +455,108 @@ class SIPadapterTest(unittest.TestCase):
self.assertIn(str('<fileFormat>PULP</fileFormat>'), sip.get_prettyxml()) self.assertIn(str('<fileFormat>PULP</fileFormat>'), sip.get_prettyxml())
class CycleReportTest(unittest.TestCase):
def setUp(self):
# Create requirements
self.cycle = models.Cycle.objects.create(**Cycle_test_data(start=datetime.utcnow().isoformat(), stop=(datetime.utcnow() + timedelta(weeks=12)).isoformat()))
# Projects
self.project = models.Project.objects.create(**Project_test_data(name='test_for_cycle_report'))
self.project.cycles.set([self.cycle.pk])
self.project_regular = models.Project.objects.create(**Project_test_data())
self.project_regular.cycles.set([self.cycle.pk])
self.project_regular.project_category = models.ProjectCategory.objects.get(value='regular')
self.project_regular.save()
# SU, SUD and TD
self.scheduling_set = models.SchedulingSet.objects.create(**SchedulingSet_test_data(project=self.project))
self.scheduling_unit_draft = models.SchedulingUnitDraft.objects.create(
**SchedulingUnitDraft_test_data(scheduling_set=self.scheduling_set))
self.task_draft = models.TaskDraft.objects.create(
**TaskDraft_test_data(scheduling_unit_draft=self.scheduling_unit_draft))
# Create test_data_creator as superuser
self.test_data_creator = TMSSRESTTestDataCreator(BASE_URL, AUTH)
response = requests.get(self.test_data_creator.django_api_url + '/', auth=self.test_data_creator.auth)
def _create_subtask_with_type_and_set_status(self, type, status=None):
"""
Help method to create a Subtask by specifying its type and (optionally) set the its status.
"""
sub = models.SchedulingUnitBlueprint.objects.create(**SchedulingUnitBlueprint_test_data(draft=self.scheduling_unit_draft))
tb = models.TaskBlueprint.objects.create(**TaskBlueprint_test_data(task_draft=self.task_draft, scheduling_unit_blueprint=sub))
# Create Subtask
subtask_template = models.SubtaskTemplate.objects.create(**SubtaskTemplate_test_data(subtask_type_value=type))
subtask = models.Subtask.objects.create(**Subtask_test_data(subtask_template=subtask_template))
subtask.task_blueprints.set([tb])
if status:
set_subtask_state_following_allowed_transitions(subtask, status)
return subtask
def test_create_cycle_report(self):
"""
Test create_cycle_report extra action.
"""
# Create and set two Subtasks of type 'observation' and 'pipeline' with the state 'finished'.
subtask_obs = self._create_subtask_with_type_and_set_status('observation', 'finished')
subtask_pip = self._create_subtask_with_type_and_set_status('pipeline', 'finished')
# Create SubtaskOutput and Dataproducts
subtask_output_obs = models.SubtaskOutput.objects.create(**SubtaskOutput_test_data(subtask=subtask_obs))
dp_interferometric_obs = models.Dataproduct.objects.create(**Dataproduct_test_data(producer=subtask_output_obs, dataformat=models.Dataformat.objects.get(value="MeasurementSet"), datatype=models.Datatype.objects.get(value="visibilities")))
dp_beamformed_obs = models.Dataproduct.objects.create(**Dataproduct_test_data(producer=subtask_output_obs, dataformat=models.Dataformat.objects.get(value="Beamformed"), datatype=models.Datatype.objects.get(value="time series")))
subtask_output_pip = models.SubtaskOutput.objects.create(**SubtaskOutput_test_data(subtask=subtask_pip))
dp_preprocessing_pip = models.Dataproduct.objects.create(**Dataproduct_test_data(producer=subtask_output_pip, dataformat=models.Dataformat.objects.get(value="MeasurementSet"), datatype=models.Datatype.objects.get(value="visibilities")))
dp_pulsar_pip1 = models.Dataproduct.objects.create(**Dataproduct_test_data(producer=subtask_output_pip, dataformat=models.Dataformat.objects.get(value="pulp summary"), datatype=models.Datatype.objects.get(value="pulsar profile")))
dp_pulsar_pip2 = models.Dataproduct.objects.create(**Dataproduct_test_data(producer=subtask_output_pip, dataformat=models.Dataformat.objects.get(value="pulp analysis"), datatype=models.Datatype.objects.get(value="time series")))
# Create generic and 'stand-alone' reservations
reservation_no_project = models.Reservation.objects.create(**Reservation_test_data(duration=300))
reservation_mixed = models.Reservation.objects.create(**Reservation_test_data(duration=500, project=self.project)) # Non-production project
reservation_project = models.Reservation.objects.create(**Reservation_test_data(duration=600, project=self.project_regular)) # Production project
reservation_template = models.ReservationTemplate.objects.get(name="reservation")
reservation_template_spec = get_default_json_object_for_schema(reservation_template.schema)
reservation_template_spec['activity']['type'] = 'stand-alone mode'
reservation_no_project_sa_mode = models.Reservation.objects.create(start_time=datetime.now(), stop_time=datetime.now()+timedelta(seconds=1200), name="SA no project", description="SA no project", specifications_template=reservation_template, specifications_doc=reservation_template_spec)
reservation_mixed_sa_mode = models.Reservation.objects.create(start_time=datetime.now(), stop_time=datetime.now()+timedelta(seconds=350), project=self.project, name="SA mixed no project", description="SA mixed no project", specifications_template=reservation_template, specifications_doc=reservation_template_spec)
reservation_project_sa_mode = models.Reservation.objects.create(start_time=datetime.now(), stop_time=datetime.now() + timedelta(seconds=800), project=self.project_regular, name="SA project", description="SA project", specifications_template=reservation_template, specifications_doc=reservation_template_spec)
# Assertions
# Assert we get the expected object
response = requests.get(BASE_URL + '/cycle/%s/report' % self.cycle.pk, auth=self.test_data_creator.auth)
self.assertEqual(response.status_code, 200)
result = response.json()
# Assert data_ingested_per_site_and_category
data_per_site_and_cat = result['data_ingested_per_site_and_category']
self.assertEqual(data_per_site_and_cat['Interferometric Observation']['size__sum'], dp_interferometric_obs.size)
self.assertEqual(data_per_site_and_cat['Beamformed Observation']['size__sum'], dp_beamformed_obs.size)
self.assertEqual(data_per_site_and_cat['Preprocessing Pipeline']['size__sum'], dp_preprocessing_pip.size)
self.assertEqual(data_per_site_and_cat['Pulsar Pipeline']['size__sum'], dp_pulsar_pip1.size + dp_pulsar_pip2.size)
# TODO: Avoid calculations in the code.
# Assert usage_mode
total_sa_mode = reservation_no_project_sa_mode.duration + reservation_mixed_sa_mode.duration + reservation_project_sa_mode.duration
total_all_modes = reservation_no_project.duration + reservation_mixed.duration + reservation_project.duration + total_sa_mode
usage_mode = result['usage_mode']
self.assertAlmostEqual(usage_mode['all modes']['total'], total_all_modes)
self.assertAlmostEqual(usage_mode['all modes']['observing'], reservation_project.duration+reservation_project_sa_mode.duration)
self.assertAlmostEqual(usage_mode['all modes']['idle/test'], reservation_mixed.duration+reservation_mixed_sa_mode.duration)
self.assertAlmostEqual(usage_mode['stand-alone mode']['total'], total_sa_mode)
self.assertAlmostEqual(usage_mode['stand-alone mode']['no project'], reservation_no_project_sa_mode.duration)
self.assertAlmostEqual(usage_mode['stand-alone mode']['project'], reservation_project_sa_mode.duration)
self.assertAlmostEqual(usage_mode['stand-alone mode']['mixed/no project'], reservation_mixed_sa_mode.duration)
self.assertAlmostEqual(usage_mode['ILT mode']['total'], total_all_modes-total_sa_mode)
self.assertAlmostEqual(usage_mode['ILT mode']['observing'], reservation_project.duration+reservation_project_sa_mode.duration - reservation_project_sa_mode.duration)
self.assertAlmostEqual(usage_mode['ILT mode']['idle/test'], reservation_mixed.duration+reservation_mixed_sa_mode.duration - reservation_mixed_sa_mode.duration)
class ProjectReportTest(unittest.TestCase): class ProjectReportTest(unittest.TestCase):
def setUp(self): def setUp(self):
# Create requirements # Create requirements
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment