Improved testing
This commit is contained in:
8
src/tests/appsettings.edrafts-pc.json
Normal file
8
src/tests/appsettings.edrafts-pc.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "TRACE",
|
||||
"FileLogLevel": "TRACE"
|
||||
}
|
||||
}
|
93
src/tests/configuration/config.py
Normal file
93
src/tests/configuration/config.py
Normal file
@@ -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)
|
33
src/tests/hosting/app_host.py
Normal file
33
src/tests/hosting/app_host.py
Normal file
@@ -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))
|
0
src/tests/services/__init__.py
Normal file
0
src/tests/services/__init__.py
Normal file
0
src/tests/services/logging/__init__.py
Normal file
0
src/tests/services/logging/__init__.py
Normal file
0
src/tests/services/publishing/__init__.py
Normal file
0
src/tests/services/publishing/__init__.py
Normal file
@@ -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)
|
||||
|
@@ -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'))
|
||||
|
Reference in New Issue
Block a user