From 850aa9e067c257b1302a5bad9eb275afc7d343f3 Mon Sep 17 00:00:00 2001
From: jkuensem <jkuensem@physik.uni-bielefeld.de>
Date: Tue, 9 Jun 2020 19:21:01 +0200
Subject: [PATCH] TMSS-200: Remove SubtaskInputSelectionTemplate since and use
 TaskRelationSelectionTemplate instead. Fix test.

---
 .../src/tmss/tmssapp/models/scheduling.py     | 10 +---
 SAS/TMSS/src/tmss/tmssapp/populate.py         | 59 ++++++++-----------
 .../tmss/tmssapp/serializers/scheduling.py    |  6 --
 SAS/TMSS/src/tmss/tmssapp/subtasks.py         |  8 +--
 .../src/tmss/tmssapp/viewsets/scheduling.py   |  6 --
 SAS/TMSS/src/tmss/urls.py                     |  1 -
 .../test/t_tmssapp_scheduling_REST_API.py     | 33 +++++------
 .../test/t_tmssapp_scheduling_django_API.py   |  4 --
 .../test/t_tmssapp_specification_REST_API.py  |  2 +-
 SAS/TMSS/test/tmss_test_data_django_models.py | 13 +---
 SAS/TMSS/test/tmss_test_data_rest.py          | 21 ++-----
 11 files changed, 52 insertions(+), 111 deletions(-)

diff --git a/SAS/TMSS/src/tmss/tmssapp/models/scheduling.py b/SAS/TMSS/src/tmss/tmssapp/models/scheduling.py
index f67a46eef6c..e36eef6bcb5 100644
--- a/SAS/TMSS/src/tmss/tmssapp/models/scheduling.py
+++ b/SAS/TMSS/src/tmss/tmssapp/models/scheduling.py
@@ -126,14 +126,6 @@ class DefaultDataproductSpecificationsTemplate(BasicCommon):
     template = ForeignKey('DataproductSpecificationsTemplate', on_delete=PROTECT)
 
 
-class SubtaskInputSelectionTemplate(Template):
-    class Meta:
-        # TODO: move up to the abstract base class and replace with django 3.0 UniqueConstraint(... name='%*class)s_unique_name_version)
-        constraints = [UniqueConstraint(fields=['name', 'version'], name='SubtaskInputSelectionTemplate_unique_name_version')]
-
-# todo: so we need to specify a default?
-
-
 class DataproductFeedbackTemplate(Template):
     class Meta:
         # TODO: move up to the abstract base class and replace with django 3.0 UniqueConstraint(... name='%*class)s_unique_name_version)
@@ -258,7 +250,7 @@ class SubtaskInput(BasicCommon):
     producer = ForeignKey('SubtaskOutput', on_delete=PROTECT, related_name='consumers', help_text='The SubtaskOutput producing the input dataproducts for this SubtaskInput.')
     dataproducts = ManyToManyField('Dataproduct', help_text='The Dataproducts resulting from application of the filter at time of scheduling Although the dataproducts are simply the result of applying the filter on immutable data, the filter application could change over time. We thus store the result of this filtering directly to retain which input was specified for the task..')
     selection_doc = JSONField(help_text='Filter to apply to the dataproducts of the producer, to derive input dataproducts when scheduling.')
-    selection_template = ForeignKey('SubtaskInputSelectionTemplate', on_delete=PROTECT, help_text='Schema used for selection_doc.')
+    selection_template = ForeignKey('TaskRelationSelectionTemplate', on_delete=PROTECT, help_text='Schema used for selection_doc.')
 
     def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
         if self.selection_doc and self.selection_template_id and self.selection_template.schema:
diff --git a/SAS/TMSS/src/tmss/tmssapp/populate.py b/SAS/TMSS/src/tmss/tmssapp/populate.py
index a31d8cfa517..fffc75596da 100644
--- a/SAS/TMSS/src/tmss/tmssapp/populate.py
+++ b/SAS/TMSS/src/tmss/tmssapp/populate.py
@@ -37,7 +37,6 @@ def populate_choices(apps, schema_editor):
 
 
 def populate_lofar_json_schemas(apps, schema_editor):
