Skip to content

Commit

Permalink
update BatchValidateChecksumsTask error display on empty md5 value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Dec 13, 2024
1 parent 5591c20 commit d0affc2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
28 changes: 25 additions & 3 deletions landingzones/tests/test_views_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion taskflowbackend/tasks/irods_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
META_EMPTY_VALUE = 'N/A'
MD5_RE = re.compile(r'([^\w.])')
CHECKSUM_RETRY = 5
NO_FILE_CHECKSUM_LABEL = 'None'


# Mixins -----------------------------------------------------------------------
Expand Down Expand Up @@ -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,
)
)
Expand Down

0 comments on commit d0affc2

Please sign in to comment.