From cedd1c58fbeee59f9ec5a5763c472e1a5f1a3c1a Mon Sep 17 00:00:00 2001
From: Mario Raciti <mario.raciti@inaf.it>
Date: Mon, 25 Oct 2021 12:02:04 +0200
Subject: [PATCH] TMSS-1123: Update allowed state transition from
 'unschedulable' to 'cancelling'; add tests

---
 SAS/TMSS/backend/src/tmss/tmssapp/populate.py |  4 ++--
 SAS/TMSS/backend/test/t_subtasks.py           |  3 +++
 SAS/TMSS/backend/test/t_tasks.py              | 22 +++++++++++++++++--
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
index 7bfb6223571..9f9c8a64b9f 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
@@ -189,14 +189,14 @@ def populate_subtask_allowed_state_transitions(apps, schema_editor):
 def populate_subtask_allowed_state_transitions_extra(apps, schema_editor):
     '''populate the SubtaskAllowedStateTransitions table with additional allowed state transitions'''
     DEFINED = SubtaskState.objects.get(value=SubtaskState.Choices.DEFINED.value)
-    CANCELLED = SubtaskState.objects.get(value=SubtaskState.Choices.CANCELLED.value)
+    CANCELLING = SubtaskState.objects.get(value=SubtaskState.Choices.CANCELLING.value)
     ERROR = SubtaskState.objects.get(value=SubtaskState.Choices.ERROR.value)
     UNSCHEDULABLE = SubtaskState.objects.get(value=SubtaskState.Choices.UNSCHEDULABLE.value)
 
     SubtaskAllowedStateTransitions.objects.bulk_create([
         SubtaskAllowedStateTransitions(old_state=DEFINED, new_state=UNSCHEDULABLE),
         SubtaskAllowedStateTransitions(old_state=UNSCHEDULABLE, new_state=DEFINED),
-        SubtaskAllowedStateTransitions(old_state=UNSCHEDULABLE, new_state=CANCELLED),
+        SubtaskAllowedStateTransitions(old_state=UNSCHEDULABLE, new_state=CANCELLING),
         SubtaskAllowedStateTransitions(old_state=UNSCHEDULABLE, new_state=ERROR)
         ])
 
diff --git a/SAS/TMSS/backend/test/t_subtasks.py b/SAS/TMSS/backend/test/t_subtasks.py
index 53d98a77b91..04432b0f5c9 100755
--- a/SAS/TMSS/backend/test/t_subtasks.py
+++ b/SAS/TMSS/backend/test/t_subtasks.py
@@ -722,6 +722,7 @@ class SubtaskAllowedStateTransitionsTest(unittest.TestCase):
         for state_value in (SubtaskState.Choices.DEFINING.value,
                             SubtaskState.Choices.DEFINED.value,
                             SubtaskState.Choices.SCHEDULING.value,
+                            SubtaskState.Choices.UNSCHEDULABLE.value,
                             SubtaskState.Choices.SCHEDULED.value,
                             SubtaskState.Choices.QUEUEING.value,
                             SubtaskState.Choices.QUEUED.value,
@@ -740,6 +741,7 @@ class SubtaskAllowedStateTransitionsTest(unittest.TestCase):
         for intermediate_state_value in (SubtaskState.Choices.DEFINING.value,
                                          SubtaskState.Choices.SCHEDULING.value,
                                          SubtaskState.Choices.UNSCHEDULING.value,
+                                         SubtaskState.Choices.UNSCHEDULABLE.value,
                                          SubtaskState.Choices.QUEUEING.value,
                                          SubtaskState.Choices.STARTING.value,
                                          SubtaskState.Choices.STARTED.value,
@@ -769,6 +771,7 @@ class SubtaskAllowedStateTransitionsTest(unittest.TestCase):
     def test_helper_method_set_subtask_state_following_allowed_transitions_cancel_path(self):
         for desired_end_state_value in (SubtaskState.Choices.CANCELLING.value,SubtaskState.Choices.CANCELLED.value):
             for state_value in (SubtaskState.Choices.DEFINED.value,
+                                SubtaskState.Choices.UNSCHEDULABLE.value,
                                 SubtaskState.Choices.SCHEDULED.value,
                                 SubtaskState.Choices.QUEUED.value,
                                 SubtaskState.Choices.STARTED.value):
diff --git a/SAS/TMSS/backend/test/t_tasks.py b/SAS/TMSS/backend/test/t_tasks.py
index 63ab80d6203..1a127c3da5b 100755
--- a/SAS/TMSS/backend/test/t_tasks.py
+++ b/SAS/TMSS/backend/test/t_tasks.py
@@ -305,12 +305,23 @@ class TaskBlueprintStateTest(unittest.TestCase):
             ("finished",    "finished")
         ], [
             ("defining",    "defined"),
-            ("error",  "error")
+            ("error",       "error")
+        ], [
+            ("defining",    "defined"),
+            ("defined",     "schedulable"),
+            ("unschedulable","unschedulable"),
+            ("error",       "error")
         ], [
             ("defining",    "defined"),
             ("defined",     "schedulable"),
             ("cancelling",  "cancelled"),
             ("cancelled",   "cancelled")
+        ], [
+            ("defining",    "defined"),
+            ("defined",     "schedulable"),
+            ("unschedulable","unschedulable"),
+            ("cancelling",  "cancelled"),
+            ("cancelled",   "cancelled")
         ]]
 
         for test_table in test_tables:
@@ -356,7 +367,14 @@ class TaskBlueprintStateTest(unittest.TestCase):
         ], [
             ("cancelling",  "defined",    "cancelled"),
             ("cancelled",   "defined",    "cancelled")
-        ] , [
+        ], [
+            ("unschedulable", "defined",  "unschedulable"),
+            ("cancelling",    "defined",  "cancelled"),
+            ("cancelled",     "defined",  "cancelled"),
+        ], [
+            ("error",       "defined",    "error")
+        ], [
+            ("unschedulable","defined",   "unschedulable"),
             ("error",       "defined",    "error")
         ], [
             # qa finishing/finished should be not observed
-- 
GitLab