Skip to content

Commit

Permalink
Add test to ensure an error is raised due to choice duplicates
Browse files Browse the repository at this point in the history
- Duplicate choice values are no longer allowed in PyXForm.
  More info: XLSForm/pyxform#23
- Rename new_cascading_select.xls to duplicate_choice_form.xls
- Replace choice_filter.xls file with choice_filter.xlsx; Duplicate of
  choice_filter.xls with allow_duplicate_choices setting
  • Loading branch information
DavisRayM committed Jan 28, 2020
1 parent 1a02671 commit 9ba9165
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion onadata/apps/api/tests/viewsets/test_floip_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_publish_number_question_names(self): # pylint: disable=C0103
self.assertEqual(response.status_code, 400)
self.assertEqual(response['Content-Type'],
'application/vnd.api+json')
self.assertIn(u"The name '1448506769745_42' is an invalid xml tag",
self.assertIn(u"The name '1448506769745_42' is an invalid XML tag",
response.data['text'])

def test_responses_endpoint_format(self):
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions onadata/apps/main/tests/test_form_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,24 @@ def test_spaced_xlsform(self):
self.assertRaisesMessage(
PyXFormError, msg, self._publish_xls_file, xls_path)
self.assertEquals(XForm.objects.count(), count)

def test_choice_duplicate_error(self):
"""
Test that the choice duplicate error is raised if
the "allow_choice_duplicates" setting is not set in the
forms settings sheet
"""
count = XForm.objects.count()
xls_path = os.path.join(
self.this_directory, 'fixtures', 'cascading_selects',
'duplicate_choice_form.xls')
msg = ("There does not seem to be"
" a `allow_choice_duplicates`"
" column header defined in your settings sheet."
" You must have set `allow_choice_duplicates`"
" setting in your settings sheet"
" to have duplicate choice list names"
" in your choices sheet")
self.assertRaisesMessage(
PyXFormError, msg, self._publish_xls_file, xls_path)
self.assertEquals(XForm.objects.count(), count)
6 changes: 5 additions & 1 deletion onadata/libs/tests/utils/test_export_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,10 @@ def test_zipped_sav_export_with_duplicate_name_in_choice_list(self):
| | animals | 6 | Other | # <--- duplicate name
| | animals | 8 | None |
| | animals | 9 | Don't Know |
| settings | |
| | allow_choice_duplicates |
| | Yes |
"""
survey = self.md_to_pyxform_survey(md, {'name': 'exp'})
data = [{"q1": "1",
Expand Down Expand Up @@ -2185,7 +2189,7 @@ def test_select_multiples_choices(self):

def test_select_multiples_choices_with_choice_filter(self):
survey = create_survey_from_xls(_logger_fixture_path(
'choice_filter.xls'
'choice_filter.xlsx'
))
dd = DataDictionary()
dd._survey = survey
Expand Down

0 comments on commit 9ba9165

Please sign in to comment.