-    _populate_subtask_input_selection_templates()
     _populate_dataproduct_specifications_templates()
     _populate_taskrelation_selection_templates()
     _populate_dataproduct_feedback_templates()
@@ -866,40 +865,9 @@ def _populate_stations_schema():
     TaskTemplate.objects.create(**task_template_data)
 
 
-def _populate_subtask_input_selection_templates():
-    selection_template_data = { "name": "All",
-                           "description": 'Select all, apply no filtering.',
-                           "version": '1',
-                           "schema": json.loads('''{
-                           "$id": "http://example.com/example.json",
-                           "type": "object",
-                           "$schema": "http://json-schema.org/draft-06/schema#",
-                           "definitions": {},
-                           "additionalProperties": false,
-                           "properties": {} }'''),
-                           "tags": []}
-
-    SubtaskInputSelectionTemplate.objects.create(**selection_template_data)
-
-
-def _populate_subtask_input_selection_templates():
-    selection_template_data = { "name": "All",
-                           "description": 'Select all, apply no filtering.',
-                           "version": '1',
-                           "schema": json.loads('''{
-                           "$id": "http://example.com/example.json",
-                           "type": "object",
-                           "$schema": "http://json-schema.org/draft-06/schema#",
-                           "definitions": {},
-                           "additionalProperties": false,
-                           "properties": {} }'''),
-                           "tags": []}
-
-    SubtaskInputSelectionTemplate.objects.create(**selection_template_data)
-
-
-
 def _populate_taskrelation_selection_templates():
