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

Properly flatten select_multiple_from_file #319

Merged
merged 2 commits into from
Feb 6, 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/flatten_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def _flatten_survey_row(row):
row['type'] = '{} {} or_other'.format(_type, _list_name)
else:
row['type'] = '{} {}'.format(_type, _list_name)
elif row['type'] == 'select_one_from_file' and 'file' in row:
elif (
row['type'] in ('select_one_from_file', 'select_multiple_from_file')
and 'file' in row
):
_file = row.pop('file')
row['type'] = '{} {}'.format(_type, _file)
22 changes: 12 additions & 10 deletions tests/test_utils_flatten_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,18 @@ def test_flatten_select_or_other():
assert 'select_from_list_name' not in row0


def test_flatten_select_one_from_file():
s1 = {
'survey': [
{'type': 'select_one_from_file', 'file': 'fruits.csv'}
]
}
flatten_content(s1, in_place=True)
row0 = s1['survey'][0]
assert row0['type'] == 'select_one_from_file fruits.csv'
assert 'file' not in row0
def test_flatten_select_x_from_file():
# Search terms: select_one_from_file, select_multiple_from_file
for x in 'one', 'multiple':
s1 = {
'survey': [
{'type': f'select_{x}_from_file', 'file': 'fruits.csv'}
]
}
flatten_content(s1, in_place=True)
row0 = s1['survey'][0]
assert row0['type'] == f'select_{x}_from_file fruits.csv'
assert 'file' not in row0


def test_flatten_select():
Expand Down
Loading