mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
form: cli retries as variable to be patched in tests
This commit is contained in:
parent
98d3b4ffc8
commit
98ec5448f2
2 changed files with 12 additions and 1 deletions
|
@ -26,6 +26,7 @@ from yunohost.utils.form import (
|
||||||
FileOption,
|
FileOption,
|
||||||
evaluate_simple_js_expression,
|
evaluate_simple_js_expression,
|
||||||
)
|
)
|
||||||
|
from yunohost.utils import form
|
||||||
from yunohost.utils.error import YunohostError, YunohostValidationError
|
from yunohost.utils.error import YunohostError, YunohostValidationError
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,6 +95,12 @@ def patch_with_tty():
|
||||||
yield
|
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)
|
_test_intake(raw_option, intake, expected_output)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("patch_cli_retries") # To avoid chain error logging
|
||||||
class BaseTest:
|
class BaseTest:
|
||||||
raw_option: dict[str, Any] = {}
|
raw_option: dict[str, Any] = {}
|
||||||
prefill: dict[Literal["raw_option", "prefill", "intake"], Any]
|
prefill: dict[Literal["raw_option", "prefill", "intake"], Any]
|
||||||
|
|
|
@ -1464,6 +1464,9 @@ def parse_prefilled_values(
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
MAX_RETRIES = 4
|
||||||
|
|
||||||
|
|
||||||
def prompt_or_validate_form(
|
def prompt_or_validate_form(
|
||||||
options: list[AnyOption],
|
options: list[AnyOption],
|
||||||
form: FormModel,
|
form: FormModel,
|
||||||
|
@ -1543,7 +1546,7 @@ def prompt_or_validate_form(
|
||||||
context[option.id] = form[option.id]
|
context[option.id] = form[option.id]
|
||||||
except (ValidationError, YunohostValidationError) as e:
|
except (ValidationError, YunohostValidationError) as e:
|
||||||
# If in interactive cli, re-ask the current question
|
# If in interactive cli, re-ask the current question
|
||||||
if i < 4 and interactive:
|
if i < MAX_RETRIES and interactive:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
value = None
|
value = None
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Reference in a new issue