From 113b5501ada6e2df1737c6a36a9fb571172039e7 Mon Sep 17 00:00:00 2001 From: Vermaas <vermaas@astron.nl> Date: Fri, 5 Jan 2024 15:14:44 +0100 Subject: [PATCH] add unittests --- .../tests/test_ingest_fraction.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 atdb/taskdatabase/tests/test_ingest_fraction.py diff --git a/atdb/taskdatabase/tests/test_ingest_fraction.py b/atdb/taskdatabase/tests/test_ingest_fraction.py new file mode 100644 index 00000000..f56b408b --- /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) -- GitLab