Skip to content
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

Merged
merged 9 commits into from
Oct 2, 2019

Conversation

nribeka
Copy link
Contributor

@nribeka nribeka commented Sep 23, 2019

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.

@@ -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"):
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

| | type | name | label |
| | text | city | City Name |
""",
name='some-name',
Copy link
Contributor Author

@nribeka nribeka Sep 24, 2019

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

pyxform/xls2json.py Outdated Show resolved Hide resolved
Copy link
Contributor

@lognaturel lognaturel left a 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.

pyxform/xls2json.py Outdated Show resolved Hide resolved
@@ -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"):
Copy link
Contributor

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-io
Copy link

codecov-io commented Sep 24, 2019

Codecov Report

Merging #375 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
pyxform/file_utils.py 89.47% <100%> (ø) ⬆️
pyxform/xls2json.py 77.88% <100%> (-0.07%) ⬇️
pyxform/builder.py 75.4% <100%> (ø) ⬆️
pyxform/xform2json.py 79.87% <0%> (+0.2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a2cfa5...db6ca73. Read the comment docs.

Copy link
Contributor

@lognaturel lognaturel left a 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"))
Copy link
Contributor

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

Copy link
Contributor Author

@nribeka nribeka Sep 27, 2019

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

| | type | name | label |
| | text | city | City Name |
""",
name='some-name',
Copy link
Contributor

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/xls2json.py Outdated Show resolved Hide resolved
| | type | name | label |
| | text | city | City Name |
""",
name='data',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lognaturel,

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>',
            ],
        )

Copy link
Contributor Author

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>

@nribeka nribeka marked this pull request as ready for review September 30, 2019 16:08
ukanga
ukanga previously approved these changes Oct 2, 2019
Copy link
Contributor

@ukanga ukanga left a 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"))
Copy link
Contributor

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.

@ukanga
Copy link
Contributor

ukanga commented Oct 2, 2019

@nribeka If you can fix the black issues, this should be good to merge.

Copy link
Contributor

@lognaturel lognaturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ukanga ukanga merged commit 077972c into XLSForm:master Oct 2, 2019
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 25, 2020
Modify Export Builder tests passing in the new 'default_name' arguement
to PyXForms 'create_survey_from_xls' function. More info:
XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 25, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 26, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 26, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 27, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 27, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 27, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 27, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 27, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 2, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 2, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 2, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 2, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 2, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 3, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 3, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 3, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 3, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 13, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 13, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 27, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 27, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 27, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 27, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 27, 2020
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
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 27, 2020
As of PyXForm v1.0.0 the name of the file is no longer used as the root
node. More Info: XLSForm/pyxform#375
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert files with leading numbers in their name
4 participants