diff --git a/src/sh_edraft/configuration/configuration.py b/src/sh_edraft/configuration/configuration.py index 0b311d6e..dc0ef33f 100644 --- a/src/sh_edraft/configuration/configuration.py +++ b/src/sh_edraft/configuration/configuration.py @@ -7,6 +7,7 @@ from sh_edraft.configuration.base.configuration_base import ConfigurationBase from sh_edraft.configuration.model.configuration_variable_name import ConfigurationVariableName from sh_edraft.environment.base.environment_base import EnvironmentBase from sh_edraft.environment.hosting_environment import HostingEnvironment +from sh_edraft.environment.model import EnvironmentName from sh_edraft.utils import Console @@ -36,7 +37,7 @@ class Configuration(ConfigurationBase): def _set_variable(self, name: str, value: str): if name == ConfigurationVariableName.environment.value: - self._hosting_environment.environment_name = value + self._hosting_environment.environment_name = EnvironmentName(value) elif name == ConfigurationVariableName.name.value: self._hosting_environment.application_name = value diff --git a/src/sh_edraft/environment/base/environment_base.py b/src/sh_edraft/environment/base/environment_base.py index 9d78d598..f5dc9266 100644 --- a/src/sh_edraft/environment/base/environment_base.py +++ b/src/sh_edraft/environment/base/environment_base.py @@ -1,7 +1,5 @@ from abc import ABC, abstractmethod -from sh_edraft.environment.model.environment_name import EnvironmentName - class EnvironmentBase(ABC): @@ -10,11 +8,11 @@ class EnvironmentBase(ABC): @property @abstractmethod - def environment_name(self) -> EnvironmentName: pass + def environment_name(self) -> str: pass @environment_name.setter @abstractmethod - def environment_name(self, environment_name: EnvironmentName): pass + def environment_name(self, environment_name: str): pass @property @abstractmethod diff --git a/src/sh_edraft/environment/hosting_environment.py b/src/sh_edraft/environment/hosting_environment.py index 3840a3d2..2f2021ff 100644 --- a/src/sh_edraft/environment/hosting_environment.py +++ b/src/sh_edraft/environment/hosting_environment.py @@ -16,12 +16,12 @@ class HostingEnvironment(EnvironmentBase): self._content_root_path: Optional[str] = crp @property - def environment_name(self) -> EnvironmentName: - return self._environment_name + def environment_name(self) -> str: + return str(self._environment_name.value) @environment_name.setter - def environment_name(self, environment_name: EnvironmentName): - self._environment_name = environment_name + def environment_name(self, environment_name: str): + self._environment_name = EnvironmentName(environment_name) @property def application_name(self) -> str: diff --git a/src/sh_edraft/hosting/application_host.py b/src/sh_edraft/hosting/application_host.py index 1960b419..e5e6b362 100644 --- a/src/sh_edraft/hosting/application_host.py +++ b/src/sh_edraft/hosting/application_host.py @@ -1,4 +1,3 @@ -import sys from datetime import datetime from sh_edraft.configuration.configuration import Configuration diff --git a/src/sh_edraft/service/__init__.py b/src/sh_edraft/service/__init__.py index dbc93593..52003f0b 100644 --- a/src/sh_edraft/service/__init__.py +++ b/src/sh_edraft/service/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -sh_edraft.service +sh_edraft.services ~~~~~~~~~~~~~~~~~~~ @@ -11,7 +11,7 @@ sh_edraft.service """ -__title__ = 'sh_edraft.service' +__title__ = 'sh_edraft.services' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 sh-edraft.de' diff --git a/src/sh_edraft/service/base/__init__.py b/src/sh_edraft/service/base/__init__.py index e2c43c24..6ce7f45b 100644 --- a/src/sh_edraft/service/base/__init__.py +++ b/src/sh_edraft/service/base/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -sh_edraft.service.base +sh_edraft.services.base ~~~~~~~~~~~~~~~~~~~ @@ -11,7 +11,7 @@ sh_edraft.service.base """ -__title__ = 'sh_edraft.service.base' +__title__ = 'sh_edraft.services.base' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 sh-edraft.de' diff --git a/src/sh_edraft/service/model/__init__.py b/src/sh_edraft/service/model/__init__.py index 96c24ada..b95fe3c2 100644 --- a/src/sh_edraft/service/model/__init__.py +++ b/src/sh_edraft/service/model/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -sh_edraft.service.base +sh_edraft.services.base ~~~~~~~~~~~~~~~~~~~ @@ -11,7 +11,7 @@ sh_edraft.service.base """ -__title__ = 'sh_edraft.service.base' +__title__ = 'sh_edraft.services.base' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 sh-edraft.de' diff --git a/src/tests/appsettings.edrafts-pc.json b/src/tests/appsettings.edrafts-pc.json new file mode 100644 index 00000000..62ec6c61 --- /dev/null +++ b/src/tests/appsettings.edrafts-pc.json @@ -0,0 +1,8 @@ +{ + "LoggingSettings": { + "Path": "logs/", + "Filename": "log_$start_time.log", + "ConsoleLogLevel": "TRACE", + "FileLogLevel": "TRACE" + } +} \ No newline at end of file diff --git a/src/tests/logging/__init__.py b/src/tests/configuration/__init__.py similarity index 100% rename from src/tests/logging/__init__.py rename to src/tests/configuration/__init__.py diff --git a/src/tests/configuration/config.py b/src/tests/configuration/config.py new file mode 100644 index 00000000..27218978 --- /dev/null +++ b/src/tests/configuration/config.py @@ -0,0 +1,93 @@ +import os +import unittest +from typing import cast + +from sh_edraft.configuration import Configuration +from sh_edraft.environment.model import EnvironmentName +from sh_edraft.hosting import ApplicationHost +from sh_edraft.logging.model import LoggingSettings, LoggingLevel +from sh_edraft.publishing.model import PublishSettings +from sh_edraft.time.model import TimeFormatSettings + + +class ConfigTest(unittest.TestCase): + + def setUp(self): + self._app_host = ApplicationHost() + self._config = cast(Configuration, self._app_host.configuration) + + def test_create(self): + print(f'{__name__}.test_create:') + self.assertIsNotNone(self._config) + self._config.create() + self.assertIsNotNone(self._config) + + self.assertEqual(len(self._config._config), 0) + self.assertIsNotNone(self._app_host.application_runtime) + + def test_env_vars(self): + print(f'{__name__}.test_env_vars:') + self._config.add_environment_variables('PYTHON_') + self._config.add_environment_variables('CPL_') + + def test_arguments(self): + print(f'{__name__}.test_arguments:') + self._config.add_argument_variables() + self.assertEqual(self._config.environment.environment_name, EnvironmentName.testing.value) + + def test_appsettings(self): + print(f'{__name__}.test_appsettings:') + self._config.add_json_file(f'appsettings.json') + + time_formats: TimeFormatSettings = cast(TimeFormatSettings, self._config.get_configuration(TimeFormatSettings)) + self.assertIsNotNone(time_formats) + self.assertEqual(time_formats.date_format, '%Y-%m-%d') + self.assertEqual(time_formats.time_format, '%H:%M:%S') + self.assertEqual(time_formats.date_time_format, '%Y-%m-%d %H:%M:%S.%f') + self.assertEqual(time_formats.date_time_log_format, '%Y-%m-%d_%H-%M-%S') + + logging = cast(LoggingSettings, self._config.get_configuration(LoggingSettings)) + self.assertIsNotNone(logging) + self.assertEqual(logging.path, 'logs/') + self.assertEqual(logging.filename, 'log_$start_time.log') + self.assertEqual(logging.console.value, LoggingLevel.ERROR.value) + self.assertEqual(logging.level.value, LoggingLevel.WARN.value) + + with self.assertRaises(Exception): + publish: PublishSettings = cast(PublishSettings, self._config.get_configuration(PublishSettings)) + + def test_appsettings_environment(self): + print(f'{__name__}.test_appsettings_environment:') + self._config.add_argument_variables() + self._config.add_json_file(f'appsettings.{self._config.environment.environment_name}.json') + + logging = cast(LoggingSettings, self._config.get_configuration(LoggingSettings)) + self.assertIsNotNone(logging) + self.assertEqual(logging.path, 'logs/') + self.assertEqual(logging.filename, 'log_$start_time.log') + self.assertEqual(logging.console.value, LoggingLevel.TRACE.value) + self.assertEqual(logging.level.value, LoggingLevel.TRACE.value) + + publish: PublishSettings = cast(PublishSettings, self._config.get_configuration(PublishSettings)) + self.assertIsNotNone(publish) + self.assertEqual(publish.source_path, '../') + self.assertEqual(publish.dist_path, '../../dist') + self.assertEqual(publish.templates, []) + self.assertEqual(publish.included_files, []) + self.assertEqual(publish.excluded_files, []) + self.assertEqual(publish.template_ending, '_template.txt') + + def test_appsettings_host(self): + print(f'{__name__}.test_appsettings_host:') + self._config.add_json_file(f'appsettings.{self._config.environment.host_name}.json') + + def test_appsettings_customer(self): + print(f'{__name__}.test_appsettings_customer:') + file_name = f'appsettings.{self._config.environment.customer}.json' + with self.assertRaises(SystemExit): + if os.path.isfile(f'{self._config.environment.content_root_path}/{file_name}'): + os.remove(f'{self._config.environment.content_root_path}/{file_name}') + + self._config.add_json_file(file_name) + + self._config.add_json_file(file_name, optional=True) diff --git a/src/tests/publishing/__init__.py b/src/tests/hosting/__init__.py similarity index 100% rename from src/tests/publishing/__init__.py rename to src/tests/hosting/__init__.py diff --git a/src/tests/hosting/app_host.py b/src/tests/hosting/app_host.py new file mode 100644 index 00000000..ec940481 --- /dev/null +++ b/src/tests/hosting/app_host.py @@ -0,0 +1,33 @@ +import unittest +import datetime + +from sh_edraft.configuration.base import ConfigurationBase +from sh_edraft.hosting import ApplicationHost +from sh_edraft.hosting.base import ApplicationRuntimeBase +from sh_edraft.service.base import ServiceProviderBase + + +class AppHostTest(unittest.TestCase): + + def setUp(self): + pass + + def test_create(self): + print(f'{__name__}.test_create:') + app_host = ApplicationHost() + self.assertIsNotNone(app_host) + app_host.create() + + self.assertIsNotNone(app_host.configuration) + self.assertTrue(isinstance(app_host.configuration, ConfigurationBase)) + + self.assertIsNotNone(app_host.application_runtime) + self.assertTrue(isinstance(app_host.application_runtime, ApplicationRuntimeBase)) + + self.assertIsNotNone(app_host.services) + self.assertTrue(isinstance(app_host.services, ServiceProviderBase)) + + self.assertIsNotNone(app_host._start_time) + self.assertTrue(isinstance(app_host._start_time, datetime.datetime)) + self.assertIsNotNone(app_host._end_time) + self.assertTrue(isinstance(app_host._end_time, datetime.datetime)) diff --git a/src/tests/services/__init__.py b/src/tests/services/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/tests/services/logging/__init__.py b/src/tests/services/logging/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/tests/logging/logger.py b/src/tests/services/logging/logger.py similarity index 100% rename from src/tests/logging/logger.py rename to src/tests/services/logging/logger.py diff --git a/src/tests/services/publishing/__init__.py b/src/tests/services/publishing/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/tests/publishing/publisher.py b/src/tests/services/publishing/publisher.py similarity index 98% rename from src/tests/publishing/publisher.py rename to src/tests/services/publishing/publisher.py index 4e87c8c1..afb17eaa 100644 --- a/src/tests/publishing/publisher.py +++ b/src/tests/services/publishing/publisher.py @@ -83,6 +83,7 @@ class PublisherTest(unittest.TestCase): shutil.rmtree(self._log_settings.path) def test_create(self): + print(f'{__name__}.test_create:') publisher: Publisher = Publisher(self._logger, self._publish_settings_model) self.assertIsNotNone(publisher) diff --git a/src/tests/tester.py b/src/tests/tester.py index dfb11e49..d7b17030 100644 --- a/src/tests/tester.py +++ b/src/tests/tester.py @@ -1,7 +1,9 @@ import unittest -from tests.logging.logger import LoggerTest -from tests.publishing.publisher import PublisherTest +from tests.configuration.config import ConfigTest +from tests.hosting.app_host import AppHostTest +from tests.services.logging.logger import LoggerTest +from tests.services.publishing.publisher import PublisherTest from tests.service_providing.service_provider import ServiceProviderTest @@ -11,6 +13,18 @@ class Tester: self._suite = unittest.TestSuite() def create(self): + # hosting app host + self._suite.addTest(AppHostTest('test_create')) + + # configuration + self._suite.addTest(ConfigTest('test_create')) + self._suite.addTest(ConfigTest('test_env_vars')) + self._suite.addTest(ConfigTest('test_arguments')) + self._suite.addTest(ConfigTest('test_appsettings')) + self._suite.addTest(ConfigTest('test_appsettings_environment')) + self._suite.addTest(ConfigTest('test_appsettings_host')) + self._suite.addTest(ConfigTest('test_appsettings_customer')) + # providing self._suite.addTest(ServiceProviderTest('test_create')) self._suite.addTest(ServiceProviderTest('test_add_singleton')) diff --git a/src/tests_dev/program.py b/src/tests_dev/program.py index 7d4e7494..2ee1b09b 100644 --- a/src/tests_dev/program.py +++ b/src/tests_dev/program.py @@ -14,14 +14,14 @@ class Program(ApplicationBase): ApplicationBase.__init__(self) self._app_host: Optional[ApplicationHost] = None - self._services: Optional[ServiceProviderBase] = None self._configuration: Optional[ConfigurationBase] = None + self._logger: Optional[LoggerBase] = None def create_application_host(self): self._app_host = ApplicationHost() - self._services = self._app_host.services self._configuration = self._app_host.configuration + self._services = self._app_host.services def create_configuration(self): self._configuration.create() @@ -35,12 +35,11 @@ class Program(ApplicationBase): def create_services(self): self._services.create() self._services.add_singleton(LoggerBase, Logger) - logger: Logger = self._services.get_service(LoggerBase) - logger.create() - logger.header(f'{self._configuration.environment.application_name}:') - logger.debug(__name__, f'Host: {self._configuration.environment.host_name}') - logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}') - logger.debug(__name__, f'Customer: {self._configuration.environment.customer}') + self._logger = self._services.get_service(LoggerBase) + self._logger.create() def main(self): - print('RUN') + self._logger.header(f'{self._configuration.environment.application_name}:') + self._logger.debug(__name__, f'Host: {self._configuration.environment.host_name}') + self._logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}') + self._logger.debug(__name__, f'Customer: {self._configuration.environment.customer}')