Skip to content

Commit

Permalink
[QOLSVC-3826] Convert empty size string to None and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RossWebsterWork committed Nov 22, 2023
1 parent eb8b44a commit 2c5d92a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ckanext/data_qld/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ def filesize_converter(value, context):
value = re.sub(' ', '', value)
# remove commas
value = re.sub(',', '', value)
if not value:
return None
value = value.upper()

# If the size is not all digits then get size converted into bytes
if value and re.search(r'^\d+$', value) is None:
if re.search(r'^\d+$', value) is None:
value = filesize_bytes(value)

return value
Expand Down
23 changes: 23 additions & 0 deletions ckanext/data_qld/tests/test_converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# encoding: utf-8
"""Unit tests for ckan/logic/converters.py.
"""
import six
from ckanext.data_qld.converters import filesize_converter


def test_filesize_converter():
test_cases = {'foo': 'FOO',
'FOO': 'FOO',
'foo,baz': 'FOOBAZ',
' , ': None,
' ': None,
'': None,
None: None,
1024: '1 KiB',
'1024': '1 KiB',
'1024, ': '1 KiB',
'1024a': '1024A',
}
for key, value in six.iteritems(test_cases):
assert value == filesize_converter(key, {})

0 comments on commit 2c5d92a

Please sign in to comment.