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

Issue 471 deprecate unused device id methods #473

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyxform/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@

# The ODK XForms version that generated forms comply to
CURRENT_XFORMS_VERSION = "1.0.0"

DEPRECATED_DEVICE_ID_METADATA_FIELDS = ["subscriberid", "simserial"]
15 changes: 0 additions & 15 deletions pyxform/tests/example_xls/spec_test_expected_output.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@
<text id="/xlsform_spec_test/everything/some_text:label">
<value>-</value>
</text>
<text id="/xlsform_spec_test/everything/simserial_test_output:label">
<value>-</value>
</text>
<text id="/xlsform_spec_test/everything/number_label:label">
<value>-</value>
</text>
Expand Down Expand Up @@ -373,9 +370,6 @@
<text id="/xlsform_spec_test/everything/start_test_output:label">
<value>-</value>
</text>
<text id="/xlsform_spec_test/everything/simserial_test_output:label">
<value>-</value>
</text>
<text id="/xlsform_spec_test/everything/repeat_test/compact-test:label">
<value>-</value>
</text>
Expand Down Expand Up @@ -556,8 +550,6 @@
</text>
<text id="/xlsform_spec_test/everything/start_test_output:label">
<value>start test output: <output value="/xlsform_spec_test/everything/start"/></value> </text>
<text id="/xlsform_spec_test/everything/simserial_test_output:label">
<value>simserial_test_output: <output value="/xlsform_spec_test/everything/simserial"/></value> </text>
<text id="/xlsform_spec_test/everything/repeat_test/compact-test:label">
<value>compact-test</value>
</text>
Expand Down Expand Up @@ -612,8 +604,6 @@
<today_test_output/>
<deviceid/>
<deviceid_test_output/>
<simserial/>
<simserial_test_output/>
<phonenumber/>
<phonenumber_test_output/>
<_1/>
Expand Down Expand Up @@ -663,8 +653,6 @@
<bind nodeset="/xlsform_spec_test/everything/today_test_output" readonly="true()" type="string"/>
<bind jr:preload="property" jr:preloadParams="deviceid" nodeset="/xlsform_spec_test/everything/deviceid" type="string"/>
<bind nodeset="/xlsform_spec_test/everything/deviceid_test_output" readonly="true()" type="string"/>
<bind jr:preload="property" jr:preloadParams="simserial" nodeset="/xlsform_spec_test/everything/simserial" type="string"/>
<bind nodeset="/xlsform_spec_test/everything/simserial_test_output" readonly="true()" type="string"/>
<bind jr:preload="property" jr:preloadParams="phonenumber" nodeset="/xlsform_spec_test/everything/phonenumber" type="string"/>
<bind nodeset="/xlsform_spec_test/everything/phonenumber_test_output" readonly="true()" type="string"/>
<bind nodeset="/xlsform_spec_test/everything/_1" type="string"/>
Expand Down Expand Up @@ -881,9 +869,6 @@
<input ref="/xlsform_spec_test/everything/deviceid_test_output">
<label ref="jr:itext('/xlsform_spec_test/everything/deviceid_test_output:label')"/>
</input>
<input ref="/xlsform_spec_test/everything/simserial_test_output">
<label ref="jr:itext('/xlsform_spec_test/everything/simserial_test_output:label')"/>
</input>
<input ref="/xlsform_spec_test/everything/phonenumber_test_output">
<label ref="jr:itext('/xlsform_spec_test/everything/phonenumber_test_output:label')"/>
</input>
Expand Down
Binary file modified pyxform/tests/example_xls/warnings.xls
Binary file not shown.
Binary file modified pyxform/tests/example_xls/xlsform_spec_test.xlsx
Binary file not shown.
15 changes: 0 additions & 15 deletions pyxform/tests/test_expected_output/xlsform_spec_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@
<text id="/xlsform_spec_test/everything/start_test_output:label">
<value>-</value>
</text>
<text id="/xlsform_spec_test/everything/simserial_test_output:label">
<value>-</value>
</text>
<text id="/xlsform_spec_test/everything/repeat_test/labeled_select_group/list-nolabel-test:label">
<value>-</value>
</text>
Expand Down Expand Up @@ -392,9 +389,6 @@
<text id="/xlsform_spec_test/everything/start_test_output:label">
<value>-</value>
</text>
<text id="/xlsform_spec_test/everything/simserial_test_output:label">
<value>-</value>
</text>
<text id="/xlsform_spec_test/everything/repeat_test/compact-test:label">
<value>-</value>
</text>
Expand Down Expand Up @@ -576,8 +570,6 @@
</text>
<text id="/xlsform_spec_test/everything/start_test_output:label">
<value>start test output: <output value=" /xlsform_spec_test/everything/start "/></value></text>
<text id="/xlsform_spec_test/everything/simserial_test_output:label">
<value>simserial_test_output: <output value=" /xlsform_spec_test/everything/simserial "/></value></text>
<text id="/xlsform_spec_test/everything/repeat_test/compact-test:label">
<value>compact-test</value>
</text>
Expand Down Expand Up @@ -653,8 +645,6 @@
<deviceid_test_output/>
<uri_deviceid/>
<uri_deviceid_test_output/>
<simserial/>
<simserial_test_output/>
<phonenumber/>
<phonenumber_test_output/>
<_1/>
Expand Down Expand Up @@ -711,8 +701,6 @@
<bind nodeset="/xlsform_spec_test/everything/deviceid_test_output" readonly="true()" type="string"/>
<bind jr:preload="property" jr:preloadParams="uri:deviceid" nodeset="/xlsform_spec_test/everything/uri_deviceid" type="string"/>
<bind nodeset="/xlsform_spec_test/everything/uri_deviceid_test_output" readonly="true()" type="string"/>
<bind jr:preload="property" jr:preloadParams="simserial" nodeset="/xlsform_spec_test/everything/simserial" type="string"/>
<bind nodeset="/xlsform_spec_test/everything/simserial_test_output" readonly="true()" type="string"/>
<bind jr:preload="property" jr:preloadParams="phonenumber" nodeset="/xlsform_spec_test/everything/phonenumber" type="string"/>
<bind nodeset="/xlsform_spec_test/everything/phonenumber_test_output" readonly="true()" type="string"/>
<bind nodeset="/xlsform_spec_test/everything/_1" type="string"/>
Expand Down Expand Up @@ -929,9 +917,6 @@
<input ref="/xlsform_spec_test/everything/uri_deviceid_test_output">
<label ref="jr:itext('/xlsform_spec_test/everything/uri_deviceid_test_output:label')"/>
</input>
<input ref="/xlsform_spec_test/everything/simserial_test_output">
<label ref="jr:itext('/xlsform_spec_test/everything/simserial_test_output:label')"/>
</input>
<input ref="/xlsform_spec_test/everything/phonenumber_test_output">
<label ref="jr:itext('/xlsform_spec_test/everything/phonenumber_test_output:label')"/>
</input>
Expand Down
83 changes: 83 additions & 0 deletions pyxform/tests_v1/test_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
"""
Test language warnings.
"""
import os
import tempfile

