Skip to content

Commit

Permalink
Merge pull request #319 from kobotoolbox/properly-flatten-select_mult…
Browse files Browse the repository at this point in the history
…iple_from_file

Properly flatten select_multiple_from_file
  • Loading branch information
duvld authored Feb 6, 2024
2 parents 569d8bf + a806e0d commit 3b6c89a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
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

0 comments on commit 3b6c89a

Please sign in to comment.