config: readd value has been initialized + change test removed value from settings since boolean has a native default value

This commit is contained in:
axolotle 2023-04-19 14:37:49 +02:00
parent f087a6b967
commit 73b795be1d
2 changed files with 13 additions and 2 deletions

View file

@ -125,9 +125,9 @@ def test_app_config_get_nonexistentstuff(config_app):
with pytest.raises(YunohostValidationError):
app_config_get(config_app, "main.components.nonexistent")
app_setting(config_app, "boolean", delete=True)
app_setting(config_app, "number", delete=True)
with pytest.raises(YunohostError):
app_config_get(config_app, "main.components.boolean")
app_config_get(config_app, "main.components.number")
def test_app_config_regular_setting(config_app):

View file

@ -601,6 +601,17 @@ class ConfigPanel:
for _, section, option in config.iter_children():
value = data = raw_settings.get(option.id, getattr(option, "default", None))
if isinstance(option, BaseInputOption) and option.id not in raw_settings:
if option.default is not None:
value = option.default
elif option.type is OptionType.file or option.bind == "null":
continue
else:
raise YunohostError(
f"Config panel question '{option.id}' should be initialized with a value during install or upgrade.",
raw_msg=True,
)
if isinstance(data, dict):
# Settings data if gathered from bash "ynh_app_config_show"
# may be a custom getter that returns a dict with `value` or `current_value`