-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating default form_name to data instead of using filename. #375
Conversation
@@ -78,7 +78,8 @@ def _ss_structure_to_pyxform_survey(ss_structure, kwargs): | |||
# ideally, when all these tests are working, this would be | |||
# refactored as well | |||
survey = create_survey_element_from_dict(imported_survey_json) | |||
survey.name = kwargs.get("name") | |||
if not kwargs.get("skip_name"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to add the skip here because the test will always set the form name. I will never get the data
tag without this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not thrilled by this approach because it means adding a code path only for testing. I'm wondering whether it might be appropriate to have an "old style" test for this particular change since the code that is changed and needs to be exercised is in xls2json.parse_file_to_json
. @ukanga might be best position to answer that. I know he doesn't want to use those old style tests anymore for testing the actual conversion process which I agree strongly with. In this case the goal is to test a change to how the XLS file itself is treated, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the old tests I think will better suited for this case. I needed to add the skipping part because the test will set the form name when I don't pass name field in the markdown setting part.
I can add one old unit test if everyone is OK with that? I was under the impression that we are not touching the old unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree adding a skip_name
is unnecessary here. I don't think we need to change this one at all. We could change all tests that refer to pyxform_autotestname
such that the paths only has /data/field-name-path
. Perhaps we could even default it to data i.e.
survey.name = kwargs.get("name", "data")
We can still use the auto-generated id_string
and title
.
I am very okay with tests in pyxform/tests_v1
being updated to reflect the new default. My main opposition was on changes to fixtures on the old pyxform/tests/
. The one XML fixture here I understand why that was unavoidable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base unit test updated. Reverted some code related to the skipping part. I think this is ready for review again.
pyxform/tests_v1/test_form_name.py
Outdated
| | type | name | label | | ||
| | text | city | City Name | | ||
""", | ||
name='some-name', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the name will override the default data
tag name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it'd be good to do this with a settings sheet to even more closely match the code paths used by real users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting sheet will not work. See my other comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that you can remove the default_name is None
code path. Couple of questions inline.
@@ -78,7 +78,8 @@ def _ss_structure_to_pyxform_survey(ss_structure, kwargs): | |||
# ideally, when all these tests are working, this would be | |||
# refactored as well | |||
survey = create_survey_element_from_dict(imported_survey_json) | |||
survey.name = kwargs.get("name") | |||
if not kwargs.get("skip_name"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not thrilled by this approach because it means adding a code path only for testing. I'm wondering whether it might be appropriate to have an "old style" test for this particular change since the code that is changed and needs to be exercised is in xls2json.parse_file_to_json
. @ukanga might be best position to answer that. I know he doesn't want to use those old style tests anymore for testing the actual conversion process which I agree strongly with. In this case the goal is to test a change to how the XLS file itself is treated, though.
Codecov Report
@@ Coverage Diff @@
## master #375 +/- ##
==========================================
+ Coverage 82.31% 82.33% +0.01%
==========================================
Files 23 23
Lines 3246 3244 -2
Branches 758 757 -1
==========================================
- Hits 2672 2671 -1
- Misses 435 436 +1
+ Partials 139 137 -2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple more questions!
autoname=False, | ||
) | ||
|
||
self.assertEqual(survey.name, unicode("data")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML should be the same as for the test below, right? I think it'd be good to have that be explicitl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added explicit xml comparison. I had to manually set the id_string
and title
because the parent class override them with None
even though I pass it using the settings tab. This part I think have issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
survey = create_survey_element_from_dict(imported_survey_json)
survey.name = kwargs.get("name", "data")
survey.title = kwargs.get("title")
survey.id_string = kwargs.get("id_string")
The code above will create survey object based on the parsed markdown string. But after the survey is created, the next line will overwrite the id_string
and title
with whatever value from the kwargs. So if you don't set the values in the kwargs, it will set it to None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the way to test the default_name="data" is by testing parse_file_to_json()
function directly. The markdown implementation may need to be updated to match the same but it will be fine to handle that outside of this PR.
pyxform/tests_v1/test_form_name.py
Outdated
| | type | name | label | | ||
| | text | city | City Name | | ||
""", | ||
name='some-name', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it'd be good to do this with a settings sheet to even more closely match the code paths used by real users?
pyxform/tests_v1/test_form_name.py
Outdated
| | type | name | label | | ||
| | text | city | City Name | | ||
""", | ||
name='data', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't use the settings tab here too. If I add settings tab in the markdown, it will correctly create the survey using the settings tab. But the next line will override it with the values from the kwargs. And the values in the kwargs is set in _autoname_inputs
.
This unit test will show this issue:
def test_should_use_setting_tab(self):
"""
Test using data as the name of the form which will generate <data />.
"""
self.assertPyxformXform(
md="""
| survey | | | |
| | type | name | label |
| | text | city | City Name |
| settings | | | |
| | id_string | name |
| | some-id | data |
""",
debug=True,
instance__contains=['<data id="some-id">'],
model__contains=['<bind nodeset="/data/city" type="string"/>'],
xml__contains=[
'<input ref="/data/city">',
'<label>City Name</label>',
'</input>',
],
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above test will fail because it will generate this xml file (tag name is not data):
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<h:head>
<h:title>pyxform_autotesttitle</h:title>
<model>
<instance>
<pyxform_autotestname id="pyxform_autotest_id_string">
<city/>
<meta>
<instanceID/>
</meta>
</pyxform_autotestname>
</instance>
<bind nodeset="/pyxform_autotestname/city" type="string"/>
<bind jr:preload="uid" nodeset="/pyxform_autotestname/meta/instanceID" readonly="true()" type="string"/>
</model>
</h:head>
<h:body>
<input ref="/pyxform_autotestname/city">
<label>City Name</label>
</input>
</h:body>
</h:html>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, minimal changes to tests as I would have prefered.
autoname=False, | ||
) | ||
|
||
self.assertEqual(survey.name, unicode("data")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the way to test the default_name="data" is by testing parse_file_to_json()
function directly. The markdown implementation may need to be updated to match the same but it will be fine to handle that outside of this PR.
@nribeka If you can fix the black issues, this should be good to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function. More info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
Modify Export Builder tests passing in the new 'default_name' arguement to PyXForms 'create_survey_from_xls' function and use SELECT_BIND_TYPE and MULTIPLE_SELECT_TYPE common tags instead of static values. More info: XLSForm/pyxform#375
As of PyXForm v1.0.0 the name of the file is no longer used as the root node. More Info: XLSForm/pyxform#375
Fix #130
Defaulting the tag name to 'data' instead of using filename. This will alleviate issue when filename is not valid for tag name.
The tag name can be changed by overriding it using the 'name' column in the setting sheet.
More conversation in #368.