From 67c56df43c68c8ca6b8027274ffea6e11a294a62 Mon Sep 17 00:00:00 2001 From: Ross Webster Date: Wed, 22 Nov 2023 15:17:57 +1000 Subject: [PATCH] [QOLSVC-3826] Check for None before converting to string, and adding more unit test cases --- ckanext/data_qld/converters.py | 2 ++ ckanext/data_qld/tests/test_converters.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/ckanext/data_qld/converters.py b/ckanext/data_qld/converters.py index 402f0a5a..79a53f66 100644 --- a/ckanext/data_qld/converters.py +++ b/ckanext/data_qld/converters.py @@ -12,6 +12,8 @@ def filesize_converter(value, context): :rtype: int """ + if not value: + return None value = str(value) # remove whitespaces value = re.sub(' ', '', value) diff --git a/ckanext/data_qld/tests/test_converters.py b/ckanext/data_qld/tests/test_converters.py index aa53c6b8..e2d1d491 100644 --- a/ckanext/data_qld/tests/test_converters.py +++ b/ckanext/data_qld/tests/test_converters.py @@ -14,6 +14,8 @@ def test_filesize_converter(): '2 kb': 2048, 1024: 1024, '1024, ': 1024, + '1,000 bytes': 1000, + '1,000 MB': 1048576000, } for key, value in six.iteritems(test_cases): assert value == filesize_converter(key, {})