From 0384de4b6321c7fbabccf4ce6ff9331d5ab3e9dc Mon Sep 17 00:00:00 2001
From: Vermaas <vermaas@astron.nl>
Date: Thu, 22 Feb 2024 14:12:53 +0100
Subject: [PATCH] check for STORED instead of PROCESSED added unit tests

---
 atdb/taskdatabase/models.py                   |  2 +-
 .../templates/taskdatabase/index.html         |  2 +-
 .../tests/test_activities_associate.py        |  0
 atdb/taskdatabase/tests/test_summary_tasks.py | 42 +++++++++++++++++++
 4 files changed, 44 insertions(+), 2 deletions(-)
 delete mode 100644 atdb/taskdatabase/tests/test_activities_associate.py
 create mode 100644 atdb/taskdatabase/tests/test_summary_tasks.py

diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py
index d7dbbe95..14d24b81 100644
--- a/atdb/taskdatabase/models.py
+++ b/atdb/taskdatabase/models.py
@@ -217,7 +217,7 @@ class Task(models.Model):
             self.calculated_qualities = qualities.calculate_qualities(self, tasks_for_this_sasid, quality_thresholds)
 
         # nv:20feb2024, check if this task is a summary task
-        if (self.status != State.PROCESSED.value) & (self.new_status == State.PROCESSED.value):
+        if (self.status != State.STORED.value) & (self.new_status == State.STORED.value):
             self.is_summary = check_if_summary(self)
 
         # nv:20feb2024, same as above, but for backward compatibilty reasons.
diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html
index fc4fe7f3..35a46bfd 100644
--- a/atdb/taskdatabase/templates/taskdatabase/index.html
+++ b/atdb/taskdatabase/templates/taskdatabase/index.html
@@ -31,7 +31,7 @@
             {% include 'taskdatabase/pagination.html' %}
         </div>
     </div>
-    <p class="footer"> Version 20 Feb 2024
+    <p class="footer"> Version 22 Feb 2024
 </div>
 
 {% include 'taskdatabase/refresh.html' %}
diff --git a/atdb/taskdatabase/tests/test_activities_associate.py b/atdb/taskdatabase/tests/test_activities_associate.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/atdb/taskdatabase/tests/test_summary_tasks.py b/atdb/taskdatabase/tests/test_summary_tasks.py
new file mode 100644
index 00000000..bf33c9f7
--- /dev/null
+++ b/atdb/taskdatabase/tests/test_summary_tasks.py
@@ -0,0 +1,42 @@
+from django.test import TestCase
+import json
+from taskdatabase.models import Task, Workflow, Activity
+from taskdatabase.services.common import State
+class TestSummaryTasks(TestCase):
+    def setUp(self):
+        """
+        initialize test data
+        """
+        self.workflow_requantisation = Workflow(id=22, workflow_uri="psrfits_requantisation")
+        self.workflow_requantisation.save()
+
+        self.no_summary_task = Task.objects.create(sas_id=77777, new_status=State.DEFINED.value, workflow=self.workflow_requantisation,
+                                         outputs={"tar_archive": [{"size": 4885985280, "basename": "L621240_SAP002_B073_P000_bf.tar", "nameroot": "L621240_SAP002_B073_P000_bf"}]})
+        self.summary_task_defined = Task.objects.create(sas_id=77777, new_status=State.DEFINED.value, workflow=self.workflow_requantisation,
+                                         outputs={"tar_archive": [{"size": 4885985280, "basename": "L185619_summaryCS.tar", "nameroot": "L185619_summaryCS"}]})
+        self.summary_task_stored = Task.objects.create(sas_id=77777, new_status=State.STORED.value, workflow=self.workflow_requantisation,
+                                         outputs={"tar_archive": [{"size": 4885985280, "basename": "L185619_summaryCS.tar", "nameroot": "L185619_summaryCS"}]})
+
+    def test_no_summary_task(self):
+        """
+        test task that is not a summary task
+        """
+
+        actual = self.no_summary_task.is_summary
+        self.assertEqual(actual, False)
+
+    def test_summary_task_defined(self):
+        """
+        test summary task, but before it knows that it becomes a summary task (which it only knows when 'processed')
+        """
+
+        actual = self.summary_task_defined.is_summary
+        self.assertEqual(actual, False)
+
+    def test_summary_task_stored(self):
+        """
+        test summary task, at 'stored' it should know that it is a summary task and return True)
+        """
+        self.summary_task_stored.save()
+        actual = self.summary_task_stored.is_summary
+        self.assertEqual(actual, True)
-- 
GitLab