From 609e311e3fe87ef4a6a4263a3c9beb848d0fbc36 Mon Sep 17 00:00:00 2001 From: Autio Date: Tue, 29 Sep 2026 12:01:26 +0100 Subject: [PATCH] chg: accept standard true/false aliases for auto_send and auto_delete Closes #767 Co-Authored-By: Claude Opus 5.5 (1M context) --- pyxform/xls2json.py | 7 ++++ tests/test_settings_auto_send_delete.py | 44 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/pyxform/xls2json.py b/pyxform/xls2json.py index 093c6d40..55d7e920 100644 --- a/pyxform/xls2json.py +++ b/pyxform/xls2json.py @@ -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( diff --git a/tests/test_settings_auto_send_delete.py b/tests/test_settings_auto_send_delete.py index 58e8e13c..d242ddf4 100644 --- a/tests/test_settings_auto_send_delete.py +++ b/tests/test_settings_auto_send_delete.py @@ -83,3 +83,47 @@ def test_settings_with_submission_url_generates_method_attribute(self): '' ], ) + + 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' + ] + """ + ], + )