From 0a5e7e1189d9680146b2de5d1aafa77be2e25b03 Mon Sep 17 00:00:00 2001
From: lb584 <lb584@cam.ac.uk>
Date: Thu, 20 Oct 2022 16:44:25 +0100
Subject: [PATCH] adding test utils

---
 tests/integration/integration_test_utils.py | 23 +++++++++++++++++
 tests/integration/test_deposition.py        | 28 ++++-----------------
 tests/integration/test_env_suit.py          | 10 ++++----
 3 files changed, 33 insertions(+), 28 deletions(-)
 create mode 100644 tests/integration/integration_test_utils.py

diff --git a/tests/integration/integration_test_utils.py b/tests/integration/integration_test_utils.py
new file mode 100644
index 0000000..b4f228a
--- /dev/null
+++ b/tests/integration/integration_test_utils.py
@@ -0,0 +1,23 @@
+import json
+from datetime import datetime
+
+
+class IntegrationTestUtils:
+
+    @staticmethod
+    def load_json_file(file: str) -> dict:
+        with open(file) as config_file:
+            config: dict = json.load(config_file)
+            return config
+
+
+    @staticmethod
+    def write_json_file(values: dict, file: str):
+        with open(file, 'w') as file:
+            json.dump(values, file, indent = 4)
+
+
+    @staticmethod
+    def get_now_string() -> str:
+        nowstring: str = datetime.today().strftime('%Y-%m-%d_%H%M%S')
+        return nowstring
diff --git a/tests/integration/test_deposition.py b/tests/integration/test_deposition.py
index 7781c72..cfa6069 100644
--- a/tests/integration/test_deposition.py
+++ b/tests/integration/test_deposition.py
@@ -1,8 +1,8 @@
 import copy
-import json
 import os
 import unittest
-from datetime import datetime
+
+from integration.integration_test_utils import IntegrationTestUtils
 
 
 class TestDeposition(unittest.TestCase):
@@ -12,30 +12,12 @@ class TestDeposition(unittest.TestCase):
     def setUp(self) -> None:
         super().setUp()
         default_config = '../test_data/test_deployment/regions/EastAfrica/resources/coordinator/configs/config_EastAfrica_fc_live.json'
-        self.default_config_dict: dict = TestDeposition.load_json_file(default_config)
+        self.default_config_dict: dict = IntegrationTestUtils.load_json_file(default_config)
         i = 0
 
-    @staticmethod
-    def load_json_file(file: str) -> dict:
-        with open(file) as config_file:
-            config: dict = json.load(config_file)
-            return config
-
-
-    @staticmethod
-    def write_json_file(values: dict, file: str):
-        with open(file, 'w') as file:
-            json.dump(values, file, indent = 4)
-
-    @staticmethod
-    def get_now_string() -> str:
-        nowstring: str = datetime.today().strftime('%Y-%m-%d_%H%M%S')
-        return nowstring
-
-
     def test_depo_standard_inputs_expected_results1(self):
 
-        nowstring: str = TestDeposition.get_now_string()
+        nowstring: str = IntegrationTestUtils.get_now_string()
 
         os.environ["EMAIL_CRED"] = "../test_data/test_deployment/envs/Cred_gmail.json"
         from Processor import run_Process, set_log_level
@@ -58,7 +40,7 @@ class TestDeposition(unittest.TestCase):
 
         run_dict['SubRegionNames'].remove('Kenya')
         run_dict['Deposition']['EWS-Plotting'].pop('Kenya', None)
-        TestDeposition.write_json_file(run_dict, self.TEMP_CONFIG_FILE_PATH)
+        IntegrationTestUtils.write_json_file(run_dict, self.TEMP_CONFIG_FILE_PATH)
 
         run_Process(args_dict)
         self.assertTrue(True)
diff --git a/tests/integration/test_env_suit.py b/tests/integration/test_env_suit.py
index 9275f9b..f2c45b1 100644
--- a/tests/integration/test_env_suit.py
+++ b/tests/integration/test_env_suit.py
@@ -1,8 +1,8 @@
 import copy
 import os
 import unittest
-from datetime import datetime
 
+from integration.integration_test_utils import IntegrationTestUtils
 from integration.test_deposition import TestDeposition
 
 
@@ -11,11 +11,11 @@ class TestEnvSuit(unittest.TestCase):
     def setUp(self) -> None:
         super().setUp()
         default_config = '../test_data/test_deployment/regions/EastAfrica/resources/coordinator/configs/config_EastAfrica_fc_live.json'
-        self.default_config_dict: dict = TestDeposition.load_json_file(default_config)
+        self.default_config_dict: dict = IntegrationTestUtils.load_json_file(default_config)
 
     def test_env_suit_standard_inputs_expected_results1(self):
 
-        nowstring: str = TestDeposition.get_now_string()
+        nowstring: str = IntegrationTestUtils.get_now_string()
 
         os.environ["EMAIL_CRED"] = "../test_data/test_deployment/envs/Cred_gmail.json"
         from Processor import run_Process, set_log_level
@@ -41,11 +41,11 @@ class TestEnvSuit(unittest.TestCase):
 
         run_dict['SubRegionNames'].remove('Kenya')
 
-        TestDeposition.write_json_file(run_dict, TestDeposition.TEMP_CONFIG_FILE_PATH)
+        IntegrationTestUtils.write_json_file(run_dict, TestDeposition.TEMP_CONFIG_FILE_PATH)
 
         run_Process(args_dict)
         self.assertTrue(True)
 
 
 if __name__ == '__main__':
-    unittest.main()
\ No newline at end of file
+    unittest.main()
-- 
GitLab