From 493e9eb4e04e2aa22ea644e721e031040e3d5aad Mon Sep 17 00:00:00 2001
From: Vermaas <vermaas@astron.nl>
Date: Thu, 29 Aug 2024 14:01:49 +0200
Subject: [PATCH] hotfix

---
 atdb/taskdatabase/services/common.py          |  3 +-
 atdb/taskdatabase/tests/test_views.py         | 36 +++++++++++++++++++
 .../tests/test_views_get_summary.py           | 17 ++++++---
 3 files changed, 51 insertions(+), 5 deletions(-)
 create mode 100644 atdb/taskdatabase/tests/test_views.py

diff --git a/atdb/taskdatabase/services/common.py b/atdb/taskdatabase/services/common.py
index e3fb9ecd..ad0013e8 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 00000000..a44a776b
--- /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 c12779f2..60f5c5b8 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)
+
-- 
GitLab