Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand select_*_from_file #314

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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