-
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 #76 from XLSForm/support_external_instances
add support for external_instances
- Loading branch information
Showing
5 changed files
with
173 additions
and
5 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
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
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,140 @@ | ||
from pyxform_test_case import PyxformTestCase | ||
|
||
|
||
class ExternalCSVInstancesTest(PyxformTestCase): | ||
def test_external_csv_instances(self): | ||
# re: https://github.com/XLSForm/pyxform/issues/30 | ||
self.assertPyxformXform( | ||
name="ecsv", | ||
md=""" | ||
| survey | | | | | ||
| | type | name | label | | ||
| | select_one_from_file cities.csv | city | City | | ||
| | select_multiple_from_file neighbourhoods.csv | neighbourhoods | Neighbourhoods | | ||
""", # noqa | ||
xml__contains=[ | ||
"""<instance id="cities" src="jr://file-csv/cities.csv"> | ||
<root> | ||
<item> | ||
<name/> | ||
<label/> | ||
</item> | ||
</root> | ||
</instance>""", # noqa | ||
'<select1 ref="/ecsv/city">', | ||
'<itemset nodeset="instance(\'cities\')/root/item">', | ||
"""<instance id="neighbourhoods" src="jr://file-csv/neighbourhoods.csv"> | ||
<root> | ||
<item> | ||
<name/> | ||
<label/> | ||
</item> | ||
</root> | ||
</instance>""", # noqa | ||
'<select ref="/ecsv/neighbourhoods">', | ||
'<itemset nodeset="instance(\'neighbourhoods\')/root/item">', | ||
], | ||
) | ||
|
||
def test_external_csv_instances_w_choice_filter(self): | ||
# re: https://github.com/XLSForm/pyxform/issues/30 | ||
self.assertPyxformXform( | ||
name="ecsv", | ||
md=""" | ||
| survey | | | | | ||
| | type | name | label | choice_filter | | ||
| | select_one_from_file cities.csv | city | City | | | ||
| | select_multiple_from_file neighbourhoods.csv | neighbourhoods | Neighbourhoods | city=${city} | | ||
""", # noqa | ||
xml__contains=[ | ||
"""<instance id="cities" src="jr://file-csv/cities.csv"> | ||
<root> | ||
<item> | ||
<name/> | ||
<label/> | ||
</item> | ||
</root> | ||
</instance>""", # noqa | ||
'<select1 ref="/ecsv/city">', | ||
"""<instance id="neighbourhoods" src="jr://file-csv/neighbourhoods.csv"> | ||
<root> | ||
<item> | ||
<name/> | ||
<label/> | ||
</item> | ||
</root> | ||
</instance>""", # noqa | ||
'<select ref="/ecsv/neighbourhoods">', | ||
'<itemset nodeset="instance(\'neighbourhoods\')/root/item[city= /ecsv/city ]">', | ||
], | ||
) | ||
|
||
|
||
class ExternalXMLInstancesTest(PyxformTestCase): | ||
def test_external_xml_instances(self): | ||
# re: https://github.com/XLSForm/pyxform/issues/30 | ||
self.assertPyxformXform( | ||
name="exml", | ||
md=""" | ||
| survey | | | | | ||
| | type | name | label | | ||
| | select_one_from_file cities.xml | city | City | | ||
| | select_multiple_from_file neighbourhoods.xml | neighbourhoods | Neighbourhoods | | ||
""", # noqa | ||
xml__contains=[ | ||
"""<instance id="cities" src="jr://file-xml/cities.xml"> | ||
<root> | ||
<item> | ||
<name/> | ||
<label/> | ||
</item> | ||
</root> | ||
</instance>""", # noqa | ||
'<select1 ref="/exml/city">', | ||
'<itemset nodeset="instance(\'cities\')/root/item">', | ||
"""<instance id="neighbourhoods" src="jr://file-xml/neighbourhoods.xml"> | ||
<root> | ||
<item> | ||
<name/> | ||
<label/> | ||
</item> | ||
</root> | ||
</instance>""", # noqa | ||
'<select ref="/exml/neighbourhoods">', | ||
'<itemset nodeset="instance(\'neighbourhoods\')/root/item">', | ||
], | ||
) | ||
|
||
|
||
class InvalidExternalFileInstancesTest(PyxformTestCase): | ||
def test_external_other_extension_instances(self): | ||
# re: https://github.com/XLSForm/pyxform/issues/30 | ||
self.assertPyxformXform( | ||
name="epdf", | ||
md=""" | ||
| survey | | | | | ||
| | type | name | label | | ||
| | select_one_from_file cities.pdf | city | City | | ||
| | select_multiple_from_file neighbourhoods.pdf | neighbourhoods | Neighbourhoods | | ||
""", # noqa | ||
errored=True, | ||
error_contains=["should be a choices sheet in this xlsform"], | ||
) | ||
|
||
def test_external_choices_sheet_included_instances(self): | ||
# re: https://github.com/XLSForm/pyxform/issues/30 | ||
self.assertPyxformXform( | ||
name="epdf", | ||
md=""" | ||
| survey | | | | | ||
| | type | name | label | | ||
| | select_one_from_file cities.pdf | city | City | | ||
| | select_multiple_from_file neighbourhoods.pdf | neighbourhoods | Neighbourhoods | | ||
| choices | | ||
| | list name | name | label | | ||
| | fruits | apple | Apple | | ||
""", # noqa | ||
errored=True, | ||
error__contains=["List name not in choices sheet: cities.pdf"], | ||
) |
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