From 5999f13142297de03ce247e8efc5c1d28ef0c270 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 12 Jan 2021 10:21:20 +0100 Subject: [PATCH] fix boolean arg parse --- src/yunohost/app.py | 4 ++-- .../tests/test_apps_arguments_parsing.py | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 8f75889c5..007ee2d37 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -2537,10 +2537,10 @@ class BooleanArgumentParser(YunoHostArgumentFormatParser): if isinstance(question.value, bool): return 1 if question.value else 0 - if str(question.value).lower() in ["1", "yes", "y"]: + if str(question.value).lower() in ["1", "yes", "y", "true"]: return 1 - if str(question.value).lower() in ["0", "no", "n"]: + if str(question.value).lower() in ["0", "no", "n", "false"]: return 0 raise YunohostError('app_argument_choice_invalid', name=question.name, diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 88c235252..ff5d1d15d 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -616,6 +616,18 @@ def test_parse_args_in_yunohost_format_boolean_all_yes(): _parse_args_in_yunohost_format({"some_boolean": True}, questions) == expected_result ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "True"}, questions) == + expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "TRUE"}, questions) == + expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "true"}, questions) == + expected_result + ) def test_parse_args_in_yunohost_format_boolean_all_no(): @@ -653,6 +665,18 @@ def test_parse_args_in_yunohost_format_boolean_all_no(): _parse_args_in_yunohost_format({"some_boolean": False}, questions) == expected_result ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "False"}, questions) == + expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "FALSE"}, questions) == + expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "false"}, questions) == + expected_result + ) # XXX apparently boolean are always False (0) by default, I'm not sure what to think about that