From 6e654b29a6baec87eb72c1c34e8dc4211f29eb41 Mon Sep 17 00:00:00 2001 From: Anandashankar Anil Date: Thu, 20 Jun 2024 16:06:54 +0200 Subject: [PATCH 1/3] Status fix for projects with dates that could have been closed or aborted --- daily_read/ngi_data.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/daily_read/ngi_data.py b/daily_read/ngi_data.py index a2ddf75..1a78feb 100644 --- a/daily_read/ngi_data.py +++ b/daily_read/ngi_data.py @@ -278,8 +278,13 @@ def __init__( else: self.status = latest_statuses[0] else: - log.info(f"No project dates found for {project_id}, so setting its status to Pending") - self.status = "Pending" + log.info(f"No project dates found for {project_id}, trying to find status from internal_proj_status") + if internal_proj_status in ["Pending", "Aborted", "Closed"]: + self.status = internal_proj_status + else: + log.error( + f"ERROR! No project dates or incorrect internal_proj_status found for {project_id}, no status set!" + ) @property def internal_id_or_portal_id(self): From b23f81b3c9fc62067bf69cc252336635bd4abc1a Mon Sep 17 00:00:00 2001 From: Anandashankar Anil Date: Thu, 20 Jun 2024 23:52:48 +0200 Subject: [PATCH 2/3] Add tests --- tests/test_ngi_data.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/test_ngi_data.py b/tests/test_ngi_data.py index 5f5461c..4e43a5c 100644 --- a/tests/test_ngi_data.py +++ b/tests/test_ngi_data.py @@ -213,7 +213,28 @@ def test_data_loc_not_dir(mock_status, tmp_path, get_env_file_path): ngi_data.ProjectDataMaster(config_values) -def test_get_data_with_no_project_dates(data_repo_full, mocked_statusdb_conn_rows, caplog, get_env_file_path): +def test_get_data_with_no_project_dates_closed(data_repo_full, mocked_statusdb_conn_rows, caplog, get_env_file_path): + """Test log output when no project dates are found in statusdb for a Closed project""" + from copy import deepcopy + + config_values = config.Config(get_env_file_path) + with mock.patch("daily_read.statusdb.StatusDBSession"): + data_master = ngi_data.ProjectDataMaster(config_values) + data_master.sources[0].statusdb_session.rows.return_value = mocked_statusdb_conn_rows + proj_no_dates = deepcopy(data_master.sources[0].statusdb_session.rows.return_value[1]) + proj_no_dates.value["proj_dates"] = {} + proj_no_dates.value["portal_id"] = "NGI123459" + proj_no_dates.value["project_id"] = "NGI123459" + proj_no_dates.key[1] = "NGI123459" + data_master.sources[0].statusdb_session.rows.return_value.append(proj_no_dates) + with caplog.at_level(logging.INFO): + data_master.get_data("NGI123459") + assert len(data_master.data.keys()) == 1 + assert "NGI123459" in data_master.data + assert "No project dates found for NGI123459, trying to find status from internal_proj_status" in caplog.text + assert data_master.data["NGI123459"].status == "Closed" + +def test_get_data_with_no_project_dates_ongoing(data_repo_full, mocked_statusdb_conn_rows, caplog, get_env_file_path): """Test log output when no project dates are found in statusdb for a specific project""" from copy import deepcopy @@ -224,14 +245,15 @@ def test_get_data_with_no_project_dates(data_repo_full, mocked_statusdb_conn_row proj_no_dates = deepcopy(data_master.sources[0].statusdb_session.rows.return_value[0]) proj_no_dates.value["proj_dates"] = {} proj_no_dates.value["portal_id"] = "NGI123459" + proj_no_dates.value["project_id"] = "NGI123459" + proj_no_dates.key[1] = "NGI123459" data_master.sources[0].statusdb_session.rows.return_value.append(proj_no_dates) with caplog.at_level(logging.INFO): data_master.get_data("NGI123459") assert len(data_master.data.keys()) == 1 assert "NGI123459" in data_master.data - assert "No project dates found for NGI123459, so setting its status to Pending" in caplog.text - assert data_master.data["NGI123459"].status == "Pending" - + assert "No project dates found for NGI123459, trying to find status from internal_proj_status" in caplog.text + assert "ERROR! No project dates or incorrect internal_proj_status found for NGI123459, no status set!" in caplog.text def test_skip_order_with_no_year(data_repo_full, mocked_statusdb_conn_rows, caplog, get_env_file_path): """Test that orders with no order year (i.e. with no contract signed) are skipped""" From 399816abeed7514b75422c35d09ed13c6af2a17e Mon Sep 17 00:00:00 2001 From: Anandashankar Anil Date: Thu, 20 Jun 2024 23:54:19 +0200 Subject: [PATCH 3/3] Black --- tests/test_ngi_data.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_ngi_data.py b/tests/test_ngi_data.py index 4e43a5c..513e6cc 100644 --- a/tests/test_ngi_data.py +++ b/tests/test_ngi_data.py @@ -231,9 +231,12 @@ def test_get_data_with_no_project_dates_closed(data_repo_full, mocked_statusdb_c data_master.get_data("NGI123459") assert len(data_master.data.keys()) == 1 assert "NGI123459" in data_master.data - assert "No project dates found for NGI123459, trying to find status from internal_proj_status" in caplog.text + assert ( + "No project dates found for NGI123459, trying to find status from internal_proj_status" in caplog.text + ) assert data_master.data["NGI123459"].status == "Closed" + def test_get_data_with_no_project_dates_ongoing(data_repo_full, mocked_statusdb_conn_rows, caplog, get_env_file_path): """Test log output when no project dates are found in statusdb for a specific project""" from copy import deepcopy @@ -252,8 +255,14 @@ def test_get_data_with_no_project_dates_ongoing(data_repo_full, mocked_statusdb_ data_master.get_data("NGI123459") assert len(data_master.data.keys()) == 1 assert "NGI123459" in data_master.data - assert "No project dates found for NGI123459, trying to find status from internal_proj_status" in caplog.text - assert "ERROR! No project dates or incorrect internal_proj_status found for NGI123459, no status set!" in caplog.text + assert ( + "No project dates found for NGI123459, trying to find status from internal_proj_status" in caplog.text + ) + assert ( + "ERROR! No project dates or incorrect internal_proj_status found for NGI123459, no status set!" + in caplog.text + ) + def test_skip_order_with_no_year(data_repo_full, mocked_statusdb_conn_rows, caplog, get_env_file_path): """Test that orders with no order year (i.e. with no contract signed) are skipped"""