-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from XLSForm/issue-54
Allows "value" as an alias for "name"
- Loading branch information
Showing
7 changed files
with
178 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from pyxform_test_case import PyxformTestCase | ||
|
||
|
||
class MissingHeaders(PyxformTestCase): | ||
''' | ||
when survey and choices columns are missing headers, it is helpful to see | ||
an error message that prompts the user to include necessary headers. | ||
''' | ||
def test_missing_survey_headers(self): | ||
self.assertPyxformXform( | ||
md=""" | ||
| survey | | | | ||
| | select_one list | S1 | | ||
""", | ||
errored=True, | ||
error__contains=[ | ||
'missing important column headers', | ||
]) | ||
|
||
def test_missing_choice_headers(self): | ||
self.assertPyxformXform( | ||
md=""" | ||
| survey | | | | | ||
| | type | label | name | | ||
| | select_one list | S1 | s1 | | ||
| choices | | | | | ||
| | list | option a | a | | ||
| | list | option b | b | | ||
""", | ||
errored=True, | ||
error__contains=[ | ||
"has columns 'list name', 'name', and 'label'", | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
from pyxform_test_case import PyxformTestCase | ||
|
||
|
||
class InvalidSurveyColumnsTests(PyxformTestCase): | ||
def test_missing_name(self): | ||
''' | ||
every question needs a name (or alias of name) | ||
''' | ||
self.assertPyxformXform( | ||
name='invalidcols', | ||
ss_structure={'survey': [{'type': 'text', | ||
'label': 'label'}]}, | ||
errored=True, | ||
error__contains=['no name'], | ||
) | ||
|
||
def test_missing_name_but_has_alias_of_name(self): | ||
self.assertPyxformXform( | ||
name='invalidcols', | ||
ss_structure={'survey': [{'value': 'q1', | ||
'type': 'text', | ||
'label': 'label'}]}, | ||
errored=False, | ||
) | ||
|
||
def test_missing_label(self): | ||
self.assertPyxformXform( | ||
name="invalidcols", | ||
ss_structure={'survey': [{'type': 'text', | ||
'name': 'q1'}]}, | ||
errored=True, | ||
error__contains=['no label or hint'], | ||
) | ||
|
||
|
||
class InvalidChoiceSheetColumnsTests(PyxformTestCase): | ||
def _simple_choice_ss(self, choice_sheet=[]): | ||
return {'survey': [{'type': 'select_one l1', | ||
'name': 'l1choice', | ||
'label': 'select one from list l1'}], | ||
'choices': choice_sheet} | ||
|
||
def test_valid_choices_sheet_passes(self): | ||
self.assertPyxformXform( | ||
name='valid_choices', | ||
ss_structure=self._simple_choice_ss([ | ||
{'list_name': 'l1', | ||
'name': 'c1', | ||
'label': 'choice 1'}, | ||
{'list_name': 'l1', | ||
'name': 'c2', | ||
'label': 'choice 2'}]), | ||
errored=False, | ||
) | ||
|
||
def test_invalid_choices_sheet_fails(self): | ||
self.assertPyxformXform( | ||
name='missing_name', | ||
ss_structure=self._simple_choice_ss([ | ||
{'list_name': 'l1', | ||
'label': 'choice 1'}, | ||
{'list_name': 'l1', | ||
'label': 'choice 2'}, | ||
]), | ||
errored=True, | ||
error__contains=['option with no name'], | ||
) | ||
|
||
def test_missing_list_name(self): | ||
self.assertPyxformXform( | ||
name='missing_list_name', | ||
ss_structure=self._simple_choice_ss([ | ||
{'bad_column': 'l1', | ||
'name': 'l1c1', | ||
'label': 'choice 1'}, | ||
{'bad_column': 'l1', | ||
'name': 'l1c1', | ||
'label': 'choice 2'}, | ||
]), | ||
debug=True, | ||
errored=True, | ||
# some basic keywords that should be in the error: | ||
error__contains=[ | ||
'choices', | ||
'name', | ||
'list name', | ||
]) | ||
|
||
|
||
class AliasesTests(PyxformTestCase): | ||
def test_value_and_name(self): | ||
''' | ||
confirm that both 'name' and 'value' both compile to xforms with the | ||
correct output. | ||
''' | ||
for name_alias in ['name', 'value']: | ||
self.assertPyxformXform( | ||
name="aliases", | ||
md=""" | ||
| survey | | | | | ||
| | type | %(name_alias)s | label | | ||
| | text | q1 | Question 1 | | ||
""" % ({ | ||
u'name_alias': name_alias | ||
}), | ||
instance__contains=[ | ||
'<q1/>', | ||
], | ||
model__contains=[ | ||
'<bind nodeset="/aliases/q1" type="string"/>', | ||
], | ||
xml__contains=[ | ||
'<input ref="/aliases/q1">', | ||
'<label>Question 1</label>', | ||
'</input>', | ||
]) | ||
''' # uncomment when re-implemented | ||
# TODO: test that this fails for the correct reason | ||
def test_conflicting_aliased_values_raises_error(self): | ||
# example: | ||
# an xlsform has {"name": "q_name", "value": "q_value"} | ||
# should not compile because "name" and "value" columns are aliases | ||
self.assertPyxformXform( | ||
# debug=True, | ||
name="aliases", | ||
md=""" | ||
| survey | | | | | | ||
| | type | name | value | label | | ||
| | text | q_name | q_value | Question 1 | | ||
""", | ||
errored=True, | ||
) | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters