OpenSlides/server/tests/unit/config/test_api.py

37 lines
1.3 KiB
Python
Raw Normal View History

from typing import cast
2015-06-19 09:08:36 +02:00
from unittest import TestCase
from unittest.mock import patch
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
self.assertTrue(
"defaultValue" in cast(ConfigVariableDict, config_variable.data)
2019-01-06 16:22:33 +01:00
)
data = config_variable.data
self.assertTrue(data)
2015-06-19 09:08:36 +02:00
self.assertEqual(
cast(ConfigVariableDict, config_variable.data)["defaultValue"],
2019-01-06 16:22:33 +01:00
"test_default_value",
"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")
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"
)