feat: allow append list options

This commit is contained in:
2024-10-17 18:45:38 +03:00
parent f48993ccd5
commit 7c6c24a46d
10 changed files with 243 additions and 28 deletions

View File

@ -1,4 +1,6 @@
import configparser
from io import StringIO
import pytest
from pathlib import Path
@ -180,6 +182,32 @@ def test_getlist_unmatched_quote(configuration: Configuration) -> None:
configuration.getlist("build", "test_list")
def test_getlist_append() -> None:
"""
must correctly append list values
"""
configuration = Configuration()
configuration._read(
StringIO("""
[section]
list1[] = value1
list1[] = value2
list2[] = value3
list2[] =
list2[] = value4
list2[] = value5
list3[] = value6
list3 = value7
list3[] = value8
"""), "io")
assert configuration.getlist("section", "list1") == ["value1", "value2"]
assert configuration.getlist("section", "list2") == ["value4", "value5"]
assert configuration.getlist("section", "list3") == ["value7", "value8"]
def test_getpath_absolute_to_absolute(configuration: Configuration) -> None:
"""
must not change path for absolute path in settings

View File

@ -0,0 +1,54 @@
import pytest
from ahriman.core.configuration.configuration_multi_dict import ConfigurationMultiDict
from ahriman.core.exceptions import OptionError
def test_setitem_non_list() -> None:
"""
must insert not list correctly
"""
instance = ConfigurationMultiDict()
instance["key"] = "value"
assert instance["key"] == "value"
def test_setitem_remove() -> None:
"""
must remove key
"""
instance = ConfigurationMultiDict()
instance["key"] = "value"
instance["key"] = [""]
assert "key" not in instance
def test_setitem_array() -> None:
"""
must set array correctly
"""
instance = ConfigurationMultiDict()
instance["key[]"] = ["value1"]
instance["key[]"] = ["value2"]
assert instance["key"] == ["value1 value2"]
def test_setitem_array_exception() -> None:
"""
must raise exception if the current value is not a single value array
"""
instance = ConfigurationMultiDict()
instance["key[]"] = ["value1", "value2"]
with pytest.raises(OptionError):
instance["key[]"] = ["value3"]
def test_setitem_exception() -> None:
"""
must raise exception on invalid key
"""
instance = ConfigurationMultiDict()
with pytest.raises(OptionError):
instance["prefix[]suffix"] = "value"

View File

@ -60,7 +60,7 @@ target = console
[email]
host = 127.0.0.1
link_path =
link_path = http://example.com
no_empty_report = no
port = 587
receivers = mail@example.com
@ -72,9 +72,8 @@ templates = ../web/templates
use_utf = yes
[html]
path =
homepage =
link_path =
link_path = http://example.com
path = local/path
template = repo-index.jinja2
templates = ../web/templates
@ -82,17 +81,15 @@ templates = ../web/templates
manual = yes
[rss]
path =
homepage =
link_path =
link_path = http://example.com
path = local/path
template = rss.jinja2
templates = ../web/templates
[telegram]
api_key = apikey
api_key = api_key
chat_id = @ahrimantestchat
homepage =
link_path =
link_path = http://example.com
template = telegram-index.jinja2
templates = ../web/templates
@ -101,20 +98,20 @@ target =
[rsync]
command = rsync --archive --verbose --compress --partial --delete
remote =
remote = remote@example.com
[disabled]
[customs3]
type = s3
access_key =
access_key = access_key
bucket = bucket
region = eu-central-1
secret_key =
secret_key = secret_key
[github:x86_64]
owner = arcan1s
password =
password = pa55w0rd
repository = ahriman
username = arcan1s