Skip to content

Commit

Permalink
Add basic test for exporting form with disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jnm committed Jul 16, 2020
1 parent 49dbe40 commit 8e9b209
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions kpi/tests/test_mock_data_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,25 @@ def setUp(self):
self.asset.owner.id)
)

def run_csv_export_test(self, expected_lines, export_options=None, user=None):
def run_csv_export_test(
self, expected_lines, export_options=None, asset=None, user=None
):
"""
Repeat yourself less while writing CSV export tests.
`expected_lines`: a list of strings *without* trailing newlines whose
UTF-8 encoded representation should match the export
result
`export_options`: a list of extra options for `ExportTask.data`. Do not
include `source` or `type`
`export_options`: (optional) a list of extra options for
`ExportTask.data`. Do not include `source` or `type`
`asset`: (optional) the asset to export. Defaults to `self.asset`
`user`: (optional) the user to own the export. Defaults to `self.user`
"""
export_task = ExportTask()
asset = self.asset if asset is None else asset
export_task.user = self.user if user is None else user
export_task.data = {
'source': reverse('asset-detail', args=[self.asset.uid]),
'source': reverse('asset-detail', args=[asset.uid]),
'type': 'csv'
}
if export_options:
Expand Down Expand Up @@ -617,3 +622,25 @@ def test_export_exceeding_api_submission_limit(self):
export_task._run_task(messages)
# Don't forget to add one for the header row!
self.assertEqual(len(list(export_task.result)), limit + excess + 1)

def test_export_with_disabled_questions(self):
asset = Asset.objects.create(
name='Form with undocumented `disabled` column',
owner=self.asset.owner,
content={'survey': [
{'name': 'q', 'type': 'integer'},
{'name': 'ignore', 'type': 'select_one nope', 'disabled': True},
]},
)
asset.deploy(backend='mock', active=True)
asset.deployment.mock_submissions(
[{'__version__': asset.latest_deployed_version.uid, 'q': 123,}]
)
# observe that `ignore` does not appear!
expected_lines = [
'"q";"_id";"_uuid";"_submission_time";"_validation_status";"_index"',
'"123";"";"";"";"";"1"',
]
# fails with `KeyError` prior to fix for kobotoolbox/formpack#219
self.run_csv_export_test(expected_lines, asset=asset)

0 comments on commit 8e9b209

Please sign in to comment.