OpenSlides/tests/unit/config/test_api.py

36 lines
1.2 KiB
Python
Raw Normal View History

2015-06-19 09:08:36 +02:00
from unittest import TestCase
from unittest.mock import patch
2017-08-22 14:17:20 +02:00
from openslides.core.config import ConfigVariable, config
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.assertIn(
2019-01-06 16:22:33 +01:00
"default_value",
2015-06-19 09:08:36 +02:00
config_variable.data,
2019-01-06 16:22:33 +01:00
"Config_varialbe.data should have a key 'default_value'",
)
2015-06-19 09:08:36 +02:00
self.assertEqual(
2019-01-06 16:22:33 +01:00
config_variable.data["default_value"],
"test_default_value",
2015-06-19 09:08:36 +02:00
"The value of config_variable.data['default_value'] 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"
)