mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 18:29:19 +02:00
make set_config|get_config throw an informative error if you try to get/set non-existing config keys
This commit is contained in:
parent
987dc80033
commit
0bbeb65d94
2 changed files with 16 additions and 0 deletions
|
@ -45,6 +45,12 @@ class Account(object):
|
|||
self._evlogger = EventLogger(self._dc_context, logid)
|
||||
deltachat.set_context_callback(self._dc_context, self._process_event)
|
||||
self._threads = IOThreads(self._dc_context)
|
||||
self._configkeys = self.get_config("sys.config_keys").split()
|
||||
|
||||
def _check_config_key(self, name):
|
||||
if name not in self._configkeys:
|
||||
raise KeyError("{!r} not a valid config key, existing keys: {!r}".format(
|
||||
name, self._configkeys))
|
||||
|
||||
def set_config(self, name, value):
|
||||
""" set configuration values.
|
||||
|
@ -53,6 +59,7 @@ class Account(object):
|
|||
:param value: value to set (unicode)
|
||||
:returns: None
|
||||
"""
|
||||
self._check_config_key(name)
|
||||
name = name.encode("utf8")
|
||||
value = value.encode("utf8")
|
||||
if name == b"addr" and self.is_configured():
|
||||
|
@ -66,6 +73,8 @@ class Account(object):
|
|||
:returns: unicode value
|
||||
:raises: KeyError if no config value was found.
|
||||
"""
|
||||
if name != "sys.config_keys":
|
||||
self._check_config_key(name)
|
||||
name = name.encode("utf8")
|
||||
res = lib.dc_get_config(self._dc_context, name, ffi.NULL)
|
||||
if res == ffi.NULL:
|
||||
|
|
|
@ -13,6 +13,13 @@ class TestOfflineAccount:
|
|||
with pytest.raises(ValueError):
|
||||
ac1.check_is_configured()
|
||||
|
||||
def test_wrong_config_keys(self, acfactory):
|
||||
ac1 = acfactory.get_unconfigured_account()
|
||||
with pytest.raises(KeyError):
|
||||
ac1.set_config("lqkwje", "value")
|
||||
with pytest.raises(KeyError):
|
||||
ac1.get_config("lqkwje")
|
||||
|
||||
def test_selfcontact_if_unconfigured(self, acfactory):
|
||||
ac1 = acfactory.get_unconfigured_account()
|
||||
with pytest.raises(ValueError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue