diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py index 8ccf852658bfb3c020f90d43753e86874ecd2192..29c8a71ef092e2eb6607ac8d691f4639efd1e880 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py @@ -523,10 +523,10 @@ class SchedulingUnitBlueprint(RefreshFromDbInvalidatesCachedPropertiesMixin, Tem # self.scheduling_constraints_template_id != self.__original_scheduling_constraints_template_id): raise TMSSException('The scheduling constraints of SchedulingUnitBlueprint pk=%s status=%s cannot be updated since it is not in defined or schedulable state.' % (self.pk, self.status)) - # update the original constraints value for comparison on next save - # todo: make this work for constraints_doc as well: - # self.__original_scheduling_constraints_doc = self.scheduling_constraints_doc - self.__original_scheduling_constraints_template_id = self.scheduling_constraints_template_id + # update the original constraints value for comparison on next save + # todo: make this work for constraints_doc as well: + # self.__original_scheduling_constraints_doc = self.scheduling_constraints_doc + self.__original_scheduling_constraints_template_id = self.scheduling_constraints_template_id super().save(force_insert, force_update, using, update_fields) diff --git a/SAS/TMSS/backend/test/t_tmssapp_specification_django_API.py b/SAS/TMSS/backend/test/t_tmssapp_specification_django_API.py index 43866f04310a4407d2a41e5520bc1aad5472976f..aa6fd796b8cf1762186f795c6dd9114c5814e97a 100755 --- a/SAS/TMSS/backend/test/t_tmssapp_specification_django_API.py +++ b/SAS/TMSS/backend/test/t_tmssapp_specification_django_API.py @@ -779,12 +779,34 @@ class SchedulingUnitBlueprintTest(unittest.TestCase): scheduling_unit_blueprint.refresh_from_db() + # we should be able to modify other fields + scheduling_unit_blueprint.results_accepted = not scheduling_unit_blueprint.results_accepted + scheduling_unit_blueprint.save() + + # but scheduling constraints should be immutable with self.assertRaises(TMSSException) as context: scheduling_unit_blueprint.scheduling_constraints_template = models.SchedulingConstraintsTemplate.objects.get(name="constraints_2") scheduling_unit_blueprint.save() self.assertIn('schedulable state', str(context.exception)) + def test_SchedulingUnitBlueprint_allows_updating_scheduling_constraints_template_if_in_correct_state(self): + + # setup + constraints_3 = models.SchedulingConstraintsTemplate.objects.create(**SchedulingConstraintsTemplate_test_data(name='constraints_3')) + constraints_4 = models.SchedulingConstraintsTemplate.objects.create(**SchedulingConstraintsTemplate_test_data(name='constraints_4')) + scheduling_unit_blueprint = models.SchedulingUnitBlueprint.objects.create(**SchedulingUnitBlueprint_test_data(scheduling_constraints_template= constraints_3)) + task_blueprint = models.TaskBlueprint.objects.create(**TaskBlueprint_test_data(scheduling_unit_blueprint=scheduling_unit_blueprint)) + subtask = models.Subtask.objects.create(**Subtask_test_data()) + subtask.task_blueprints.set([task_blueprint]) + subtask.save() + + scheduling_unit_blueprint.refresh_from_db() + + scheduling_unit_blueprint.scheduling_constraints_template = models.SchedulingConstraintsTemplate.objects.get(name="constraints_4") + scheduling_unit_blueprint.save() + + @unittest.skip('skipped until we fix detection for constraints doc changes') def test_SchedulingUnitBlueprint_prevents_updating_scheduling_constraints_doc_if_not_in_correct_state(self): # setup @@ -797,12 +819,31 @@ class SchedulingUnitBlueprintTest(unittest.TestCase): scheduling_unit_blueprint.refresh_from_db() + # we should be able to modify other fields + scheduling_unit_blueprint.results_accepted = not scheduling_unit_blueprint.results_accepted + scheduling_unit_blueprint.save() + + # but scheduling constraints should be immutable with self.assertRaises(TMSSException) as context: scheduling_unit_blueprint.scheduling_constraints_doc = {'foo': 'matic'} scheduling_unit_blueprint.save() self.assertIn('schedulable state', str(context.exception)) + def test_SchedulingUnitBlueprint_allows_updating_scheduling_constraints_doc_if_in_correct_state(self): + + # setup + scheduling_unit_blueprint = models.SchedulingUnitBlueprint.objects.create(**SchedulingUnitBlueprint_test_data()) + task_blueprint = models.TaskBlueprint.objects.create(**TaskBlueprint_test_data(scheduling_unit_blueprint=scheduling_unit_blueprint)) + subtask = models.Subtask.objects.create(**Subtask_test_data()) + subtask.task_blueprints.set([task_blueprint]) + subtask.save() + + scheduling_unit_blueprint.refresh_from_db() + + scheduling_unit_blueprint.scheduling_constraints_doc = {'foo': 'matic'} + scheduling_unit_blueprint.save() + class TaskBlueprintTest(unittest.TestCase): @classmethod