From d0affc2f8e5073b9fb580489b3740027424fdfc5 Mon Sep 17 00:00:00 2001 From: Mikko Nieminen Date: Fri, 13 Dec 2024 15:19:24 +0100 Subject: [PATCH] update BatchValidateChecksumsTask error display on empty md5 value (#2050) --- CHANGELOG.rst | 1 + landingzones/tests/test_views_taskflow.py | 28 ++++++++++++++++++++--- taskflowbackend/tasks/irods_tasks.py | 3 ++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ca620220..684650a2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -75,6 +75,7 @@ Changed - Refactor ``landing_zone_move`` flow (#1846) - Move ``lock_project()`` into ``TaskflowTestMixin`` (#1847) - Make MD5 checksum comparison case insensitive (#2032) + - Improve ``BatchValidateChecksumsTask`` error display on empty MD5 value in file (#2050) Fixed ----- diff --git a/landingzones/tests/test_views_taskflow.py b/landingzones/tests/test_views_taskflow.py index f4ecd82a..508d48a8 100644 --- a/landingzones/tests/test_views_taskflow.py +++ b/landingzones/tests/test_views_taskflow.py @@ -24,6 +24,7 @@ from samplesheets.views import RESULTS_COLL, MISC_FILES_COLL, TRACK_HUBS_COLL # Taskflowbackend dependency +from taskflowbackend.tasks.irods_tasks import NO_FILE_CHECKSUM_LABEL from taskflowbackend.tests.base import TaskflowViewTestBase, IRODS_ACCESS_OWN @@ -595,7 +596,7 @@ def test_validate_no_files(self): ) def test_validate_invalid_md5(self): - """Test validating with invalid checksum file (should fail)""" + """Test validating with invalid checksum in file (should fail)""" irods_obj = self.make_irods_object(self.zone_coll, TEST_OBJ_NAME) make_object(self.irods, irods_obj.path + '.md5', INVALID_MD5) zone = LandingZone.objects.first() @@ -619,7 +620,28 @@ def test_validate_invalid_md5(self): AppAlert.objects.filter(alert_name='zone_validate').count(), 1 ) - def test_validate_no_md5(self): + def test_validate_empty_md5(self): + """Test validating with empty checksum in file (should fail)""" + irods_obj = self.make_irods_object(self.zone_coll, TEST_OBJ_NAME) + make_object(self.irods, irods_obj.path + '.md5', '') + zone = LandingZone.objects.first() + self.assertEqual(zone.status, ZONE_STATUS_ACTIVE) + self.assertEqual(len(self.zone_coll.data_objects), 2) + self.assertEqual(len(self.assay_coll.data_objects), 0) + self.assertEqual( + AppAlert.objects.filter(alert_name='zone_validate').count(), 0 + ) + + with self.login(self.user): + self.client.post(self.url_validate) + + self.assert_zone_status(zone, ZONE_STATUS_FAILED) + self.assertTrue('BatchValidateChecksumsTask' in zone.status_info) + self.assertTrue('File: {};'.format(NO_FILE_CHECKSUM_LABEL)) + self.assertEqual(len(self.zone_coll.data_objects), 2) + self.assertEqual(len(self.assay_coll.data_objects), 0) + + def test_validate_no_md5_file(self): """Test validating without checksum file (should fail)""" self.make_irods_object(self.zone_coll, TEST_OBJ_NAME) # No md5 @@ -636,7 +658,7 @@ def test_validate_no_md5(self): self.assertEqual(len(self.zone_coll.data_objects), 1) self.assertEqual(len(self.assay_coll.data_objects), 0) - def test_validate_md5_only(self): + def test_validate_md5_file_only(self): """Test validating zone with no file for MD5 file (should fail)""" irods_obj = self.make_irods_object(self.zone_coll, TEST_OBJ_NAME) self.md5_obj = self.make_irods_md5_object(irods_obj) diff --git a/taskflowbackend/tasks/irods_tasks.py b/taskflowbackend/tasks/irods_tasks.py index 8be2cd1e..8b831da7 100644 --- a/taskflowbackend/tasks/irods_tasks.py +++ b/taskflowbackend/tasks/irods_tasks.py @@ -36,6 +36,7 @@ META_EMPTY_VALUE = 'N/A' MD5_RE = re.compile(r'([^\w.])') CHECKSUM_RETRY = 5 +NO_FILE_CHECKSUM_LABEL = 'None' # Mixins ----------------------------------------------------------------------- @@ -660,7 +661,7 @@ def _compare_checksums(cls, data_obj, checksum): '(File: {}; iRODS: {})'.format( os.path.basename(data_obj.path), replica.resource_name, - checksum, + checksum or NO_FILE_CHECKSUM_LABEL, replica.checksum, ) )