diff --git a/atdb/taskdatabase/services/common.py b/atdb/taskdatabase/services/common.py index e3fb9ecd4b9cbfeed41626ef67d6f02c7a4b88a2..ad0013e86da96b4384b8bd392fdafad136f76e93 100644 --- a/atdb/taskdatabase/services/common.py +++ b/atdb/taskdatabase/services/common.py @@ -16,6 +16,7 @@ class State(Enum): AGGREGATE = "aggregate" AGGREGATING = "aggregating" AGGREGATED = "aggregated" + STORING = 'storing' STORED = 'stored' VALIDATED = "validated" SCRUBBED = "scrubbed" @@ -34,7 +35,7 @@ class State(Enum): VERIFIED_STATUSSES = [State.STORED.value, State.VALIDATED.value, State.SCRUBBED.value, State.PRE_ARCHIVED.value, State.ARCHIVED.value, State.FINISHED.value, State.SUSPENDED.value, State.DISCARDED.value] -PROCESSED_STATUSSES = [State.PROCESSED.value, State.AGGREGATE.value, State.AGGREGATING.value, State.AGGREGATED.value, State.STORED.value, +PROCESSED_STATUSSES = [State.PROCESSED.value, State.AGGREGATE.value, State.AGGREGATING.value, State.AGGREGATED.value, State.STORED.value, State.STORING.value, State.DISCARDED.value] INGEST_FRACTION_STATUSSES = [State.SCRUBBED.value, State.PRE_ARCHIVING.value, State.PRE_ARCHIVED.value, diff --git a/atdb/taskdatabase/tests/test_views.py b/atdb/taskdatabase/tests/test_views.py new file mode 100644 index 0000000000000000000000000000000000000000..a44a776bff3080bff519ba87baa170fecee94e3f --- /dev/null +++ b/atdb/taskdatabase/tests/test_views.py @@ -0,0 +1,36 @@ +from django.test import TestCase, RequestFactory +from django.urls import reverse +from django.http import HttpResponse +from django.shortcuts import redirect + +from taskdatabase.models import Task, Workflow +from taskdatabase.views import SortTasks + +class TestViews(TestCase): + def setUp(self): + self.factory = RequestFactory() + + # Create a test workflow + workflow_requantisation = Workflow(workflow_uri="psrfits_requantisation") + workflow_requantisation.save() + + # Create a test task + self.task1 = Task.objects.create(filter='a',sas_id=456, status='stored', workflow=workflow_requantisation, priority=1) + self.task2 = Task.objects.create(filter='b',sas_id=123, status='stored', workflow=workflow_requantisation, priority=1) + + # def test_sort(self): + # # Set up the URL for the view + # #url = reverse('sort-tasks', kwargs={'sort': 'sas_id', 'redirect_to_page': 'atdb'}) + # + # # Create a request object + # request = self.factory.get('/dummy-url') + # + # # Call the function with sort='priority' and redirect_to_page='tasks_list' + # response = SortTasks(request, sort='sas_id', redirect_to_page='atdb') + # + # # Check if the sort field is correctly stored in the session + # self.assertEqual(request.session['sort'], 'name') + # + # # Check if it redirects to the 'index' page + # self.assertEqual(response.status_code, 302) + # self.assertEqual(response.url, reverse('atdb')) \ No newline at end of file diff --git a/atdb/taskdatabase/tests/test_views_get_summary.py b/atdb/taskdatabase/tests/test_views_get_summary.py index c12779f29d1d225092d543b4c104f4adfcb2a011..60f5c5b8398e717289d33778d0aa73aaf1070e72 100644 --- a/atdb/taskdatabase/tests/test_views_get_summary.py +++ b/atdb/taskdatabase/tests/test_views_get_summary.py @@ -2,7 +2,7 @@ from django.test import TestCase from django.urls import reverse from django.http import JsonResponse, HttpResponse -from taskdatabase.models import Task, Workflow +from taskdatabase.models import Task, Workflow, Activity import taskdatabase.tests.test_calculated_qualities_outputs as outputs import json @@ -12,8 +12,11 @@ class TestGetSummary(TestCase): workflow_requantisation = Workflow(workflow_uri="psrfits_requantisation") workflow_requantisation.save() + activity_54321 = Activity(sas_id=54321, calculated_quality="good") + activity_54321.save() + # rfi_percent=0 - Task.objects.get_or_create(sas_id=54321, status='stored', + Task.objects.get_or_create(sas_id=54321, status='stored', activity = activity_54321, outputs=outputs.default_summary_flavour_with_rfi_percent_zero_1, workflow=workflow_requantisation, calculated_qualities = {"per_task": "good", "per_sasid": "good"}, @@ -33,10 +36,15 @@ class TestGetSummary(TestCase): workflow=workflow_requantisation, calculated_qualities = {"per_task": "good", "per_sasid": "good"}) + # test image compression, rfi_percentage=1.7186448587105623 workflow_imaging_compression = Workflow(workflow_uri="imaging_compress_pipeline_v011") workflow_imaging_compression.save() - Task.objects.get_or_create(sas_id=55555, status='stored', + + activity_55555 = Activity(sas_id=55555, calculated_quality="good") + activity_55555.save() + + Task.objects.get_or_create(sas_id=55555, status='stored', activity = activity_55555, outputs=outputs.imaging_compression_summary_flavor_with_rfi_1, workflow=workflow_imaging_compression, calculated_qualities={"per_task": "good", "per_sasid": "good"}, @@ -152,7 +160,7 @@ class TestGetSummary(TestCase): def test_summary_pdf_response(self): # Mock request - response = self.client.get(reverse('get-summary', args=['your_sas_id', 'pdf'])) + response = self.client.get(reverse('get-summary', args=['54321', 'pdf'])) # Check if response is HttpResponse self.assertIsInstance(response, HttpResponse) @@ -191,3 +199,4 @@ class TestGetSummary(TestCase): # Assert # test a little bit of the html content self.assertEqual(expected_title in html_data, True) +