From 9cf51cc8d259b773197bc5047823ab76ced7b32b Mon Sep 17 00:00:00 2001 From: lb584 <lb584@cam.ac.uk> Date: Mon, 31 Oct 2022 16:35:55 +0000 Subject: [PATCH] adding basic advisory tests --- .gitlab-ci.yml | 8 ++-- tests/integration/test_advisory.py | 60 ++++++++++++++++++++++-------- tests/integration/test_env_suit.py | 4 +- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 27c2104..3e79209 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,10 +59,10 @@ test: - python -m coverage html -d $CI_PROJECT_DIR/coverage - cd $CI_PROJECT_DIR/tests/integration - python3 -m coverage run -m unittest test_deposition.py -# - python3 -m unittest test_deposition.py -# - python3 -m unittest test_env_suit.py -# - python3 -m unittest test_survey.py -# - python3 -m unittest test_advisory.py + - python3 -m unittest test_deposition.py + - python3 -m unittest test_env_suit.py + - python3 -m unittest test_survey.py + - python3 -m unittest test_advisory.py - python -m coverage report - python -m coverage html -d $CI_PROJECT_DIR/coverage - ls diff --git a/tests/integration/test_advisory.py b/tests/integration/test_advisory.py index c95e9bd..4c96d87 100644 --- a/tests/integration/test_advisory.py +++ b/tests/integration/test_advisory.py @@ -7,17 +7,35 @@ from integration.integration_test_utils import IntegrationTestUtils 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 = IntegrationTestUtils.load_json_file(default_config) + TEST_OUT_PATH: str = "not_set" + TEST_RUN_DATE: str = '20221001' + TEST_JOB_DIR: str = "SUMMARY_" + TEST_RUN_DATE - def test_env_suit_standard_inputs_expected_results1(self): + @classmethod + def setUpClass(cls) -> None: + TestEnvSuit.write_temp_run_config_file() + TestEnvSuit.run_advisory_pipeline() + + @staticmethod + def write_temp_run_config_file(): nowstring: str = IntegrationTestUtils.get_now_string() prefix: str = "temp_advisory_" + nowstring # prefix: str = "" + default_config = IntegrationTestUtils.DEFAULT_CONFIG_FILE_PATH + default_config_dict: dict = IntegrationTestUtils.load_json_file(default_config) + run_dict: dict = copy.deepcopy(default_config_dict) + TestEnvSuit.TEST_OUT_PATH = run_dict['WorkspacePathout'] + prefix + os.sep + run_dict['WorkspacePathout'] = TestEnvSuit.TEST_OUT_PATH + run_dict['WorkspacePath'] = TestEnvSuit.TEST_OUT_PATH + run_dict['ServerName'] = '' # nothing, as local machine + + IntegrationTestUtils.write_json_file(run_dict, IntegrationTestUtils.TEMP_CONFIG_FILE_PATH) + + @staticmethod + def run_advisory_pipeline(): + os.environ["EMAIL_CRED"] = "../test_data/test_deployment/envs/Cred_gmail.json" from Processor import run_Process, set_log_level args_dict: dict = {} @@ -29,20 +47,30 @@ class TestEnvSuit(unittest.TestCase): args_dict['noupload'] = True set_log_level(args_dict['log_level']) - run_dict: dict = copy.deepcopy(self.default_config_dict) - test_out_path = run_dict['WorkspacePathout'] + prefix + os.sep - run_dict['WorkspacePathout'] = test_out_path - run_dict['WorkspacePath'] = test_out_path - run_dict['ServerName'] = '' # nothing, as local machine + IntegrationTestUtils.unpack_zip(IntegrationTestUtils.EXAMPLE_SURVEY_FILE_PATH, TestEnvSuit.TEST_OUT_PATH) + IntegrationTestUtils.unpack_zip(IntegrationTestUtils.EXAMPLE_DEPO_FILE_PATH, TestEnvSuit.TEST_OUT_PATH) + IntegrationTestUtils.unpack_zip(IntegrationTestUtils.EXAMPLE_ENV_SUIT_FILE_PATH, TestEnvSuit.TEST_OUT_PATH) - IntegrationTestUtils.write_json_file(run_dict, IntegrationTestUtils.TEMP_CONFIG_FILE_PATH) + run_Process(args_dict) - IntegrationTestUtils.unpack_zip(IntegrationTestUtils.EXAMPLE_SURVEY_FILE_PATH, test_out_path) - IntegrationTestUtils.unpack_zip(IntegrationTestUtils.EXAMPLE_DEPO_FILE_PATH, test_out_path) - IntegrationTestUtils.unpack_zip(IntegrationTestUtils.EXAMPLE_ENV_SUIT_FILE_PATH, test_out_path) + def test_standard_run_input_status_success(self): + status_file_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.TEST_JOB_DIR, "STATUS_SUCCESS") + success_file_exists: bool = os.path.isfile(status_file_path) + self.assertTrue(success_file_exists) - run_Process(args_dict) - self.assertTrue(True) + def test_standard_run_input_all_docs_produced(self): + + east_africa_image_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.TEST_JOB_DIR, + "tight-layout", + "wheat_rust_advisory_template_EastAfrica_20221001.docx") + ethiopia_image_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.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) if __name__ == '__main__': diff --git a/tests/integration/test_env_suit.py b/tests/integration/test_env_suit.py index d2dbd55..e557528 100644 --- a/tests/integration/test_env_suit.py +++ b/tests/integration/test_env_suit.py @@ -6,15 +6,15 @@ from integration.integration_test_utils import IntegrationTestUtils class TestEnvSuit(unittest.TestCase): + TEST_OUT_PATH: str = "not_set" TEST_RUN_DATE: str = '20221001' TEST_JOB_DIR: str = "ENVIRONMENT_2.0_" + TEST_RUN_DATE - @classmethod def setUpClass(cls) -> None: TestEnvSuit.write_temp_run_config_file() - # TestEnvSuit.run_env_pipeline() + TestEnvSuit.run_env_pipeline() @staticmethod -- GitLab