Skip to content
Closed
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
7 changes: 7 additions & 0 deletions pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ def workbook_to_json(
settings[constants.CLIENT_EDITABLE] = aliases.yes_no.get(
settings.get(constants.CLIENT_EDITABLE, "no"), False
)
# auto_send and auto_delete are tri-state: unset, "true", or "false", since an
# explicit "false" overrides the client's own setting. Unrecognised values are kept.
for key in (constants.AUTO_SEND, constants.AUTO_DELETE):
if key in settings:
value = aliases.yes_no.get(settings[key])
if value is not None:
settings[key] = "true" if value else "false"

# Here we create our json dict root with default settings:
id_string = settings.get(
Expand Down
44 changes: 44 additions & 0 deletions tests/test_settings_auto_send_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,47 @@ def test_settings_with_submission_url_generates_method_attribute(self):
'<submission action="https://odk.ona.io/random_person/submission" method="post" orx:auto-send="false"/>'
],
)

def test_settings_auto_send_delete__true_aliases(self):
"""Should output "true" for any alias of true."""
for alias in ("yes", "Yes", "YES", "true", "True", "TRUE", "true()"):
with self.subTest(alias=alias):
self.assertPyxformXform(
md=f"""
| settings |
| | auto_delete | auto_send |
| | {alias} | {alias} |
| survey |
| | type | name | label |
| | text | q1 | Q1 |
""",
xml__xpath_match=[
"""
/h:html/h:head/x:model/x:submission[
@orx:auto-send='true' and @orx:auto-delete='true'
]
"""
],
)

def test_settings_auto_send_delete__false_aliases(self):
"""Should output "false" for any alias of false, since it overrides the client."""
for alias in ("no", "No", "NO", "false", "False", "FALSE", "false()"):
with self.subTest(alias=alias):
self.assertPyxformXform(
md=f"""
| settings |
| | auto_delete | auto_send |
| | {alias} | {alias} |
| survey |
| | type | name | label |
| | text | q1 | Q1 |
""",
xml__xpath_match=[
"""
/h:html/h:head/x:model/x:submission[
@orx:auto-send='false' and @orx:auto-delete='false'
]
"""
],
)