2019-05-27 18:38:43 +02:00
|
|
|
from typing import cast
|
2015-06-19 09:08:36 +02:00
|
|
|
from unittest import TestCase
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
2019-05-27 18:38:43 +02:00
|
|
|
from openslides.core.config import ConfigVariable, ConfigVariableDict, config
|
2017-08-22 14:17:20 +02:00
|
|
|
from openslides.core.exceptions import ConfigNotFound
|
2015-06-19 09:08:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestConfigVariable(TestCase):
|
2019-01-06 16:22:33 +01:00
|
|
|
@patch("openslides.core.config.config", {"test_variable": None})
|
2015-06-19 09:08:36 +02:00
|
|
|
def test_default_value_in_data(self):
|
|
|
|
"""
|
|
|
|
Tests, that the default_value attribute is in the 'data' property of
|
|
|
|
a ConfigVariable instance.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
config_variable = ConfigVariable("test_variable", "test_default_value")
|
2015-06-19 09:08:36 +02:00
|
|
|
|
2019-05-27 18:38:43 +02:00
|
|
|
self.assertTrue(
|
|
|
|
"defaultValue" in cast(ConfigVariableDict, config_variable.data)
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2019-05-27 18:38:43 +02:00
|
|
|
data = config_variable.data
|
|
|
|
self.assertTrue(data)
|
2015-06-19 09:08:36 +02:00
|
|
|
self.assertEqual(
|
2019-05-27 18:38:43 +02:00
|
|
|
cast(ConfigVariableDict, config_variable.data)["defaultValue"],
|
2019-01-06 16:22:33 +01:00
|
|
|
"test_default_value",
|
2019-05-27 18:38:43 +02:00
|
|
|
"The value of config_variable.data['defaultValue'] should be the same "
|
2019-01-06 16:22:33 +01:00
|
|
|
"as set as second argument of ConfigVariable()",
|
|
|
|
)
|
2017-08-22 14:17:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestConfigHandler(TestCase):
|
2019-01-06 16:22:33 +01:00
|
|
|
@patch("openslides.core.config.ConfigHandler.save_default_values")
|
2018-01-20 15:58:36 +01:00
|
|
|
def test_get_not_found(self, mock_save_default_values):
|
2017-08-22 14:17:20 +02:00
|
|
|
self.assertRaises(
|
2019-01-06 16:22:33 +01:00
|
|
|
ConfigNotFound, config.__getitem__, "key_leehah4Sho4ee7aCohbn"
|
|
|
|
)
|