#157 #165

Merged
edraft merged 14 commits from #157 into 2023.4 2023-04-11 11:48:49 +02:00
3 changed files with 34 additions and 3 deletions
Showing only changes of commit 106975015e - Show all commits

View File

@ -314,7 +314,7 @@ class Configuration(ConfigurationABC):
for arg in self._argument_types:
call(arg)
def get_configuration(self, search_type: Type[T]) -> Optional[T]:
def get_configuration(self, search_type: T) -> Optional[T]:
if type(search_type) is str:
if search_type == ConfigurationVariableNameEnum.environment.value:
return self._application_environment.environment_name

View File

@ -124,7 +124,7 @@ class ConfigurationABC(ABC):
pass
@abstractmethod
def get_configuration(self, search_type: Type[T]) -> Optional[T]:
def get_configuration(self, search_type: T) -> Optional[T]:
r"""Returns value from configuration by given type
Parameter:

View File

@ -1,8 +1,11 @@
import os
import sys
import unittest
from unittest.mock import Mock, MagicMock
from cpl_core.configuration import Configuration
from cpl_core.configuration import Configuration, ArgumentTypeEnum
from cpl_core.database import DatabaseSettings
from cpl_core.dependency_injection import ServiceProvider, ServiceCollection
from cpl_core.mailing import EMailClientSettings
@ -35,3 +38,31 @@ class ConfigurationTestCase(unittest.TestCase):
self.assertTrue(db.buffered)
self.assertEqual("mysql_native_password", db.auth_plugin)
self.assertIsNone(self._config.get_configuration(EMailClientSettings))
def test_add_config(self):
self.assertIsNone(self._config.get_configuration("Test"))
self._config.add_configuration("Test", "Hello World")
self.assertIsNotNone(self._config.get_configuration("Test"))
self.assertEqual("Hello World", self._config.get_configuration("Test"))
def test_console_argument(self):
sc = ServiceCollection(self._config)
self.assertEqual([], sys.argv[1:])
sys.argv.append("flag")
sys.argv.append("exec")
sys.argv.append("var=test")
self.assertNotEqual([], sys.argv[1:])
self._config.create_console_argument(ArgumentTypeEnum.Flag, "", "flag", [])
mocked_exec = Mock()
mocked_exec.run = MagicMock()
sc.add_transient(mocked_exec)
self._config.create_console_argument(ArgumentTypeEnum.Executable, "", "exec", [], Mock)
self._config.create_console_argument(ArgumentTypeEnum.Variable, "", "var", [], "=")
self.assertIsNone(self._config.get_configuration("var"))
self._config.parse_console_arguments(sc.build_service_provider())
mocked_exec.run.assert_called()
self.assertEqual("test", self._config.get_configuration("var"))
self.assertIn("flag", self._config.additional_arguments)