form: cli retries as variable to be patched in tests

This commit is contained in:
axolotle 2023-04-19 15:07:34 +02:00
parent 98d3b4ffc8
commit 98ec5448f2
2 changed files with 12 additions and 1 deletions

View file

@ -26,6 +26,7 @@ from yunohost.utils.form import (
FileOption,
evaluate_simple_js_expression,
)
from yunohost.utils import form
from yunohost.utils.error import YunohostError, YunohostValidationError
@ -94,6 +95,12 @@ def patch_with_tty():
yield
@pytest.fixture
def patch_cli_retries():
with patch.object(form, "MAX_RETRIES", 0):
yield
# ╭───────────────────────────────────────────────────────╮
# │ ╭─╴╭─╴┌─╴╭╮╷╭─┐┌─╮╶┬╴╭─╮╭─╴ │
# │ ╰─╮│ ├─╴│││├─┤├┬╯ │ │ │╰─╮ │
@ -405,6 +412,7 @@ def _test_intake_may_fail(raw_option, intake, expected_output):
_test_intake(raw_option, intake, expected_output)
@pytest.mark.usefixtures("patch_cli_retries") # To avoid chain error logging
class BaseTest:
raw_option: dict[str, Any] = {}
prefill: dict[Literal["raw_option", "prefill", "intake"], Any]

View file

@ -1464,6 +1464,9 @@ def parse_prefilled_values(
return values
MAX_RETRIES = 4
def prompt_or_validate_form(
options: list[AnyOption],
form: FormModel,
@ -1543,7 +1546,7 @@ def prompt_or_validate_form(
context[option.id] = form[option.id]
except (ValidationError, YunohostValidationError) as e:
# If in interactive cli, re-ask the current question
if i < 4 and interactive:
if i < MAX_RETRIES and interactive:
logger.error(str(e))
value = None
continue