Skip to content

Commit

Permalink
Merge pull request #315 from WinnyTroy/include_check_for_valid_url
Browse files Browse the repository at this point in the history
Check that whitespaces are stripped from urls
  • Loading branch information
ukanga authored Jun 24, 2019
2 parents 5b2fca2 + 306f73c commit e6da309
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Binary file modified pyxform/tests/bug_example_xls/spaces_in_choices_header.xls
Binary file not shown.
16 changes: 16 additions & 0 deletions pyxform/tests/bug_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ def runTest(self):
pyxform.xls2json.parse_file_to_json(path_to_excel_file, warnings=warnings)
self.assertEquals(len(warnings), 3, "Found " + str(len(warnings)) + " warnings")

def test_values_with_spaces_are_cleaned(self):
"""
Test that values with leading and trailing whitespaces are processed.
This test checks that the submission_url provided is cleaned
of leading and trailing whitespaces.
"""
filename = "spaces_in_choices_header.xls"
path_to_excel_file = os.path.join(DIR, "bug_example_xls", filename)
survey_reader = SurveyReader(path_to_excel_file)
result = survey_reader.to_json_dict()

self.assertEqual(
result["submission_url"], "https://odk.ona.io/random_person/submission"
)


class TestChoiceNameAsType(unittest.TestCase):
def test_choice_name_as_type(self):
Expand Down
16 changes: 16 additions & 0 deletions pyxform/tests_v1/test_whitespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ def test_over_trim(self):
""",
xml__contains=['<label><output value=" /issue96/var "/> text </label>'],
)

def test_values_without_whitespaces_are_processed_successfully(self):
md = """
| survey | | | |
| | type | label | name |
| | text | Ignored | Var |
| settings | | | |
| | id_string | public_key | submission_url |
| | tutorial_encrypted | MIIB | https://odk.ona.io/random_person/submission |
"""

survey = self.md_to_pyxform_survey(md_raw=md)
expected = """<submission action="https://odk.ona.io/random_person/submission" base64RsaPublicKey="MIIB" method="form-data-post"/>"""
xml = survey._to_pretty_xml()
self.assertEqual(1, xml.count(expected))
self.assertPyxformXform(md=md, xml__contains=expected, run_odk_validate=True)

0 comments on commit e6da309

Please sign in to comment.