From 2b6fe5b099132bc4e491f0e6ee19f73e0e683b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20K=C3=BCnsem=C3=B6ller?= <jkuensem@physik.uni-bielefeld.de> Date: Wed, 28 Apr 2021 18:11:57 +0200 Subject: [PATCH] TMSS-697: fix logic --- .../src/tmss/tmssapp/models/specification.py | 15 ++++++--------- .../test/t_tmssapp_specification_django_API.py | 3 +-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py index 29c8a71ef09..7e3b5624af7 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py @@ -501,8 +501,8 @@ class SchedulingUnitBlueprint(RefreshFromDbInvalidatesCachedPropertiesMixin, Tem super().__init__(*args, **kwargs) # keep original scheduling constraints to detect changes on save - # todo: make this work for constraints_doc as well: - # self.__original_scheduling_constraints_doc = self.scheduling_constraints_doc + if 'scheduling_constraints_doc' in kwargs.keys(): + self.__original_scheduling_constraints_doc = kwargs['scheduling_constraints_doc'] self.__original_scheduling_constraints_template_id = self.scheduling_constraints_template_id def save(self, force_insert=False, force_update=False, using=None, update_fields=None): @@ -515,17 +515,14 @@ class SchedulingUnitBlueprint(RefreshFromDbInvalidatesCachedPropertiesMixin, Tem if hasattr(self, 'draft'): setattr(self, copy_field, getattr(self.draft, copy_field)) else: - # On updates, prevent changing the scheduling contraints doc or template if we are past schedulable state + # On updates, prevent changing the scheduling constraints doc or template if we are past schedulable state if self.status not in [SchedulingUnitBlueprint.Status.DEFINED.value, SchedulingUnitBlueprint.Status.SCHEDULABLE.value] and \ - self.scheduling_constraints_template_id != self.__original_scheduling_constraints_template_id: - # todo: make this work for constraints_doc as well: - #(self.scheduling_constraints_doc != self.__original_scheduling_constraints_doc or - # self.scheduling_constraints_template_id != self.__original_scheduling_constraints_template_id): + (self.scheduling_constraints_doc != self.__original_scheduling_constraints_doc or + 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_doc = dict(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 aa6fd796b8c..94a2bfeed52 100755 --- a/SAS/TMSS/backend/test/t_tmssapp_specification_django_API.py +++ b/SAS/TMSS/backend/test/t_tmssapp_specification_django_API.py @@ -472,7 +472,7 @@ class SchedulingUnitDraftTest(unittest.TestCase): models.SchedulingUnitDraft.objects.create(**test_data) def test_SchedulingUnitDraft_gets_created_with_correct_default_ingest_permission_required(self): - + # setup entry = models.SchedulingUnitDraft.objects.create(**SchedulingUnitDraft_test_data()) #check the auto_ingest on project @@ -806,7 +806,6 @@ class SchedulingUnitBlueprintTest(unittest.TestCase): 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 -- GitLab