Skip to content

Commit

Permalink
Merge pull request #314 from kobotoolbox/expand-select-x-from-file
Browse files Browse the repository at this point in the history
expand select_*_from_file
  • Loading branch information
jnm authored Jan 4, 2024
2 parents 54515ab + 7c10ecf commit f3eb041
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/formpack/utils/expand_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ def _expand_type_to_dict(type_str: str) -> Dict[str, Union[str, bool]]:
(type_, list_name) = match.groups()
matched_type = selects[select_type]
out['type'] = matched_type
out['select_from_list_name'] = list_name
ref_field_name = 'select_from_list_name'
if 'from_file' in matched_type:
ref_field_name = 'file'
out[ref_field_name] = list_name
return out
# if it does not expand, we return the original string
return {'type': type_str}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_expand_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def test_expand_selects_with_or_other():
assert _expand_type_to_dict('select_one_or_other').get(_OR_OTHER) == True


def test_expand_select_x_from_file():
row_type_dict = _expand_type_to_dict('select_one_from_file file.csv')
assert 'select_from_list_name' not in row_type_dict
assert row_type_dict.get('file') == 'file.csv'

row_type_dict = _expand_type_to_dict('select_multiple_from_file file.csv')
assert 'select_from_list_name' not in row_type_dict
assert row_type_dict.get('file') == 'file.csv'


def test_expand_select_one():
s1 = {'survey': [{'type': 'select_one dogs'}]}
expand_content(s1, in_place=True)
Expand Down

0 comments on commit f3eb041

Please sign in to comment.