Skip to content

Commit

Permalink
Merge pull request #231 from qld-gov-au/develop
Browse files Browse the repository at this point in the history
Develop to Master - Upload size field
  • Loading branch information
RossWebsterWork authored Nov 24, 2023
2 parents 133c7e9 + 52ba4a0 commit 727c800
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ckanext/data_qld/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ def filesize_converter(value, context):
:rtype: int
"""
if not value:
return None
value = str(value)
# remove whitespaces
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):
value = int(value)
else:
value = filesize_bytes(value)

return value
Expand Down
21 changes: 21 additions & 0 deletions ckanext/data_qld/tests/test_converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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 = {' , ': None,
' ': None,
'': None,
None: None,
'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, {})

0 comments on commit 727c800

Please sign in to comment.