mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Get rid of example settings, only keep them for tests
This commit is contained in:
parent
b10393a5e1
commit
083776bc4a
3 changed files with 21 additions and 17 deletions
|
@ -312,10 +312,6 @@
|
||||||
"global_settings_key_doesnt_exists": "The key '{settings_key:s}' does not exist in the global settings, you can see all the available keys by running 'yunohost settings list'",
|
"global_settings_key_doesnt_exists": "The key '{settings_key:s}' does not exist in the global settings, you can see all the available keys by running 'yunohost settings list'",
|
||||||
"global_settings_reset_success": "Previous settings now backed up to {path:s}",
|
"global_settings_reset_success": "Previous settings now backed up to {path:s}",
|
||||||
"global_settings_setting_pop3_enabled": "Enable the POP3 protocol for the mail server",
|
"global_settings_setting_pop3_enabled": "Enable the POP3 protocol for the mail server",
|
||||||
"global_settings_setting_example_bool": "Example boolean option",
|
|
||||||
"global_settings_setting_example_enum": "Example enum option",
|
|
||||||
"global_settings_setting_example_int": "Example int option",
|
|
||||||
"global_settings_setting_example_string": "Example string option",
|
|
||||||
"global_settings_setting_security_nginx_compatibility": "Compatibility vs. security tradeoff for the web server NGINX. Affects the ciphers (and other security-related aspects)",
|
"global_settings_setting_security_nginx_compatibility": "Compatibility vs. security tradeoff for the web server NGINX. Affects the ciphers (and other security-related aspects)",
|
||||||
"global_settings_setting_security_password_admin_strength": "Admin password strength",
|
"global_settings_setting_security_password_admin_strength": "Admin password strength",
|
||||||
"global_settings_setting_security_password_user_strength": "User password strength",
|
"global_settings_setting_security_password_user_strength": "User password strength",
|
||||||
|
|
|
@ -53,15 +53,11 @@ def is_boolean(value):
|
||||||
# * enum (in the form of a python list)
|
# * enum (in the form of a python list)
|
||||||
|
|
||||||
DEFAULTS = OrderedDict([
|
DEFAULTS = OrderedDict([
|
||||||
("example.bool", {"type": "bool", "default": True}),
|
|
||||||
("example.int", {"type": "int", "default": 42}),
|
|
||||||
("example.string", {"type": "string", "default": "yolo swag"}),
|
|
||||||
("example.enum", {"type": "enum", "default": "a", "choices": ["a", "b", "c"]}),
|
|
||||||
|
|
||||||
# Password Validation
|
# Password Validation
|
||||||
# -1 disabled, 0 alert if listed, 1 8-letter, 2 normal, 3 strong, 4 strongest
|
# -1 disabled, 0 alert if listed, 1 8-letter, 2 normal, 3 strong, 4 strongest
|
||||||
("security.password.admin.strength", {"type": "int", "default": 1}),
|
("security.password.admin.strength", {"type": "int", "default": 1}),
|
||||||
("security.password.user.strength", {"type": "int", "default": 1}),
|
("security.password.user.strength", {"type": "int", "default": 1}),
|
||||||
|
|
||||||
("service.ssh.allow_deprecated_dsa_hostkey", {"type": "bool", "default": False}),
|
("service.ssh.allow_deprecated_dsa_hostkey", {"type": "bool", "default": False}),
|
||||||
("security.ssh.compatibility", {"type": "enum", "default": "modern",
|
("security.ssh.compatibility", {"type": "enum", "default": "modern",
|
||||||
"choices": ["intermediate", "modern"]}),
|
"choices": ["intermediate", "modern"]}),
|
||||||
|
@ -69,6 +65,7 @@ DEFAULTS = OrderedDict([
|
||||||
"choices": ["intermediate", "modern"]}),
|
"choices": ["intermediate", "modern"]}),
|
||||||
("security.postfix.compatibility", {"type": "enum", "default": "intermediate",
|
("security.postfix.compatibility", {"type": "enum", "default": "intermediate",
|
||||||
"choices": ["intermediate", "modern"]}),
|
"choices": ["intermediate", "modern"]}),
|
||||||
|
|
||||||
("pop3.enabled", {"type": "bool", "default": False}),
|
("pop3.enabled", {"type": "bool", "default": False}),
|
||||||
("smtp.allow_ipv6", {"type": "bool", "default": True}),
|
("smtp.allow_ipv6", {"type": "bool", "default": True}),
|
||||||
("backup.compress_tar_archives", {"type": "bool", "default": False}),
|
("backup.compress_tar_archives", {"type": "bool", "default": False}),
|
||||||
|
@ -209,12 +206,19 @@ def settings_reset_all():
|
||||||
|
|
||||||
|
|
||||||
def _get_settings():
|
def _get_settings():
|
||||||
|
|
||||||
|
def get_setting_description(key):
|
||||||
|
if key.startswith("example"):
|
||||||
|
# (This is for dummy stuff used during unit tests)
|
||||||
|
return "Dummy %s setting" % key.split(".")[-1]
|
||||||
|
return m18n.n("global_settings_setting_%s" % key.replace(".", "_"))
|
||||||
|
|
||||||
settings = {}
|
settings = {}
|
||||||
|
|
||||||
for key, value in DEFAULTS.copy().items():
|
for key, value in DEFAULTS.copy().items():
|
||||||
settings[key] = value
|
settings[key] = value
|
||||||
settings[key]["value"] = value["default"]
|
settings[key]["value"] = value["default"]
|
||||||
settings[key]["description"] = m18n.n("global_settings_setting_%s" % key.replace(".", "_"))
|
settings[key]["description"] = get_setting_description(key)
|
||||||
|
|
||||||
if not os.path.exists(SETTINGS_PATH):
|
if not os.path.exists(SETTINGS_PATH):
|
||||||
return settings
|
return settings
|
||||||
|
@ -243,7 +247,7 @@ def _get_settings():
|
||||||
for key, value in local_settings.items():
|
for key, value in local_settings.items():
|
||||||
if key in settings:
|
if key in settings:
|
||||||
settings[key] = value
|
settings[key] = value
|
||||||
settings[key]["description"] = m18n.n("global_settings_setting_%s" % key.replace(".", "_"))
|
settings[key]["description"] = get_setting_description(key)
|
||||||
else:
|
else:
|
||||||
logger.warning(m18n.n('global_settings_unknown_setting_from_settings_file',
|
logger.warning(m18n.n('global_settings_unknown_setting_from_settings_file',
|
||||||
setting_key=key))
|
setting_key=key))
|
||||||
|
|
|
@ -6,8 +6,12 @@ from yunohost.utils.error import YunohostError
|
||||||
|
|
||||||
from yunohost.settings import settings_get, settings_list, _get_settings, \
|
from yunohost.settings import settings_get, settings_list, _get_settings, \
|
||||||
settings_set, settings_reset, settings_reset_all, \
|
settings_set, settings_reset, settings_reset_all, \
|
||||||
SETTINGS_PATH_OTHER_LOCATION, SETTINGS_PATH
|
SETTINGS_PATH_OTHER_LOCATION, SETTINGS_PATH, DEFAULTS
|
||||||
|
|
||||||
|
DEFAULTS["example.bool"] = {"type": "bool", "default": True}
|
||||||
|
DEFAULTS["example.int"] = {"type": "int", "default": 42}
|
||||||
|
DEFAULTS["example.string"] = {"type": "string", "default": "yolo swag"}
|
||||||
|
DEFAULTS["example.enum"] = {"type": "enum", "default": "a", "choices": ["a", "b", "c"]}
|
||||||
|
|
||||||
def setup_function(function):
|
def setup_function(function):
|
||||||
os.system("mv /etc/yunohost/settings.json /etc/yunohost/settings.json.saved")
|
os.system("mv /etc/yunohost/settings.json /etc/yunohost/settings.json.saved")
|
||||||
|
@ -22,7 +26,7 @@ def test_settings_get_bool():
|
||||||
|
|
||||||
|
|
||||||
def test_settings_get_full_bool():
|
def test_settings_get_full_bool():
|
||||||
assert settings_get("example.bool", True) == {"type": "bool", "value": True, "default": True, "description": "Example boolean option"}
|
assert settings_get("example.bool", True) == {"type": "bool", "value": True, "default": True, "description": "Dummy bool setting"}
|
||||||
|
|
||||||
|
|
||||||
def test_settings_get_int():
|
def test_settings_get_int():
|
||||||
|
@ -30,7 +34,7 @@ def test_settings_get_int():
|
||||||
|
|
||||||
|
|
||||||
def test_settings_get_full_int():
|
def test_settings_get_full_int():
|
||||||
assert settings_get("example.int", True) == {"type": "int", "value": 42, "default": 42, "description": "Example int option"}
|
assert settings_get("example.int", True) == {"type": "int", "value": 42, "default": 42, "description": "Dummy int setting"}
|
||||||
|
|
||||||
|
|
||||||
def test_settings_get_string():
|
def test_settings_get_string():
|
||||||
|
@ -38,7 +42,7 @@ def test_settings_get_string():
|
||||||
|
|
||||||
|
|
||||||
def test_settings_get_full_string():
|
def test_settings_get_full_string():
|
||||||
assert settings_get("example.string", True) == {"type": "string", "value": "yolo swag", "default": "yolo swag", "description": "Example string option"}
|
assert settings_get("example.string", True) == {"type": "string", "value": "yolo swag", "default": "yolo swag", "description": "Dummy string setting"}
|
||||||
|
|
||||||
|
|
||||||
def test_settings_get_enum():
|
def test_settings_get_enum():
|
||||||
|
@ -46,7 +50,7 @@ def test_settings_get_enum():
|
||||||
|
|
||||||
|
|
||||||
def test_settings_get_full_enum():
|
def test_settings_get_full_enum():
|
||||||
assert settings_get("example.enum", True) == {"type": "enum", "value": "a", "default": "a", "description": "Example enum option", "choices": ["a", "b", "c"]}
|
assert settings_get("example.enum", True) == {"type": "enum", "value": "a", "default": "a", "description": "Dummy enum setting", "choices": ["a", "b", "c"]}
|
||||||
|
|
||||||
|
|
||||||
def test_settings_get_doesnt_exists():
|
def test_settings_get_doesnt_exists():
|
||||||
|
@ -114,7 +118,7 @@ def test_settings_set_bad_value_enum():
|
||||||
|
|
||||||
def test_settings_list_modified():
|
def test_settings_list_modified():
|
||||||
settings_set("example.int", 21)
|
settings_set("example.int", 21)
|
||||||
assert settings_list()["example.int"] == {'default': 42, 'description': 'Example int option', 'type': 'int', 'value': 21}
|
assert settings_list()["example.int"] == {'default': 42, 'description': 'Dummy int setting', 'type': 'int', 'value': 21}
|
||||||
|
|
||||||
|
|
||||||
def test_reset():
|
def test_reset():
|
||||||
|
|
Loading…
Add table
Reference in a new issue