#157 #165
| @@ -12,11 +12,11 @@ class DatabaseSettings(ConfigurationModelABC): | ||||
|         port: int = None, | ||||
|         user: str = None, | ||||
|         password: str = None, | ||||
|         databse: str = None, | ||||
|         database: str = None, | ||||
|         charset: str = None, | ||||
|         use_unicode: bool = None, | ||||
|         buffered: bool = None, | ||||
|         auth_plugin: bool = None, | ||||
|         auth_plugin: str = None, | ||||
|     ): | ||||
|         ConfigurationModelABC.__init__(self) | ||||
|  | ||||
| @@ -24,7 +24,7 @@ class DatabaseSettings(ConfigurationModelABC): | ||||
|         self._port: Optional[int] = port | ||||
|         self._user: Optional[str] = user | ||||
|         self._password: Optional[str] = password | ||||
|         self._databse: Optional[str] = databse | ||||
|         self._databse: Optional[str] = database | ||||
|         self._charset: Optional[str] = charset | ||||
|         self._use_unicode: Optional[bool] = use_unicode | ||||
|         self._buffered: Optional[bool] = buffered | ||||
|   | ||||
| @@ -30,6 +30,9 @@ class JSONProcessor: | ||||
|                 if issubclass(parameter.annotation, enum.Enum): | ||||
|                     value = parameter.annotation[value] | ||||
|  | ||||
|                 if type(value) != parameter.annotation: | ||||
|                     value = parameter.annotation(value) | ||||
|  | ||||
|                 args.append(value) | ||||
|  | ||||
|             elif parameter.default != Parameter.empty: | ||||
|   | ||||
| @@ -0,0 +1,37 @@ | ||||
| import os | ||||
| import unittest | ||||
|  | ||||
| from cpl_core.configuration import Configuration | ||||
| from cpl_core.database import DatabaseSettings | ||||
| from cpl_core.mailing import EMailClientSettings | ||||
|  | ||||
|  | ||||
| class ConfigurationTestCase(unittest.TestCase): | ||||
|     def setUp(self): | ||||
|         self._config = Configuration() | ||||
|  | ||||
|     def test_env_vars(self): | ||||
|         os.environ["CPLT_TESTVAR"] = "Hello World" | ||||
|         os.environ["CPL_NOT_EXISTING"] = "Hello World" | ||||
|  | ||||
|         self._config.add_environment_variables("CPLT_") | ||||
|  | ||||
|         self.assertEqual(self._config.get_configuration("TESTVAR"), "Hello World") | ||||
|         self.assertEqual(self._config.get_configuration("TESTVAR"), "Hello World") | ||||
|         self.assertEqual(self._config.get_configuration("NOT_EXISTING"), None) | ||||
|  | ||||
|     def test_add_json_file(self): | ||||
|         self._config.add_json_file("unittests_core/configuration/test-settings.json") | ||||
|         db = self._config.get_configuration(DatabaseSettings) | ||||
|         self.assertIsNotNone(db) | ||||
|         self.assertEqual("localhost", db.host) | ||||
|         self.assertEqual("local", db.user) | ||||
|         self.assertEqual("bG9jYWw=", db.password) | ||||
|         self.assertEqual("local", db.database) | ||||
|         self.assertEqual(int, type(db.port)) | ||||
|         self.assertEqual(3306, db.port) | ||||
|         self.assertEqual("utf8mb4", db.charset) | ||||
|         self.assertTrue(db.use_unicode) | ||||
|         self.assertTrue(db.buffered) | ||||
|         self.assertEqual("mysql_native_password", db.auth_plugin) | ||||
|         self.assertIsNone(self._config.get_configuration(EMailClientSettings)) | ||||
							
								
								
									
										25
									
								
								unittests/unittests_core/configuration/test-settings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								unittests/unittests_core/configuration/test-settings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| { | ||||
|   "TimeFormatSettings": { | ||||
|     "DateFormat": "%Y-%m-%d", | ||||
|     "TimeFormat": "%H:%M:%S", | ||||
|     "DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f", | ||||
|     "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" | ||||
|   }, | ||||
|   "LoggingSettings": { | ||||
|     "Path": "logs/$date_now/", | ||||
|     "Filename": "bot.log", | ||||
|     "ConsoleLogLevel": "TRACE", | ||||
|     "FileLogLevel": "TRACE" | ||||
|   }, | ||||
|   "DatabaseSettings": { | ||||
|     "Host": "localhost", | ||||
|     "User": "local", | ||||
|     "Password": "bG9jYWw=", | ||||
|     "Database": "local", | ||||
|     "Port": "3306", | ||||
|     "Charset": "utf8mb4", | ||||
|     "UseUnicode": "true", | ||||
|     "Buffered": "true", | ||||
|     "AuthPlugin": "mysql_native_password" | ||||
|   } | ||||
| } | ||||
| @@ -1,5 +1,6 @@ | ||||
| import unittest | ||||
|  | ||||
| from unittests_core.configuration.configuration_test_case import ConfigurationTestCase | ||||
| 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 | ||||
| @@ -16,6 +17,7 @@ class CoreTestSuite(unittest.TestSuite): | ||||
|         loader = unittest.TestLoader() | ||||
|         tests = [ | ||||
|             # config | ||||
|             ConfigurationTestCase, | ||||
|             EnvironmentTestCase, | ||||
|             # pipes | ||||
|             BoolPipeTestCase, | ||||
|   | ||||
| @@ -26,7 +26,7 @@ class JSONProcessorTestCase(unittest.TestCase): | ||||
|             "i": 10, | ||||
|             "s": "Hello World", | ||||
|             "d": {"test": "Test"}, | ||||
|             "l": range(0, 11), | ||||
|             "l": list(range(0, 11)), | ||||
|             "value": {"value": "Hello World"}, | ||||
|         } | ||||
|         test: TestClass = JSONProcessor.process(TestClass, test_dict) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user