Fixed testing errors

This commit is contained in:
Sven Heidemann 2020-11-29 16:38:58 +01:00
parent b14446272a
commit fea84418d3
3 changed files with 39 additions and 52 deletions

View File

@ -14,28 +14,21 @@ from sh_edraft.time.model import TimeFormatSettings
class LoggerTest(unittest.TestCase): class LoggerTest(unittest.TestCase):
def setUp(self): def setUp(self):
app_host = ApplicationHost('CPL_Test') self._app_host = ApplicationHost()
self._app_runtime = app_host.application_runtime self._config = self._app_host.configuration
self._config = app_host.configuration
self._config.create() 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._services.create()
self._log_settings = LoggingSettings() self._app_runtime = self._app_host.application_runtime
self._log_settings.from_dict({ self._log_settings: LoggingSettings = self._config.get_configuration(LoggingSettings)
"Path": "logs/", self._time_format_settings: TimeFormatSettings = self._config.get_configuration(TimeFormatSettings)
"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"
})
def tearDown(self): def tearDown(self):
if os.path.isdir(self._log_settings.path): if os.path.isdir(self._log_settings.path):

View File

@ -2,8 +2,7 @@ import os
import shutil import shutil
import unittest import unittest
from sh_edraft.hosting import ApplicationHost, HostingEnvironment from sh_edraft.hosting import ApplicationHost
from sh_edraft.hosting.model import EnvironmentName
from sh_edraft.logging import Logger from sh_edraft.logging import Logger
from sh_edraft.logging.model import LoggingSettings from sh_edraft.logging.model import LoggingSettings
from sh_edraft.publishing import Publisher from sh_edraft.publishing import Publisher
@ -16,22 +15,6 @@ from sh_edraft.time.model import TimeFormatSettings
class PublisherTest(unittest.TestCase): class PublisherTest(unittest.TestCase):
def _configure(self): 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() self._version = Version(2020, 12, 5).to_dict()
templates = [ templates = [
Template( Template(
@ -76,12 +59,23 @@ class PublisherTest(unittest.TestCase):
}) })
def setUp(self): 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() self._configure()
app_host = ApplicationHost('CPL_Test') self._log_settings: LoggingSettings = self._config.get_configuration(LoggingSettings)
self._app_runtime = app_host.application_runtime 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 = Logger(self._log_settings, self._time_format_settings, app_host.application_runtime)
self._logger.create() self._logger.create()
def tearDown(self): def tearDown(self):

View File

@ -1,7 +1,7 @@
import unittest import unittest
# from tests.logging.logger import LoggerTest from tests.logging.logger import LoggerTest
# from tests.publishing.publisher import PublisherTest from tests.publishing.publisher import PublisherTest
from tests.service_providing.service_provider import ServiceProviderTest from tests.service_providing.service_provider import ServiceProviderTest
@ -21,17 +21,17 @@ class Tester:
self._suite.addTest(ServiceProviderTest('test_get_transient')) self._suite.addTest(ServiceProviderTest('test_get_transient'))
# logging # logging
# self._suite.addTest(LoggerTest('test_create')) self._suite.addTest(LoggerTest('test_create'))
# self._suite.addTest(LoggerTest('test_header')) self._suite.addTest(LoggerTest('test_header'))
# self._suite.addTest(LoggerTest('test_trace')) self._suite.addTest(LoggerTest('test_trace'))
# self._suite.addTest(LoggerTest('test_debug')) self._suite.addTest(LoggerTest('test_debug'))
# self._suite.addTest(LoggerTest('test_info')) self._suite.addTest(LoggerTest('test_info'))
# self._suite.addTest(LoggerTest('test_warn')) self._suite.addTest(LoggerTest('test_warn'))
# self._suite.addTest(LoggerTest('test_error')) self._suite.addTest(LoggerTest('test_error'))
# self._suite.addTest(LoggerTest('test_fatal')) self._suite.addTest(LoggerTest('test_fatal'))
# publishing # publishing
# self._suite.addTest(PublisherTest('test_create')) self._suite.addTest(PublisherTest('test_create'))
def start(self): def start(self):
runner = unittest.TextTestRunner() runner = unittest.TextTestRunner()