Assign None if the configuration variables can't be found in environment variables. 91/11291/1
authorTaewan Kim <t25.kim@samsung.com>
Thu, 8 Jun 2023 09:19:23 +0000 (18:19 +0900)
committerTaewan Kim <t25.kim@samsung.com>
Thu, 8 Jun 2023 09:19:23 +0000 (18:19 +0900)
- A unit test which `is_config_loaded_properly` returns False added

Issue-ID: AIMLFW-35

Change-Id: I8ac0f3c7f30d6570caa6ec5c76fe499cead459a4
Signed-off-by: Taewan Kim <t25.kim@samsung.com>
tests/test_trainingmgr_config.py
trainingmgr/common/trainingmgr_config.py

index 08385cf..a699588 100644 (file)
@@ -104,8 +104,15 @@ class Test_trainingmgr_config:
         result = self.TRAININGMGR_CONFIG_OBJ.allow_control_access_origin
         assert result == expected_data
 
-    def test_is_config_loaded_properly(self):
+    def test_is_config_loaded_properly_return_true(self):
         expected_data = True
         result = TrainingMgrConfig.is_config_loaded_properly(self.TRAININGMGR_CONFIG_OBJ)
         assert result == expected_data
 
+    @patch('trainingmgr.common.trainingmgr_config.TMLogger', return_value = TMLogger("tests/common/conf_log.yaml"))
+    def test_is_config_loaded_properly_return_false(self,mock1):
+        os.environ.pop("KF_ADAPTER_IP")
+        self.TRAININGMGR_CONFIG_OBJ = TrainingMgrConfig()
+        expected_data = False
+        result = TrainingMgrConfig.is_config_loaded_properly(self.TRAININGMGR_CONFIG_OBJ)
+        assert result == expected_data
\ No newline at end of file
index 11c6b92..2bcb0d0 100644 (file)
@@ -33,20 +33,20 @@ class TrainingMgrConfig:
         """
         This constructor filling configuration varibles.
         """
-        self.__kf_adapter_port = getenv('KF_ADAPTER_PORT').rstrip()
-        self.__kf_adapter_ip = getenv('KF_ADAPTER_IP').rstrip()
+        self.__kf_adapter_port = getenv('KF_ADAPTER_PORT').rstrip() if getenv('KF_ADAPTER_PORT') is not None else None
+        self.__kf_adapter_ip = getenv('KF_ADAPTER_IP').rstrip() if getenv('KF_ADAPTER_IP') is not None else None
 
-        self.__data_extraction_port = getenv('DATA_EXTRACTION_API_PORT').rstrip()
-        self.__data_extraction_ip = getenv('DATA_EXTRACTION_API_IP').rstrip()
+        self.__data_extraction_port = getenv('DATA_EXTRACTION_API_PORT').rstrip() if getenv('DATA_EXTRACTION_API_PORT') is not None else None
+        self.__data_extraction_ip = getenv('DATA_EXTRACTION_API_IP').rstrip() if getenv('DATA_EXTRACTION_API_IP') is not None else None
 
-        self.__my_port = getenv('TRAINING_MANAGER_PORT').rstrip()
-        self.__my_ip = getenv('TRAINING_MANAGER_IP').rstrip()
+        self.__my_port = getenv('TRAINING_MANAGER_PORT').rstrip() if getenv('TRAINING_MANAGER_PORT') is not None else None
+        self.__my_ip = getenv('TRAINING_MANAGER_IP').rstrip() if getenv('TRAINING_MANAGER_IP') is not None else None
 
-        self.__ps_user = getenv('PS_USER').rstrip()
-        self.__ps_password = getenv('PS_PASSWORD').rstrip()
-        self.__ps_ip = getenv('PS_IP').rstrip()
-        self.__ps_port = getenv('PS_PORT').rstrip()
-        self.__allow_control_access_origin = getenv('ACCESS_CONTROL_ALLOW_ORIGIN').rstrip()
+        self.__ps_user = getenv('PS_USER').rstrip() if getenv('PS_USER') is not None else None
+        self.__ps_password = getenv('PS_PASSWORD').rstrip() if getenv('PS_PASSWORD') is not None else None
+        self.__ps_ip = getenv('PS_IP').rstrip() if getenv('PS_IP') is not None else None
+        self.__ps_port = getenv('PS_PORT').rstrip() if getenv('PS_PORT') is not None else None
+        self.__allow_control_access_origin = getenv('ACCESS_CONTROL_ALLOW_ORIGIN').rstrip() if getenv('ACCESS_CONTROL_ALLOW_ORIGIN') is not None else None
 
         self.tmgr_logger = TMLogger("common/conf_log.yaml")
         self.__logger = self.tmgr_logger.logger