diff --git a/daily_read/order_portal.py b/daily_read/order_portal.py index eba449e..16ad814 100644 --- a/daily_read/order_portal.py +++ b/daily_read/order_portal.py @@ -116,7 +116,8 @@ def process_orders(self, priority, closed_before_in_days=30): order_updates_item = order_updates[proj_info.orderer] if delete_report: - order_updates_item["delete_report_for"].setdefault(proj_info.status, []).append(proj_info) + if order["reports"]: + order_updates_item["delete_report_for"].setdefault(proj_info.status, []).append(proj_info) else: order_updates_item["events"] += proj_info.events diff --git a/tests/conftest.py b/tests/conftest.py index bf6b7b5..c2bf6cb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,6 +33,14 @@ "internal_proj_status": "Ongoing", } +dummy_order_closed_no_report = { + "orderer": "dummy@dummy.se", + "project_dates": {}, + "internal_id": "P123462", + "internal_name": "D.Dummysson_23_02", + "internal_proj_status": "Ongoing", +} + order_portal_resp_order_processing = { "identifier": "NGI123456", "title": "Test run with nano", @@ -161,7 +169,19 @@ }, }, "status": "closed", - "reports": [], + "reports": [ + { + "iuid": "c5ee943", + "name": "Project Progress", + "filename": "project_progress.html", + "status": "published", + "modified": "2024-01-15T15:09:18.732Z", + "links": { + "api": {"href": "https://orderportal.example.com/orders/api/v1/report/c5ee943"}, + "file": {"href": "https://orderportal.example.com/orders/report/c5ee943"}, + }, + }, + ], "history": { "preparation": "2023-07-06", "submitted": "2023-07-06", @@ -187,6 +207,10 @@ }, } +order_portal_resp_order_closed_no_report = copy.deepcopy(order_portal_resp_order_closed) +order_portal_resp_order_closed_no_report["identifier"] = "NGI123462" +order_portal_resp_order_closed_no_report["reports"] = [] + def _create_all_files(file_list, data_location): """Helper method to create files in file_list inside data_location""" @@ -344,6 +368,16 @@ def _method(status): config_values.STATUS_PRIORITY_REV, dummy_order_closed["internal_proj_status"], ) + if status == "closed_no_report": + mock_record = ngi_data.ProjectDataRecord( + "NGIS/2023/staged_file2.json", + dummy_order_closed_no_report["orderer"], + dummy_order_closed_no_report["project_dates"], + dummy_order_closed_no_report["internal_id"], + dummy_order_closed_no_report["internal_name"], + config_values.STATUS_PRIORITY_REV, + dummy_order_closed_no_report["internal_proj_status"], + ) if status == "open_with_report": mock_record = ngi_data.ProjectDataRecord( "NGIS/2023/NGI123453.json", @@ -389,6 +423,7 @@ def json(self): order_portal_resp_order_processing_mult_reports, order_portal_resp_order_processing_single_report, order_portal_resp_order_processing_to_aborted, + order_portal_resp_order_closed_no_report, ] } diff --git a/tests/test_order_portal.py b/tests/test_order_portal.py index 14cc3b3..e51d374 100644 --- a/tests/test_order_portal.py +++ b/tests/test_order_portal.py @@ -164,6 +164,24 @@ def test_get_and_process_orders_closed(data_repo_full, mock_project_data_record, assert modified_orders[orderer]["delete_report_for"]["All Raw Data Delivered"][0] == data_master.data[order_id] +def test_get_and_process_orders_closed_no_report(data_repo_full, mock_project_data_record, get_env_file_path): + """Test getting and processing an order closed within the timeframe of Project progress report deletion""" + orderer = "dummy@dummy.se" + order_id = "NGI123462" + config_values = config.Config(get_env_file_path) + with mock.patch("daily_read.statusdb.StatusDBSession"): + data_master = ngi_data.ProjectDataMaster(config_values) + + data_master.data = {order_id: mock_project_data_record("closed_no_report")} + + op = order_portal.OrderPortal(config_values, data_master) + op.get_orders(orderer=orderer) + + assert op.all_orders[5]["identifier"] == order_id + modified_orders = op.process_orders(config_values.STATUS_PRIORITY_REV) + assert not modified_orders[orderer]["delete_report_for"] + + def test_get_and_process_orders_mult_reports(data_repo_full, mock_project_data_record, get_env_file_path): """Test getting and processing orders with multiple Project progress reports""" orderer = "dummy@dummy.se"