Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only hide report if the the order has a report #45

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion daily_read/order_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 36 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
"internal_proj_status": "Ongoing",
}

dummy_order_closed_no_report = {
"orderer": "[email protected]",
"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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"""
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
]
}

Expand Down
18 changes: 18 additions & 0 deletions tests/test_order_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
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 = "[email protected]"
Expand Down
Loading