from pyxform.tests_v1.pyxform_test_case import PyxformTestCase


class MetadataTest(PyxformTestCase):
"""
Test metadata and related warnings.
"""

def test_metadata_bindings(self):
self.assertPyxformXform(
KeynesYouDigIt marked this conversation as resolved.
Show resolved Hide resolved
name="metadata",
md="""
| survey | | | |
| | type | name | label |
| | deviceid | deviceid | |
| | phonenumber | phonenumber | |
| | start | start | |
| | end | end | |
| | today | today | |
| | username | username | |
| | email | email | |
""",
xml__contains=[
'jr:preload="property" jr:preloadParams="deviceid"',
'jr:preload="property" jr:preloadParams="phonenumber"',
'jr:preload="timestamp" jr:preloadParams="start"',
'jr:preload="timestamp" jr:preloadParams="end"',
'jr:preload="date" jr:preloadParams="today"',
'jr:preload="property" jr:preloadParams="username"',
'jr:preload="property" jr:preloadParams="email"',
],
)

def test_simserial_deprecation_warning(self):
warnings = []
survey = self.md_to_pyxform_survey(
"""
| survey | | | |
| | type | name | label |
| | simserial | simserial | |
| | note | simserial_test_output | simserial_test_output: ${simserial} |
""",
warnings=warnings,
)
tmp = tempfile.NamedTemporaryFile(suffix=".xml", delete=False)
tmp.close()
survey.print_xform_to_file(tmp.name, warnings=warnings)
self.assertTrue(len(warnings) == 1)
warning_expected = (
"[row : 2] simserial is no longer supported on most devices. "
"Only old versions of Collect on Android versions older than 11 still support it."
)
self.assertEqual(warning_expected, warnings[0])
os.unlink(tmp.name)

def test_subscriber_id_deprecation_warning(self):
warnings = []
survey = self.md_to_pyxform_survey(
"""
| survey | | | |
| | type | name | label |
| | subscriberid | subscriberid | sub id - extra warning generated w/o this |
| | note | subscriberid_test_output | subscriberid_test_output: ${subscriberid} |
""",
warnings=warnings,
)
tmp = tempfile.NamedTemporaryFile(suffix=".xml", delete=False)
tmp.close()
survey.print_xform_to_file(tmp.name, warnings=warnings)
self.assertTrue(len(warnings) == 1)
warning_expected = (
"[row : 2] subscriberid is no longer supported on most devices. "
"Only old versions of Collect on Android versions older than 11 still support it."
)
self.assertEqual(warning_expected, warnings[0])
os.unlink(tmp.name)
12 changes: 11 additions & 1 deletion pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ def workbook_to_json(
survey_meta = []

dynamic_default_warning_added = False

# row by row, validate questions, throwing errors and adding warnings
# where needed.
for row in survey_sheet:
row_number += 1
if stack[-1] is not None:
Expand Down Expand Up @@ -825,7 +828,14 @@ def workbook_to_json(
raise PyXFormError(
row_format_string % row_number + " Missing calculation."
)

if question_type in constants.DEPRECATED_DEVICE_ID_METADATA_FIELDS:
warnings.append(
(row_format_string % row_number)
+ " "
+ question_type
+ " is no longer supported on most devices. "
"Only old versions of Collect on Android versions older than 11 still support it."
)
# Check if the question is actually a setting specified
# on the survey sheet
settings_type = aliases.settings_header.get(question_type)
Expand Down