Skip to content

Commit

Permalink
Update error raised when an id_string is invalid
Browse files Browse the repository at this point in the history
Update the error raised when an id_string is invalid. PyXForm now
utilizes the filename as the form_id if it's not explicitly set in the
settings sheet. More Info: XLSForm/pyxform#389
  • Loading branch information
DavisRayM committed Mar 3, 2020
1 parent 7dd63ed commit 7fffc9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 6 additions & 2 deletions onadata/apps/api/tests/viewsets/test_xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,8 +1381,12 @@ def test_publish_invalid_xls_form(self):
response = view(request)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.get('Cache-Control'), None)
error_msg = 'In strict mode, the XForm ID must be a valid slug'\
' and contain no spaces.'
error_msg = ('In strict mode, the XForm ID must be '
'a valid slug and contain no spaces.'
' Please ensure that you have set an'
' id_string in the settings sheet or '
'have modified the filename to not '
'contain any spaces.')
self.assertEqual(response.data.get('text'), error_msg)

path = os.path.join(
Expand Down
8 changes: 6 additions & 2 deletions onadata/apps/logger/models/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def check_version_set(survey):


def _expand_select_all_that_apply(d, key, e):
if e and e.bind.get(u"type") == u"select":
if e and e.bind.get(u"type") == u"string"\
and e.type == MULTIPLE_SELECT_TYPE:
options_selected = d[key].split()
for child in e.children:
new_key = child.get_abbreviated_xpath()
Expand Down Expand Up @@ -864,7 +865,10 @@ def save(self, *args, **kwargs):
not re.search(r"^[\w-]+$", self.id_string):
raise XLSFormError(
_(u'In strict mode, the XForm ID must be a '
'valid slug and contain no spaces.'))
'valid slug and contain no spaces. Please ensure'
' that you have set an id_string in the settings sheet '
'or have modified the filename to not contain'
' any spaces.'))

if not self.sms_id_string and (update_fields is None or
'id_string' in update_fields):
Expand Down
10 changes: 5 additions & 5 deletions onadata/apps/main/tests/test_form_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ def test_spaced_xlsform(self):
self.xform.save()
xls_path = os.path.join(self.this_directory, "fixtures",
"transportation", "tutorial .xls")
msg = ("The name 'tutorial ' is an invalid XML tag, it contains an"
" invalid character ' '. Names must begin with a letter, colon,"
" or underscore, subsequent characters can include numbers, "
"dashes, and periods")
msg = ("In strict mode, the XForm ID must be a valid slug"
" and contain no spaces. Please ensure that you "
"have set an id_string in the settings sheet or"
" have modified the filename to not contain any spaces.")
self.assertRaisesMessage(
PyXFormError, msg, self._publish_xls_file, xls_path)
XLSFormError, msg, self._publish_xls_file, xls_path)
self.assertEquals(XForm.objects.count(), count)

def test_choice_duplicate_error(self):
Expand Down

0 comments on commit 7fffc9b

Please sign in to comment.