diff --git a/atdb/taskdatabase/tests/test_ingest_fraction.py b/atdb/taskdatabase/tests/test_ingest_fraction.py new file mode 100644 index 0000000000000000000000000000000000000000..f56b408b19ebe046a4bef4cab3f2b41b045442e9 --- /dev/null +++ b/atdb/taskdatabase/tests/test_ingest_fraction.py @@ -0,0 +1,30 @@ +from django.test import TestCase + +from taskdatabase.models import Task, Workflow + +class TestIngestFraction(TestCase): + + def setUp(self): + # create a list of Tasks with various values of rfi_percent to test the quality algorithms + workflow_requantisation = Workflow(workflow_uri="psrfits_requantisation") + workflow_requantisation.save() + + Task.objects.get_or_create(filter='a',sas_id=54321, status='stored', workflow=workflow_requantisation) + Task.objects.get_or_create(filter='a',sas_id=54321, status='scrubbed', workflow=workflow_requantisation) + Task.objects.get_or_create(filter='b',sas_id=54321, status='scrubbed', workflow=workflow_requantisation) + Task.objects.get_or_create(filter='a',sas_id=54321, status='archiving', workflow=workflow_requantisation) + Task.objects.get_or_create(filter='a',sas_id=54321, status='archived', workflow=workflow_requantisation) + Task.objects.get_or_create(filter='a',sas_id=54321, status='finished', workflow=workflow_requantisation) + Task.objects.get_or_create(filter='b',sas_id=54321, status='finished', workflow=workflow_requantisation) + + def test_ingest_fraction(self): + + # collapse all tasks into a single task for this sas_id + task = Task.objects.filter(sas_id=54321).distinct('sas_id')[0] + + # get the list of statusses and level of completion + statusses = task.sasid_ingested_fraction['status'] + completion = task.sasid_ingested_fraction['completion'] + + self.assertEqual(statusses, {'scrubbed': 2, 'archiving': 1, 'archived': 1, 'finished': 2}) + self.assertEqual(completion,50)