+
+    # All
     data = { "name": "All",
              "description": 'Select all, apply no filtering.',
              "version": '1',
@@ -911,7 +879,30 @@ def _populate_taskrelation_selection_templates():
                                         "additionalProperties": false,
                                         "properties": {} }'''),
              "tags": []}
+    TaskRelationSelectionTemplate.objects.create(**data)
 
+    # SAP
+    data = {"name": "SAP",
+                               "description": 'Select by SAP.',
+                               "version": '1',
+                               "schema": json.loads('''{
+                                      "$id": "http://example.com/example.json",
+                                      "$schema": "http://json-schema.org/draft-06/schema#",
+                                      "additionalProperties": false,
+                                      "definitions": {},
+                                      "properties": {
+                                          "SAP": {
+                                                               "type": "integer",
+                                                               "title": "SAP",
+                                                               "default": 0,
+                                                               "minimum": 0,
+                                                               "maximum": 1,
+                                                               "description": "Sub-array pointing selector"
+                                             }
+                                          },
+                                      "type": "object"
+                                      }'''),
+                               "tags": []}
     TaskRelationSelectionTemplate.objects.create(**data)
 
 
diff --git a/SAS/TMSS/src/tmss/tmssapp/serializers/scheduling.py b/SAS/TMSS/src/tmss/tmssapp/serializers/scheduling.py
index 2fa91a1cd00..2494cb6ecf1 100644
--- a/SAS/TMSS/src/tmss/tmssapp/serializers/scheduling.py
+++ b/SAS/TMSS/src/tmss/tmssapp/serializers/scheduling.py
@@ -70,12 +70,6 @@ class DefaultDataproductSpecificationsTemplateSerializer(serializers.Hyperlinked
         fields = '__all__'
 
 
-class SubtaskInputSelectionTemplateSerializer(serializers.HyperlinkedModelSerializer):
-    class Meta:
-        model = models.SubtaskInputSelectionTemplate
-        fields = '__all__'
-
-
 class DataproductFeedbackTemplateSerializer(serializers.HyperlinkedModelSerializer):
     class Meta:
         model = models.DataproductFeedbackTemplate
diff --git a/SAS/TMSS/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/src/tmss/tmssapp/subtasks.py
index f16bf12ca81..311f403f6e2 100644
--- a/SAS/TMSS/src/tmss/tmssapp/subtasks.py
+++ b/SAS/TMSS/src/tmss/tmssapp/subtasks.py
@@ -150,7 +150,7 @@ def create_qafile_subtask_from_observation_subtask(observation_subtask: Subtask)
     qafile_subtask_input = SubtaskInput.objects.create(subtask=qafile_subtask,
                                                        producer=observation_subtask.outputs.first(), # TODO: determine proper producer based on spec in task_relation_blueprint
                                                        selection_doc="{}",
-                                                       selection_template=SubtaskInputSelectionTemplate.objects.get(name="All"))
+                                                       selection_template=TaskRelationSelectionTemplate.objects.get(name="All"))
     qafile_subtask_output = SubtaskOutput.objects.create(subtask=qafile_subtask)
 
     # step 3: set state to DEFINED
@@ -212,7 +212,7 @@ def create_qaplots_subtask_from_qafile_subtask(qafile_subtask: Subtask) -> Subta
     qaplots_subtask_input = SubtaskInput.objects.create(subtask=qaplots_subtask,
                                                         producer=qafile_subtask.outputs.first(),
                                                         selection_doc="{}",
-                                                        selection_template=SubtaskInputSelectionTemplate.objects.get(name="All"))
+                                                        selection_template=TaskRelationSelectionTemplate.objects.get(name="All"))
     qaplots_subtask_output = SubtaskOutput.objects.create(subtask=qaplots_subtask)
 
     # step 3: set state to DEFINED
@@ -256,7 +256,7 @@ def create_preprocessing_subtask_from_task_blueprint(task_blueprint: TaskBluepri
     subtask_input = SubtaskInput.objects.create(subtask=subtask,
                                                 producer=observation_predecessor_subtask.outputs.first(),
                                                 selection_doc="{}",
-                                                selection_template=SubtaskInputSelectionTemplate.objects.get(name="All"))
+                                                selection_template=TaskRelationSelectionTemplate.objects.get(name="All"))
     subtask_output = SubtaskOutput.objects.create(subtask=subtask)
 
     # step 3: set state to DEFINED
@@ -481,7 +481,7 @@ def schedule_pipeline_subtask(pipeline_subtask: Subtask):
     # for now, use all output dataproducts of the already linked inputs
     # TODO: make proper dataproduct input selection
     # TODO: use existing and reasonable selection and specification templates when we have those, for now, use "All" and "Empty"
-    subtask_input_selection_template = SubtaskInputSelectionTemplate.objects.get(name="All")
+    selection_template = TaskRelationSelectionTemplate.objects.get(name="All")
     dataproduct_specifications_template = DataproductSpecificationsTemplate.objects.get(name="Empty")
     dataproduct_feedback_template = DataproductFeedbackTemplate.objects.get(name="Empty")
 
diff --git a/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py b/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py
index 7955e7211e1..9d5cdd57e0f 100644
--- a/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py
+++ b/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py
@@ -138,12 +138,6 @@ class DefaultDataproductSpecificationsTemplateViewSet(LOFARViewSet):
     queryset = models.DefaultDataproductSpecificationsTemplate.objects.all()
     serializer_class = serializers.DefaultDataproductSpecificationsTemplateSerializer
 
-
-class SubtaskInputSelectionTemplateViewSet(LOFARViewSet):
-    queryset = models.SubtaskInputSelectionTemplate.objects.all()
-    serializer_class = serializers.SubtaskInputSelectionTemplateSerializer
-
-
 class DataproductFeedbackTemplateViewSet(LOFARViewSet):
     queryset = models.DataproductFeedbackTemplate.objects.all()
     serializer_class = serializers.DataproductFeedbackTemplateSerializer
diff --git a/SAS/TMSS/src/tmss/urls.py b/SAS/TMSS/src/tmss/urls.py
index 364d521a0b1..e6c2a1d6c0c 100644
--- a/SAS/TMSS/src/tmss/urls.py
+++ b/SAS/TMSS/src/tmss/urls.py
@@ -124,7 +124,6 @@ router.register(r'subtask_template', viewsets.SubtaskTemplateViewSet)
 router.register(r'dataproduct_specifications_template', viewsets.DataproductSpecificationsTemplateViewSet)
 router.register(r'default_subtask_template', viewsets.DefaultSubtaskTemplateViewSet)
 router.register(r'default_dataproduct_specifications_template', viewsets.DefaultDataproductSpecificationsTemplateViewSet)
-router.register(r'subtask_input_selection_template', viewsets.SubtaskInputSelectionTemplateViewSet)
 router.register(r'dataproduct_feedback_template', viewsets.DataproductFeedbackTemplateViewSet)
 
 # instances
diff --git a/SAS/TMSS/test/t_tmssapp_scheduling_REST_API.py b/SAS/TMSS/test/t_tmssapp_scheduling_REST_API.py
index 611b2ea8abc..44b17ea4944 100755
--- a/SAS/TMSS/test/t_tmssapp_scheduling_REST_API.py
+++ b/SAS/TMSS/test/t_tmssapp_scheduling_REST_API.py
@@ -242,11 +242,6 @@ class DataproductFeedbackTemplateTestCase(unittest.TestCase):
     pass
 
 
-class SubtaskInputSelectionTemplateTestCase(unittest.TestCase):
-    # This currently adds nothing on top of the template base class, so nothing new to test here.
-    pass
-
-
 class DefaultSubtaskTemplatesTestCase(unittest.TestCase):
     def test_default_subtask_template_POST(self):
         template_url = test_data_creator.post_data_and_get_url(test_data_creator.SubtaskTemplate(), '/subtask_template/')
@@ -616,7 +611,7 @@ class SubtaskInputTestCase(unittest.TestCase):
         cls.dataproduct_urls = [test_data_creator.post_data_and_get_url(test_data_creator.Dataproduct(), '/dataproduct/'), test_data_creator.post_data_and_get_url(test_data_creator.Dataproduct(), '/dataproduct/')]
         cls.subtask_output_data = test_data_creator.SubtaskOutput()
         cls.subtask_output_url = test_data_creator.post_data_and_get_url(cls.subtask_output_data, '/subtask_output/')
-        cls.subtask_input_selection_template_url = test_data_creator.post_data_and_get_url(test_data_creator.SubtaskInputSelectionTemplate(), '/subtask_input_selection_template/')
+        cls.task_relation_selection_template_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskRelationSelectionTemplate(), '/task_relation_selection_template/')
 
     def test_subtask_input_list_apiformat(self):
         r = requests.get(BASE_URL + '/subtask_input/?format=api', auth=AUTH)
@@ -627,7 +622,7 @@ class SubtaskInputTestCase(unittest.TestCase):
         GET_and_assert_equal_expected_code(self, BASE_URL + '/subtask_input/1234321/', 404)
 
     def test_subtask_input_POST_and_GET(self):
-        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url)
+        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, task_relation_selection_template_url=self.task_relation_selection_template_url)
 
         # POST and GET a new item and assert correctness
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)
@@ -635,12 +630,12 @@ class SubtaskInputTestCase(unittest.TestCase):
         GET_OK_and_assert_equal_expected_response(self, url, sti_test_data)
 
     def test_subtask_input_PUT_invalid_raises_error(self):
-        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url)
+        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, task_relation_selection_template_url=self.task_relation_selection_template_url)
 
         PUT_and_assert_expected_response(self, BASE_URL + '/subtask_input/9876789876/', sti_test_data, 404, {})
 
     def test_subtask_input_PUT(self):
-        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url)
+        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, task_relation_selection_template_url=self.task_relation_selection_template_url)
 
         # POST new item, verify
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)
@@ -648,12 +643,12 @@ class SubtaskInputTestCase(unittest.TestCase):
         GET_OK_and_assert_equal_expected_response(self, url, sti_test_data)
 
         # PUT new values, verify
-        sti_test_data2 = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url)
+        sti_test_data2 = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, task_relation_selection_template_url=self.task_relation_selection_template_url)
         PUT_and_assert_expected_response(self, url, sti_test_data2, 200, sti_test_data2)
         GET_OK_and_assert_equal_expected_response(self, url, sti_test_data2)
 
     def test_subtask_input_PATCH(self):
-        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url)
+        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, task_relation_selection_template_url=self.task_relation_selection_template_url)
 
         # POST new item, verify
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)
@@ -676,7 +671,7 @@ class SubtaskInputTestCase(unittest.TestCase):
         GET_OK_and_assert_equal_expected_response(self, url, expected_data)
 
     def test_subtask_input_DELETE(self):
-        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url)
+        sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, task_relation_selection_template_url=self.task_relation_selection_template_url)
 
         # POST new item, verify
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)
@@ -692,7 +687,7 @@ class SubtaskInputTestCase(unittest.TestCase):
                                                                                         task_blueprint_url=self.subtask_data['task_blueprint'],
                                                                                         specifications_template_url=self.subtask_data['specifications_template'],
                                                                                         specifications_doc=self.subtask_data['specifications_doc']), '/subtask/')
-        sti_test_data = test_data_creator.SubtaskInput(subtask_url=subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url)
+        sti_test_data = test_data_creator.SubtaskInput(subtask_url=subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, task_relation_selection_template_url=self.task_relation_selection_template_url)
 
         # POST new item, verify
         url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)['url']
@@ -709,7 +704,7 @@ class SubtaskInputTestCase(unittest.TestCase):
         task_relation_blueprint_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskRelationBlueprint(draft_url=self.task_relation_blueprint_data['draft'], template_url=self.task_relation_blueprint_data['selection_template'],
                                                                                                                       input_url=self.task_relation_blueprint_data['input'], output_url=self.task_relation_blueprint_data['output'],
                                                                                                                       consumer_url=self.task_relation_blueprint_data['consumer'], producer_url=self.task_relation_blueprint_data['producer']), '/task_relation_blueprint/')
-        sti_test_data = test_data_creator.SubtaskInput(task_relation_blueprint_url=task_relation_blueprint_url, subtask_url=self.subtask_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url)
+        sti_test_data = test_data_creator.SubtaskInput(task_relation_blueprint_url=task_relation_blueprint_url, subtask_url=self.subtask_url, dataproduct_urls=self.dataproduct_urls, subtask_output_url=self.subtask_output_url, task_relation_selection_template_url=self.task_relation_selection_template_url)
 
         # POST new item, verify
         url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)['url']
@@ -726,7 +721,7 @@ class SubtaskInputTestCase(unittest.TestCase):
     def test_subtask_input_PROTECT_behavior_on_producer_deleted(self):
         # make new subtask_output_url instance, but reuse related data for speed
         subtask_output_url = test_data_creator.post_data_and_get_url(test_data_creator.SubtaskOutput(subtask_url=self.subtask_output_data['subtask']), '/subtask_output/')
-        sti_test_data = test_data_creator.SubtaskInput(subtask_output_url=subtask_output_url, subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_input_selection_template_url=self.subtask_input_selection_template_url)
+        sti_test_data = test_data_creator.SubtaskInput(subtask_output_url=subtask_output_url, subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, task_relation_selection_template_url=self.task_relation_selection_template_url)
 
         # POST with dependency
         url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)['url']
@@ -740,8 +735,8 @@ class SubtaskInputTestCase(unittest.TestCase):
         GET_and_assert_equal_expected_code(self, subtask_output_url, 200)
 
     def test_subtask_input_PROTECT_behavior_on_selection_template_deleted(self):
-        subtask_input_selection_template_url = test_data_creator.post_data_and_get_url(test_data_creator.SubtaskInputSelectionTemplate(), '/subtask_input_selection_template/')
-        sti_test_data = test_data_creator.SubtaskInput(subtask_input_selection_template_url=subtask_input_selection_template_url,
+        task_relation_selection_template_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskRelationSelectionTemplate(), '/task_relation_selection_template/')
+        sti_test_data = test_data_creator.SubtaskInput(task_relation_selection_template_url=task_relation_selection_template_url,
                                                        subtask_url=self.subtask_url,
                                                        task_relation_blueprint_url=self.task_relation_blueprint_url,
                                                        dataproduct_urls=self.dataproduct_urls,
@@ -753,10 +748,10 @@ class SubtaskInputTestCase(unittest.TestCase):
 
         # Try to DELETE dependency, verify that was not successful
         # Unfortunately we don't get a nice error in json, but a Django debug page on error 500...
-        response = requests.delete(subtask_input_selection_template_url, auth=AUTH)
+        response = requests.delete(task_relation_selection_template_url, auth=AUTH)
         self.assertEqual(500, response.status_code)
         self.assertTrue("ProtectedError" in str(response.content))
-        GET_and_assert_equal_expected_code(self, subtask_input_selection_template_url, 200)
+        GET_and_assert_equal_expected_code(self, task_relation_selection_template_url, 200)
 
     def test_GET_SubtaskInput_list_view_shows_entry(self):
 
diff --git a/SAS/TMSS/test/t_tmssapp_scheduling_django_API.py b/SAS/TMSS/test/t_tmssapp_scheduling_django_API.py
index 6260ec3fbbb..71901373425 100755
--- a/SAS/TMSS/test/t_tmssapp_scheduling_django_API.py
+++ b/SAS/TMSS/test/t_tmssapp_scheduling_django_API.py
@@ -95,10 +95,6 @@ class DataproductSpecificationsTemplateTest(unittest.TestCase):
         self.assertGreater(after, entry.updated_at)
 
 
-class SubtaskInputSelectionTemplateTest(unittest.TestCase):
-    # This currently adds nothing on top of the template base class, so nothing new to test here.
-    pass
-
 class DataproductFeedbackTemplateTest(unittest.TestCase):
     # This currently adds nothing on top of the template base class, so nothing new to test here.
     pass
diff --git a/SAS/TMSS/test/t_tmssapp_specification_REST_API.py b/SAS/TMSS/test/t_tmssapp_specification_REST_API.py
index 1f8bac781f5..d5d4d76c13c 100755
--- a/SAS/TMSS/test/t_tmssapp_specification_REST_API.py
+++ b/SAS/TMSS/test/t_tmssapp_specification_REST_API.py
@@ -274,7 +274,7 @@ class TaskRelationSelectionTemplateTestCase(unittest.TestCase):
     def test_task_relation_selection_template_list_apiformat(self):
         r = requests.get(BASE_URL + '/task_relation_selection_template/?format=api', auth=AUTH)
         self.assertEqual(r.status_code, 200)
-        self.assertTrue("Work Relation Selection Template List" in r.content.decode('utf8'))
+        self.assertTrue("Task Relation Selection Template List" in r.content.decode('utf8'))
 
     def test_task_relation_selection_template_GET_nonexistant_raises_error(self):
         GET_and_assert_equal_expected_code(self, BASE_URL + '/task_relation_selection_template/1234321/', 404)
diff --git a/SAS/TMSS/test/tmss_test_data_django_models.py b/SAS/TMSS/test/tmss_test_data_django_models.py
index 7c09f45d7e7..957712bda57 100644
--- a/SAS/TMSS/test/tmss_test_data_django_models.py
+++ b/SAS/TMSS/test/tmss_test_data_django_models.py
@@ -278,7 +278,7 @@ def SubtaskInput_test_data(subtask: models.Subtask=None, producer: models.Subtas
             "task_relation_blueprint": models.TaskRelationBlueprint.objects.create(**TaskRelationBlueprint_test_data()),
             "producer": producer,
             "selection_doc": {},
-            "selection_template": models.SubtaskInputSelectionTemplate.objects.create(**SubtaskInputSelectionTemplate_test_data()),
+            "selection_template": models.TaskRelationSelectionTemplate.objects.create(**TaskRelationSelectionTemplate_test_data()),
             "tags":[]}
 
 def Subtask_test_data(task_blueprint: models.TaskBlueprint=None, subtask_template: models.SubtaskTemplate=None,
@@ -376,14 +376,3 @@ def DataproductHash_test_data() -> dict:
             "algorithm": models.Algorithm.objects.get(value='md5'),
             "hash": "myhash_1",
             "tags": ['tmss', 'testing']}
-
-def SubtaskInputSelectionTemplate_test_data(version:str=None) -> dict:
-    if version is None:
-        version = str(uuid.uuid4())
-
-    return {"name": "data",
-            "description": 'My one date',
-            "version": version,
-            "schema": {"mykey": "my value"},
-            "tags": ["TMSS", "TESTING"]}
-
diff --git a/SAS/TMSS/test/tmss_test_data_rest.py b/SAS/TMSS/test/tmss_test_data_rest.py
index 06ee8fad28c..3bc7f4471c6 100644
--- a/SAS/TMSS/test/tmss_test_data_rest.py
+++ b/SAS/TMSS/test/tmss_test_data_rest.py
@@ -252,7 +252,8 @@ class TMSSRESTTestDataCreator():
                 "requirements_doc": "{}",
                 "do_cancel": False,
                 "draft": scheduling_unit_draft_url,
-                "requirements_template": template_url}
+                "requirements_template": template_url,
+                "task_blueprints":[]}
     
     def TaskBlueprint(self, name="my_TaskBlueprint", draft_url=None, template_url=None, scheduling_unit_blueprint_url=None):
         if draft_url is None:
@@ -461,17 +462,7 @@ class TMSSRESTTestDataCreator():
                 "corrupted_since": datetime.utcnow().isoformat(),
                 "tags": ['tmss', 'testing']}
     
-    def SubtaskInputSelectionTemplate(self, name="my_SubtaskInputSelectionTemplate", version:str=None) -> dict:
-        if version is None:
-            version = str(uuid.uuid4())
-
-        return  {"name": name,
-                 "description": 'My one date',
-                 "version": version,
-                 "schema": {"mykey": "my value"},
-                 "tags": ["TMSS", "TESTING"]}
-    
-    def SubtaskInput(self, subtask_url=None, task_relation_blueprint_url=None, dataproduct_urls=None, subtask_output_url=None, subtask_input_selection_template_url=None):
+    def SubtaskInput(self, subtask_url=None, task_relation_blueprint_url=None, dataproduct_urls=None, subtask_output_url=None, task_relation_selection_template_url=None):
         if subtask_url is None:
             subtask_url = self.post_data_and_get_url(self.Subtask(), '/subtask/')
     
@@ -486,15 +477,15 @@ class TMSSRESTTestDataCreator():
         if subtask_output_url is None:
             subtask_output_url = self.post_data_and_get_url(self.SubtaskOutput(), '/subtask_output/')
     
-        if subtask_input_selection_template_url is None:
-            subtask_input_selection_template_url = self.post_data_and_get_url(self.SubtaskInputSelectionTemplate(), '/subtask_input_selection_template/')
+        if task_relation_selection_template_url is None:
+            task_relation_selection_template_url = self.post_data_and_get_url(self.TaskRelationSelectionTemplate(), '/task_relation_selection_template/')
     
         return {"subtask": subtask_url,
                 "task_relation_blueprint": task_relation_blueprint_url,
                 "producer": subtask_output_url,
                 "dataproducts": dataproduct_urls,
                 "selection_doc": "{}",
-                "selection_template": subtask_input_selection_template_url,
+                "selection_template": task_relation_selection_template_url,
                 "tags": []}
     
     def Filesystem(self, name="my_Filesystem", cluster_url=None):
-- 
GitLab