From 33536bdb8a3bcc5774911af56cfa587b30d39ab4 Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Wed, 11 Nov 2020 17:36:10 +0100
Subject: [PATCH] TMSS-190: create convenience sched_set per project

---
 SAS/TMSS/src/tmss/tmssapp/populate.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/SAS/TMSS/src/tmss/tmssapp/populate.py b/SAS/TMSS/src/tmss/tmssapp/populate.py
index d210418395f..d0028e00f49 100644
--- a/SAS/TMSS/src/tmss/tmssapp/populate.py
+++ b/SAS/TMSS/src/tmss/tmssapp/populate.py
@@ -52,7 +52,7 @@ def populate_test_data():
         # only add (with  expensive setup time) example data when developing/testing and we're not unittesting
         if isTestEnvironment() or isDevelopmentEnvironment():
             from lofar.sas.tmss.tmss.exceptions import TMSSException
-            from lofar.sas.tmss.test.tmss_test_data_django_models import SchedulingSet_test_data, SchedulingUnitDraft_test_data
+            from lofar.sas.tmss.test.tmss_test_data_django_models import SchedulingUnitDraft_test_data
             from lofar.sas.tmss.tmss.tmssapp.tasks import create_task_blueprints_and_subtasks_from_scheduling_unit_draft, create_task_blueprints_and_subtasks_and_schedule_subtasks_from_scheduling_unit_draft
             from lofar.sas.tmss.tmss.tmssapp.subtasks import schedule_subtask
             from lofar.common.json_utils import get_default_json_object_for_schema
@@ -67,12 +67,7 @@ def populate_test_data():
                 if 'Commissioning' not in tmss_project.tags:
                     continue
 
-                for set_nr in range(2):
-                    scheduling_set_data = SchedulingSet_test_data(name="Scheduling Set UC1 example %s (%s)" % (set_nr, tmss_project.name), project=tmss_project)
-                    scheduling_set = models.SchedulingSet.objects.create(**scheduling_set_data)
-
-                    logger.info('created test scheduling_set: %s', scheduling_set.name)
-
+                for scheduling_set in tmss_project.scheduling_sets.all():
                     for unit_nr in range(2):
                         # the 'template' in the strategy_template is a predefined json-data blob which validates against the given scheduling_unit_template
                         # a user might 'upload' a partial json-data blob, so add all the known defaults
@@ -137,6 +132,8 @@ def populate_cycles(apps, schema_editor):
 
 
 def populate_projects(apps, schema_editor):
+    from lofar.sas.tmss.test.tmss_test_data_django_models import SchedulingSet_test_data
+
     for name, rank in (("high", 3), ("normal", 2), ("low", 1)):
         tmss_project = models.Project.objects.create(name=name,
                                                  description="Project for all TMSS tests and commissioning (%s priority)" % (name,),
@@ -149,6 +146,9 @@ def populate_projects(apps, schema_editor):
         tmss_project.cycles.set([models.Cycle.objects.get(name="Cycle 14")])
         tmss_project.save()
 
+        # for convenience, create a schedulingset for each project
+        models.SchedulingSet.objects.create(**SchedulingSet_test_data(name="Test Scheduling Set", project=tmss_project))
+
 
 def populate_resources(apps, schema_editor):
     ResourceType.objects.create(name="lta_storage", description="Amount of storage in the LTA (in bytes)", quantity=Quantity.objects.get(value=Quantity.Choices.BYTES.value))
-- 
GitLab