From d6e57fc9fafa88584c74b29fc4609b523ec4260f 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: Fri, 26 Mar 2021 16:42:36 +0100
Subject: [PATCH] TMSS-520: Rename Algorithm to HashAlgorithm

---
 SAS/TMSS/backend/src/tmss/tmssapp/adapters/sip.py      |  6 +++---
 .../src/tmss/tmssapp/migrations/0001_initial.py        |  6 +++---
 SAS/TMSS/backend/src/tmss/tmssapp/models/scheduling.py |  6 +++---
 SAS/TMSS/backend/src/tmss/tmssapp/populate.py          |  2 +-
 .../backend/src/tmss/tmssapp/serializers/scheduling.py |  4 ++--
 .../backend/src/tmss/tmssapp/viewsets/scheduling.py    | 10 +++++-----
 SAS/TMSS/backend/src/tmss/urls.py                      |  2 +-
 SAS/TMSS/backend/test/t_tmssapp_scheduling_REST_API.py |  8 ++++----
 SAS/TMSS/backend/test/test_utils.py                    |  4 ++--
 SAS/TMSS/backend/test/tmss_test_data_django_models.py  |  2 +-
 SAS/TMSS/backend/test/tmss_test_data_rest.py           |  8 ++++----
 11 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/sip.py b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/sip.py
index 76e057c9745..50f95df8bd5 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/sip.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/sip.py
@@ -1,5 +1,5 @@
 from lofar.sas.tmss.tmss.exceptions import *
-from lofar.sas.tmss.tmss.tmssapp.models.scheduling import Dataproduct, SubtaskType, Subtask, SubtaskOutput, SIPidentifier, Algorithm
+from lofar.sas.tmss.tmss.tmssapp.models.scheduling import Dataproduct, SubtaskType, Subtask, SubtaskOutput, SIPidentifier, HashAlgorithm
 from lofar.sas.tmss.tmss.tmssapp.models.specification import Datatype, Dataformat
 from lofar.lta.sip import siplib, ltasip, validator, constants
 
@@ -447,12 +447,12 @@ def generate_sip_for_dataproduct(dataproduct: Dataproduct) -> siplib.Sip:
         if dataproduct.hashes:
             from django.core.exceptions import ObjectDoesNotExist
             try:
-                sip_dataproduct.set_checksum_md5(dataproduct.hashes.get(algorithm=Algorithm.Choices.MD5.value).hash)
+                sip_dataproduct.set_checksum_md5(dataproduct.hashes.get(hash_algorithm=HashAlgorithm.Choices.MD5.value).hash)
             except ObjectDoesNotExist:
                 pass
 
             try:
-                sip_dataproduct.set_checksum_adler32(dataproduct.hashes.get(algorithm=Algorithm.Choices.ADLER32.value).hash)
+                sip_dataproduct.set_checksum_adler32(dataproduct.hashes.get(hash_algorithm=HashAlgorithm.Choices.ADLER32.value).hash)
             except ObjectDoesNotExist:
                 pass
 
diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/migrations/0001_initial.py b/SAS/TMSS/backend/src/tmss/tmssapp/migrations/0001_initial.py
index d4095c88c95..b621cd42951 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/migrations/0001_initial.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/migrations/0001_initial.py
@@ -19,7 +19,7 @@ class Migration(migrations.Migration):
 
     operations = [
         migrations.CreateModel(
-            name='Algorithm',
+            name='HashAlgorithm',
             fields=[
                 ('value', models.CharField(max_length=128, primary_key=True, serialize=False, unique=True)),
             ],
@@ -1356,8 +1356,8 @@ class Migration(migrations.Migration):
         ),
         migrations.AddField(
             model_name='dataproducthash',
-            name='algorithm',
-            field=models.ForeignKey(help_text='Algorithm used (MD5, AES256).', on_delete=django.db.models.deletion.PROTECT, to='tmssapp.Algorithm'),
+            name='hash_algorithm',
+            field=models.ForeignKey(help_text='Algorithm used for hashing (MD5, AES256).', on_delete=django.db.models.deletion.PROTECT, to='tmssapp.HashAlgorithm'),
         ),
         migrations.AddField(
             model_name='dataproducthash',
diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/scheduling.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/scheduling.py
index 9535b3c3d97..234f8ab359c 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/models/scheduling.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/scheduling.py
@@ -76,8 +76,8 @@ class StationType(AbstractChoice):
             INTERNATIONAL = "international"
 
 
-class Algorithm(AbstractChoice):
-    """Defines the model and predefined list of possible Algorithm's for DataproductHash.
+class HashAlgorithm(AbstractChoice):
+    """Defines the model and predefined list of possible HashAlgorithm's for DataproductHash.
     The items in the Choices class below are automagically populated into the database via a data migration."""
 
     class Choices(Enum):
@@ -434,6 +434,6 @@ class DataproductArchiveInfo(BasicCommon):
 
 class DataproductHash(BasicCommon):
     dataproduct = ForeignKey('Dataproduct', related_name='hashes', on_delete=PROTECT, help_text='The dataproduct to which this hash refers.')
-    algorithm = ForeignKey('Algorithm', null=False, on_delete=PROTECT, help_text='Algorithm used (MD5, AES256).')
+    hash_algorithm = ForeignKey('HashAlgorithm', null=False, on_delete=PROTECT, help_text='Algorithm used for hashing (MD5, AES256).')
     hash = CharField(max_length=128, help_text='Hash value.')
 
diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
index 72c334977eb..a53992b0962 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
@@ -41,7 +41,7 @@ def populate_choices(apps, schema_editor):
     :return: None
     '''
     choice_classes = [Role, Datatype, Dataformat, CopyReason,
-                      SubtaskState, SubtaskType, StationType, Algorithm, SchedulingRelationPlacement,
+                      SubtaskState, SubtaskType, StationType, HashAlgorithm, SchedulingRelationPlacement,
                       Flag, ProjectCategory, PeriodCategory, Quantity, TaskType, ProjectRole]
 
     # upload choices in parallel
diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/serializers/scheduling.py b/SAS/TMSS/backend/src/tmss/tmssapp/serializers/scheduling.py
index 7c8bd8c29ee..e77cd1e3194 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/serializers/scheduling.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/serializers/scheduling.py
@@ -34,9 +34,9 @@ class StationTypeSerializer(DynamicRelationalHyperlinkedModelSerializer):
         fields = '__all__'
 
 
-class AlgorithmSerializer(DynamicRelationalHyperlinkedModelSerializer):
+class HashAlgorithmSerializer(DynamicRelationalHyperlinkedModelSerializer):
     class Meta:
-        model = models.Algorithm
+        model = models.HashAlgorithm
         fields = '__all__'
 
 
diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/scheduling.py b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/scheduling.py
index 8bda4797baa..a1201686b64 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/scheduling.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/scheduling.py
@@ -77,9 +77,9 @@ class StationTypeViewSet(LOFARViewSet):
     queryset = models.StationType.objects.all()
     serializer_class = serializers.StationTypeSerializer
 
-class AlgorithmViewSet(LOFARViewSet):
-    queryset = models.Algorithm.objects.all()
-    serializer_class = serializers.AlgorithmSerializer
+class HashAlgorithmViewSet(LOFARViewSet):
+    queryset = models.HashAlgorithm.objects.all()
+    serializer_class = serializers.HashAlgorithmSerializer
 
 class SubtaskTemplateFilter(filters.FilterSet):
     class Meta:
@@ -412,12 +412,12 @@ class DataproductViewSet(LOFARViewSet):
 
         if 'md5_checksum' in json_doc:
             models.DataproductHash.objects.create(dataproduct=dataproduct,
-                                                  algorithm=models.Algorithm.objects.get(value=models.Algorithm.Choices.MD5.value),
+                                                  hash_algorithm=models.HashAlgorithm.objects.get(value=models.HashAlgorithm.Choices.MD5.value),
                                                   hash=json_doc['md5_checksum'])
 
         if 'adler32_checksum' in json_doc:
             models.DataproductHash.objects.create(dataproduct=dataproduct,
-                                                  algorithm=models.Algorithm.objects.get(value=models.Algorithm.Choices.ADLER32.value),
+                                                  hash_algorithm=models.HashAlgorithm.objects.get(value=models.HashAlgorithm.Choices.ADLER32.value),
                                                   hash=json_doc['adler32_checksum'])
 
         # create empty feedback. Apart from the archive info above, ingest does not create feedback like observations/pipelines do.
diff --git a/SAS/TMSS/backend/src/tmss/urls.py b/SAS/TMSS/backend/src/tmss/urls.py
index 66e58162725..29301b96591 100644
--- a/SAS/TMSS/backend/src/tmss/urls.py
+++ b/SAS/TMSS/backend/src/tmss/urls.py
@@ -192,7 +192,7 @@ router.register(r'scheduling_unit_blueprint/(?P<scheduling_unit_blueprint_id>\d+
 router.register(r'subtask_state', viewsets.SubtaskStateViewSet)
 router.register(r'subtask_type', viewsets.SubtaskTypeViewSet)
 router.register(r'station_type', viewsets.StationTypeViewSet)
-router.register(r'algorithm', viewsets.AlgorithmViewSet)
+router.register(r'hash_algorithm', viewsets.HashAlgorithmViewSet)
 router.register(r'scheduling_relation_placement', viewsets.SchedulingRelationPlacement)
 
 # templates
diff --git a/SAS/TMSS/backend/test/t_tmssapp_scheduling_REST_API.py b/SAS/TMSS/backend/test/t_tmssapp_scheduling_REST_API.py
index 232c237ec2f..711ebc4a0d5 100755
--- a/SAS/TMSS/backend/test/t_tmssapp_scheduling_REST_API.py
+++ b/SAS/TMSS/backend/test/t_tmssapp_scheduling_REST_API.py
@@ -1171,7 +1171,7 @@ class DataproductHashTestCase(unittest.TestCase):
         url = r_dict['url']
         GET_OK_and_assert_equal_expected_response(self, url, dph_test_data)
 
-        test_patch = {"algorithm": BASE_URL + '/algorithm/aes256',
+        test_patch = {"hash_algorithm": BASE_URL + '/hash_algorithm/aes256',
                       "hash": 'bender-was-here'}
 
         # PATCH item and verify
@@ -1207,7 +1207,7 @@ class DataproductHashTestCase(unittest.TestCase):
         self.assertTrue("ProtectedError" in str(response.content))
         GET_and_assert_equal_expected_code(self, dph_test_data['dataproduct'], 200)
 
-    def test_dataproduct_hash_PROTECT_behavior_on_algorithm_deleted(self):
+    def test_dataproduct_hash_PROTECT_behavior_on_hash_algorithm_deleted(self):
         dph_test_data = test_data_creator.DataproductHash(dataproduct_url=self.dataproduct_url)
 
         # POST new item and verify
@@ -1217,10 +1217,10 @@ class DataproductHashTestCase(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(dph_test_data['algorithm'], auth=AUTH)
+        response = requests.delete(dph_test_data['hash_algorithm'], auth=AUTH)
         self.assertEqual(500, response.status_code)
         self.assertTrue("ProtectedError" in str(response.content))
-        GET_and_assert_equal_expected_code(self, dph_test_data['algorithm'], 200)
+        GET_and_assert_equal_expected_code(self, dph_test_data['hash_algorithm'], 200)
 
 
 class DataproductArchiveInfoTestCase(unittest.TestCase):
diff --git a/SAS/TMSS/backend/test/test_utils.py b/SAS/TMSS/backend/test/test_utils.py
index ad64349b5c1..ac81d6d0c43 100644
--- a/SAS/TMSS/backend/test/test_utils.py
+++ b/SAS/TMSS/backend/test/test_utils.py
@@ -848,8 +848,8 @@ def create_scheduling_unit_blueprint_simulator(scheduling_unit_blueprint_id: int
 
                         models.DataproductArchiveInfo.objects.create(dataproduct=output_dp, storage_ticket=uuid4())
 
-                        for algo in models.Algorithm.objects.all():
-                            models.DataproductHash.objects.create(dataproduct=output_dp, algorithm=algo, hash=uuid4())
+                        for algo in models.HashAlgorithm.objects.all():
+                            models.DataproductHash.objects.create(dataproduct=output_dp, hash_algorithm=algo, hash=uuid4())
             elif status == models.SubtaskState.Choices.DEFINED.value:
                 state_transition = models.SubtaskStateLog.objects.filter(subtask__id=subtask.id,
                                                                          old_state__value=models.SubtaskState.Choices.SCHEDULING.value,
diff --git a/SAS/TMSS/backend/test/tmss_test_data_django_models.py b/SAS/TMSS/backend/test/tmss_test_data_django_models.py
index 03bd63e3478..c4c98b7f64b 100644
--- a/SAS/TMSS/backend/test/tmss_test_data_django_models.py
+++ b/SAS/TMSS/backend/test/tmss_test_data_django_models.py
@@ -519,7 +519,7 @@ def DataproductArchiveInfo_test_data() -> dict:
 
 def DataproductHash_test_data() -> dict:
     return {"dataproduct": models.Dataproduct.objects.create(**Dataproduct_test_data()),
-            "algorithm": models.Algorithm.objects.get(value='md5'),
+            "hash_algorithm": models.HashAlgorithm.objects.get(value='md5'),
             "hash": "myhash_1",
             "tags": ['tmss', 'testing']}
 
diff --git a/SAS/TMSS/backend/test/tmss_test_data_rest.py b/SAS/TMSS/backend/test/tmss_test_data_rest.py
index 551a251a688..046bc7fa6a3 100644
--- a/SAS/TMSS/backend/test/tmss_test_data_rest.py
+++ b/SAS/TMSS/backend/test/tmss_test_data_rest.py
@@ -764,15 +764,15 @@ class TMSSRESTTestDataCreator():
                 "identity": True,
                 "tags": ['tmss', 'testing']}
     
-    def DataproductHash(self, algorithm_url=None, hash="my_hash", dataproduct_url=None):
-        if algorithm_url is None:
-            algorithm_url = self.django_api_url + '/algorithm/md5'
+    def DataproductHash(self, hash_algorithm_url=None, hash="my_hash", dataproduct_url=None):
+        if hash_algorithm_url is None:
+            hash_algorithm_url = self.django_api_url + '/hash_algorithm/md5'
     
         if dataproduct_url is None:
             dataproduct_url = self.cached_dataproduct_url
     
         return {"dataproduct": dataproduct_url,
-                "algorithm": algorithm_url,
+                "hash_algorithm": hash_algorithm_url,
                 "hash": hash,
                 "tags": ['tmss', 'testing']}
     
-- 
GitLab