Added AppEnv tests

This commit is contained in:
Sven Heidemann 2023-04-09 12:05:05 +02:00
parent 75fde0f444
commit 0378f8944a
4 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,52 @@
import os
import unittest
from _socket import gethostname
from cpl_core.configuration import Configuration
from cpl_core.environment import ApplicationEnvironment, ApplicationEnvironmentABC
from cpl_core.environment import application_environment
class EnvironmentTestCase(unittest.TestCase):
def setUp(self):
self._config = Configuration()
self._env = self._config.environment
def test_app_env_created(self):
self.assertTrue(isinstance(self._env, ApplicationEnvironment))
self.assertTrue(issubclass(type(self._env), ApplicationEnvironmentABC))
def test_app_env_values_correct_when_default(self):
self.assertEqual(self._env.environment_name, "production")
self.assertEqual(self._env.application_name, "")
self.assertEqual(self._env.customer, "")
self.assertEqual(self._env.host_name, gethostname())
self.assertEqual(self._env.working_directory, os.getcwd())
self.assertEqual(
self._env.runtime_directory,
os.path.dirname(os.path.dirname(os.path.abspath(application_environment.__file__))),
)
def test_app_env_values_correct_when_read_from_env(self):
os.environ["CPLT_ENVIRONMENT"] = "development"
os.environ["CPLT_NAME"] = "Core Tests"
os.environ["CPLT_CUSTOMER"] = "sh-edraft.de"
self._config.add_environment_variables("CPLT_")
self.assertEqual(self._env.environment_name, "development")
self.assertEqual(self._env.application_name, "Core Tests")
self.assertEqual(self._env.customer, "sh-edraft.de")
self.assertEqual(self._env.host_name, gethostname())
self.assertEqual(self._env.working_directory, os.getcwd())
self.assertEqual(
self._env.runtime_directory,
os.path.dirname(os.path.dirname(os.path.abspath(application_environment.__file__))),
)
def test_app_env_set_dirs(self):
new_cwd = os.path.join(os.getcwd(), "../")
self._env.set_working_directory(new_cwd)
self.assertEqual(self._env.working_directory, new_cwd)
self._env.set_runtime_directory(new_cwd)
self.assertEqual(self._env.runtime_directory, new_cwd)

View File

@ -1,5 +1,6 @@
import unittest
from unittests_core.configuration.environment_test_case import EnvironmentTestCase
from unittests_core.pipes.bool_pipe_test_case import BoolPipeTestCase
from unittests_core.pipes.ip_address_pipe_test_case import IPAddressTestCase
from unittests_core.pipes.version_pipe_test_case import VersionPipeTestCase
@ -14,6 +15,8 @@ class CoreTestSuite(unittest.TestSuite):
loader = unittest.TestLoader()
tests = [
# config
EnvironmentTestCase,
# pipes
BoolPipeTestCase,
IPAddressTestCase,

View File

@ -12,6 +12,7 @@ class StringTestCase(unittest.TestCase):
expected = "HelloWorld"
self.assertEqual(expected, String.convert_to_camel_case("hello-world"))
self.assertEqual(expected, String.convert_to_camel_case("hello-World"))
self.assertEqual(expected, String.convert_to_camel_case("hello_world"))
self.assertEqual("helloWorld", String.convert_to_camel_case("helloWorld"))
self.assertEqual(expected, String.convert_to_camel_case("Hello_world"))