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 4 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"]
2 changes: 1 addition & 1 deletion pyxform/tests/xlsform_spec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def runTest(self):
path_to_excel_file, default_name="warnings", warnings=warnings
)
self.assertEquals(
len(warnings), 21, "Found " + str(len(warnings)) + " warnings"
len(warnings), 22, "Found " + str(len(warnings)) + " warnings"
KeynesYouDigIt marked this conversation as resolved.
Show resolved Hide resolved
)


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 is not lable optional I guess |
KeynesYouDigIt marked this conversation as resolved.
Show resolved Hide resolved
| | 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