From 0378f8944a59a40c59cbaa5c8d244a39973bdce2 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 9 Apr 2023 12:05:05 +0200 Subject: [PATCH] Added AppEnv tests --- .../unittests_core/configuration/__init__.py | 0 .../configuration/environment_test_case.py | 52 +++++++++++++++++++ unittests/unittests_core/core_test_suite.py | 3 ++ .../unittests_core/utils/string_test_case.py | 1 + 4 files changed, 56 insertions(+) create mode 100644 unittests/unittests_core/configuration/__init__.py create mode 100644 unittests/unittests_core/configuration/environment_test_case.py diff --git a/unittests/unittests_core/configuration/__init__.py b/unittests/unittests_core/configuration/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/unittests/unittests_core/configuration/environment_test_case.py b/unittests/unittests_core/configuration/environment_test_case.py new file mode 100644 index 00000000..5c1a4aed --- /dev/null +++ b/unittests/unittests_core/configuration/environment_test_case.py @@ -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) diff --git a/unittests/unittests_core/core_test_suite.py b/unittests/unittests_core/core_test_suite.py index ede67d9e..56304328 100644 --- a/unittests/unittests_core/core_test_suite.py +++ b/unittests/unittests_core/core_test_suite.py @@ -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, diff --git a/unittests/unittests_core/utils/string_test_case.py b/unittests/unittests_core/utils/string_test_case.py index 7a5173f2..cc826567 100644 --- a/unittests/unittests_core/utils/string_test_case.py +++ b/unittests/unittests_core/utils/string_test_case.py @@ -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"))