fix boolean arg parse

This commit is contained in:
Kay0u 2021-01-12 10:21:20 +01:00
parent 1d2b1d9601
commit 5999f13142
No known key found for this signature in database
GPG key ID: AAFEEB16CFA2AE2D
2 changed files with 26 additions and 2 deletions

View file

@ -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,

View file

@ -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