diff --git a/src/tests/logging/logger.py b/src/tests/logging/logger.py index 8187ec85..4a17331e 100644 --- a/src/tests/logging/logger.py +++ b/src/tests/logging/logger.py @@ -14,28 +14,21 @@ from sh_edraft.time.model import TimeFormatSettings class LoggerTest(unittest.TestCase): def setUp(self): - app_host = ApplicationHost('CPL_Test') - self._app_runtime = app_host.application_runtime - self._config = app_host.configuration + self._app_host = ApplicationHost() + self._config = self._app_host.configuration self._config.create() - self._services: ServiceProvider = cast(ServiceProvider, app_host.services) + self._config.add_environment_variables('PYTHON_') + self._config.add_environment_variables('CPL_') + self._config.add_argument_variables() + self._config.add_json_file(f'appsettings.json') + self._config.add_json_file(f'appsettings.{self._config.environment.environment_name}.json') + self._config.add_json_file(f'appsettings.{self._config.environment.host_name}.json', optional=True) + self._services: ServiceProvider = cast(ServiceProvider, self._app_host.services) self._services.create() - self._log_settings = LoggingSettings() - self._log_settings.from_dict({ - "Path": "logs/", - "Filename": "log_$start_time.log", - "ConsoleLogLevel": "TRACE", - "FileLogLevel": "TRACE" - }) - - self._time_format_settings = TimeFormatSettings() - self._time_format_settings.from_dict({ - "DateFormat": "%Y-%m-%d", - "TimeFormat": "%H:%M:%S", - "DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f", - "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" - }) + self._app_runtime = self._app_host.application_runtime + self._log_settings: LoggingSettings = self._config.get_configuration(LoggingSettings) + self._time_format_settings: TimeFormatSettings = self._config.get_configuration(TimeFormatSettings) def tearDown(self): if os.path.isdir(self._log_settings.path): diff --git a/src/tests/publishing/publisher.py b/src/tests/publishing/publisher.py index 47bc67b2..4e87c8c1 100644 --- a/src/tests/publishing/publisher.py +++ b/src/tests/publishing/publisher.py @@ -2,8 +2,7 @@ import os import shutil import unittest -from sh_edraft.hosting import ApplicationHost, HostingEnvironment -from sh_edraft.hosting.model import EnvironmentName +from sh_edraft.hosting import ApplicationHost from sh_edraft.logging import Logger from sh_edraft.logging.model import LoggingSettings from sh_edraft.publishing import Publisher @@ -16,22 +15,6 @@ from sh_edraft.time.model import TimeFormatSettings class PublisherTest(unittest.TestCase): def _configure(self): - self._log_settings = LoggingSettings() - self._log_settings.from_dict({ - "Path": "logs/", - "Filename": "log_$start_time.log", - "ConsoleLogLevel": "TRACE", - "FileLogLevel": "TRACE" - }) - - self._time_format_settings = TimeFormatSettings() - self._time_format_settings.from_dict({ - "DateFormat": "%Y-%m-%d", - "TimeFormat": "%H:%M:%S", - "DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f", - "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" - }) - self._version = Version(2020, 12, 5).to_dict() templates = [ Template( @@ -76,12 +59,23 @@ class PublisherTest(unittest.TestCase): }) def setUp(self): + self._app_host = ApplicationHost() + self._config = self._app_host.configuration + self._config.create() + self._config.add_environment_variables('PYTHON_') + self._config.add_environment_variables('CPL_') + self._config.add_argument_variables() + self._config.add_json_file(f'appsettings.json') + self._config.add_json_file(f'appsettings.{self._config.environment.environment_name}.json') + self._config.add_json_file(f'appsettings.{self._config.environment.host_name}.json', optional=True) + + self._app_runtime = self._app_host.application_runtime + self._configure() - app_host = ApplicationHost('CPL_Test') - self._app_runtime = app_host.application_runtime - - self._logger = Logger(self._log_settings, self._time_format_settings, app_host.application_runtime) + self._log_settings: LoggingSettings = self._config.get_configuration(LoggingSettings) + self._time_format_settings: TimeFormatSettings = self._config.get_configuration(TimeFormatSettings) + self._logger = Logger(self._log_settings, self._time_format_settings, self._app_host.application_runtime) self._logger.create() def tearDown(self): diff --git a/src/tests/tester.py b/src/tests/tester.py index f5326d02..dfb11e49 100644 --- a/src/tests/tester.py +++ b/src/tests/tester.py @@ -1,7 +1,7 @@ import unittest -# from tests.logging.logger import LoggerTest -# from tests.publishing.publisher import PublisherTest +from tests.logging.logger import LoggerTest +from tests.publishing.publisher import PublisherTest from tests.service_providing.service_provider import ServiceProviderTest @@ -21,17 +21,17 @@ class Tester: self._suite.addTest(ServiceProviderTest('test_get_transient')) # logging - # self._suite.addTest(LoggerTest('test_create')) - # self._suite.addTest(LoggerTest('test_header')) - # self._suite.addTest(LoggerTest('test_trace')) - # self._suite.addTest(LoggerTest('test_debug')) - # self._suite.addTest(LoggerTest('test_info')) - # self._suite.addTest(LoggerTest('test_warn')) - # self._suite.addTest(LoggerTest('test_error')) - # self._suite.addTest(LoggerTest('test_fatal')) + self._suite.addTest(LoggerTest('test_create')) + self._suite.addTest(LoggerTest('test_header')) + self._suite.addTest(LoggerTest('test_trace')) + self._suite.addTest(LoggerTest('test_debug')) + self._suite.addTest(LoggerTest('test_info')) + self._suite.addTest(LoggerTest('test_warn')) + self._suite.addTest(LoggerTest('test_error')) + self._suite.addTest(LoggerTest('test_fatal')) # publishing - # self._suite.addTest(PublisherTest('test_create')) + self._suite.addTest(PublisherTest('test_create')) def start(self): runner = unittest.TextTestRunner()