FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 0419e50c authored by L. Bower's avatar L. Bower
Browse files

restructuring the advisory test to get ready for a full-fat implementation

parent db3eb80d
No related branches found
No related tags found
No related merge requests found
import copy import copy
import glob
import os import os
import unittest import unittest
from integration.partial.integration_test_utils import IntegrationTestUtils from integration.partial.integration_test_utils import IntegrationTestUtils
from integration.test_suites.advisory_test_suite import BaseAdvisoryTestSuite
class TestAdvisory(unittest.TestCase): class TestAdvisory(BaseAdvisoryTestSuite.AdvisoryTestSuite):
TEST_OUT_PATH: str = "not_set" def set_expected_values(self):
TEST_START_DATE: str = '20221001' BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_START_DATE = '20221001'
TEST_JOB_DIR: str = "ADVISORY_" + TEST_START_DATE BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR = "ADVISORY_" + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_START_DATE
@classmethod
def setUpClass(cls) -> None: def setUp(self) -> None:
TestAdvisory.write_temp_run_config_files()
TestAdvisory.unpack_dependencies() self.set_expected_values()
TestAdvisory.run_advisory_pipeline()
if BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH is None or not os.path.isdir(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH):
TestAdvisory.write_temp_run_config_files()
TestAdvisory.unpack_dependencies()
TestAdvisory.run_advisory_pipeline()
else:
print(f"output in {BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH} already written, skipping rerun")
@staticmethod @staticmethod
def write_temp_run_config_files(): def write_temp_run_config_files():
nowstring: str = IntegrationTestUtils.get_now_string() nowstring: str = IntegrationTestUtils.get_now_string()
prefix: str = "temp_advisory_" + nowstring # prefix: str = "temp_advisory_" + nowstring
# prefix: str = "" prefix: str = "temp_advisory"
default_config = IntegrationTestUtils.DEFAULT_CONFIG_FILE_PATH default_config = IntegrationTestUtils.DEFAULT_CONFIG_FILE_PATH
default_config_dict: dict = IntegrationTestUtils.load_json_file(default_config) default_config_dict: dict = IntegrationTestUtils.load_json_file(default_config)
run_dict: dict = copy.deepcopy(default_config_dict) run_dict: dict = copy.deepcopy(default_config_dict)
TestAdvisory.TEST_OUT_PATH = run_dict['WorkspacePathout'] + prefix + os.sep BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH = IntegrationTestUtils.TEST_WORKSPACE_PATH + prefix + os.sep
run_dict['WorkspacePathout'] = TestAdvisory.TEST_OUT_PATH # TestAdvisory.TEST_OUT_PATH = run_dict['WorkspacePathout'] + prefix + os.sep
run_dict['WorkspacePath'] = TestAdvisory.TEST_OUT_PATH run_dict['WorkspacePathout'] = BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH
run_dict['WorkspacePath'] = BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH
run_dict['ServerName'] = '' # nothing, as local machine run_dict['ServerName'] = '' # nothing, as local machine
IntegrationTestUtils.write_json_file(run_dict, IntegrationTestUtils.TEMP_CONFIG_FILE_NAME) IntegrationTestUtils.write_json_file(run_dict, IntegrationTestUtils.TEMP_CONFIG_FILE_NAME)
...@@ -49,48 +56,5 @@ class TestAdvisory(unittest.TestCase): ...@@ -49,48 +56,5 @@ class TestAdvisory(unittest.TestCase):
IntegrationTestUtils.run_unittest_pipeline(component, TestAdvisory.TEST_START_DATE) IntegrationTestUtils.run_unittest_pipeline(component, TestAdvisory.TEST_START_DATE)
def test_standard_run_input_status_success(self):
status_file_path = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR, "STATUS_SUCCESS")
success_file_exists: bool = os.path.isfile(status_file_path)
self.assertTrue(success_file_exists)
def test_standard_run_input_all_docs_produced(self):
east_africa_image_path = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR,
"tight-layout",
"wheat_rust_advisory_template_EastAfrica_20221001.docx")
ethiopia_image_path = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR,
"tight-layout",
"wheat_rust_advisory_template_Ethiopia_20221001.docx")
ea_file_exists: bool = os.path.isfile(east_africa_image_path)
eth_file_exists: bool = os.path.isfile(ethiopia_image_path)
self.assertTrue(ea_file_exists)
self.assertTrue(eth_file_exists)
def test_standard_run_input_images_produced(self):
east_africa_image_wildcard = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR,
"images",
"*eastafrica*.png")
ethiopia_image_wildcard = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR,
"images",
"*ethiopia*.png")
africa_image_count: int = len(glob.glob(east_africa_image_wildcard))
ethiopia_image_count: int = len(glob.glob(ethiopia_image_wildcard))
self.assertEqual(3, africa_image_count)
self.assertEqual(3, ethiopia_image_count)
def test_standard_run_input_shapefiles_produced(self):
east_africa_image_wildcard = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR,
"images",
"*eastafrica*.shp")
africa_image_count: int = len(glob.glob(east_africa_image_wildcard))
self.assertEqual(3, africa_image_count)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
import abc
import glob
import os
import unittest
from integration.partial.integration_test_utils import IntegrationTestUtils
class BaseAdvisoryTestSuite:
class AdvisoryTestSuite(unittest.TestCase):
TEST_OUT_PATH: str = None
TEST_START_DATE: str = None
TEST_JOB_DIR: str = None
@abc.abstractmethod
def set_expected_values(self):
pass
def test_standard_run_input_status_success(self):
status_file_path = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH, BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR, "STATUS_SUCCESS")
success_file_exists: bool = os.path.isfile(status_file_path)
self.assertTrue(success_file_exists)
def test_standard_run_input_all_docs_produced(self):
east_africa_image_path = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH,
BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR,
"tight-layout",
"wheat_rust_advisory_template_EastAfrica_20221001.docx")
ethiopia_image_path = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH,
BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR,
"tight-layout",
"wheat_rust_advisory_template_Ethiopia_20221001.docx")
ea_file_exists: bool = os.path.isfile(east_africa_image_path)
eth_file_exists: bool = os.path.isfile(ethiopia_image_path)
self.assertTrue(ea_file_exists)
self.assertTrue(eth_file_exists)
def test_standard_run_input_images_produced(self):
east_africa_image_wildcard = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH,
BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR,
"images",
"*eastafrica*.png")
ethiopia_image_wildcard = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH,
BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR,
"images",
"*ethiopia*.png")
africa_image_count: int = len(glob.glob(east_africa_image_wildcard))
ethiopia_image_count: int = len(glob.glob(ethiopia_image_wildcard))
self.assertEqual(3, africa_image_count)
self.assertEqual(3, ethiopia_image_count)
def test_standard_run_input_shapefiles_produced(self):
east_africa_image_wildcard = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH,
BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR,
"images",
"*eastafrica*.shp")
africa_image_count: int = len(glob.glob(east_africa_image_wildcard))
self.assertEqual(3, africa_image_count)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment