From 7a9be92f3f32c5b011558c1d955fbc502732edc8 Mon Sep 17 00:00:00 2001 From: Anandashankar Anil Date: Thu, 3 Oct 2024 17:49:43 +0200 Subject: [PATCH] Delete reports instead of hiding them --- daily_read/__main__.py | 4 ++-- daily_read/order_portal.py | 10 ++++++---- tests/test_order_portal.py | 15 ++++----------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/daily_read/__main__.py b/daily_read/__main__.py index a0c7065..21b9ba3 100644 --- a/daily_read/__main__.py +++ b/daily_read/__main__.py @@ -96,8 +96,8 @@ def generate_all(ctx, upload=False, develop=False): for owner in modified_orders: if upload: report = daily_rep.populate_and_write_report(owner, modified_orders[owner], config_values.STATUS_PRIORITY) - # Publish reports with published, hide reports with review - for upload_category, report_state in {"projects": "published", "delete_report_for": "review"}.items(): + # Publish reports with published, delete reports with delete + for upload_category, report_state in {"projects": "published", "delete_report_for": "delete"}.items(): for status in modified_orders[owner][upload_category].keys(): for project in modified_orders[owner][upload_category][status]: request_success = False diff --git a/daily_read/order_portal.py b/daily_read/order_portal.py index 16ad814..e53d4b0 100644 --- a/daily_read/order_portal.py +++ b/daily_read/order_portal.py @@ -139,7 +139,7 @@ def sorting_key(item): def upload_report_to_order_portal(self, report, project, status): """Upload report to order portal With the status 'published' the user can see the report immediately - With the status 'review', the user will not be able to view the report(used here as a proxy for deletion) + With the status 'delete', the report will be deleted from the order portal """ # Encoded to utf-8 to display special characters properly add_to_url = "" @@ -159,10 +159,12 @@ def upload_report_to_order_portal(self, report, project, status): content_type="text/html", ) - # TODO: check Encoded to utf-8 to display special characters properly - response = requests.post(url, headers=self.headers, json=indata) + # TODO: check Encoded to utf-8 to display special characters properly + response = requests.post(url, headers=self.headers, json=indata) + elif status == "delete": + response = requests.delete(url, headers=self.headers) - operation = "updated" if report else "hidden" + operation = "updated" if report else "deleted" if response.status_code == 200: log.info(f"Report {operation} for order with project id: {project.project_id}") return True diff --git a/tests/test_order_portal.py b/tests/test_order_portal.py index e51d374..c6f7301 100644 --- a/tests/test_order_portal.py +++ b/tests/test_order_portal.py @@ -130,20 +130,13 @@ def test_get_and_process_orders_open_to_aborted_with_report_and_upload( modified_orders = op.process_orders(config_values.STATUS_PRIORITY_REV) assert modified_orders[orderer]["delete_report_for"]["Library QC Finished"][0] == data_master.data[order_id] - with mock.patch("daily_read.order_portal.requests.post") as mock_post: - mock_post.return_value.status_code = 200 + with mock.patch("daily_read.order_portal.requests.delete") as mock_delete: + mock_delete.return_value.status_code = 204 op.upload_report_to_order_portal( - "", modified_orders[orderer]["delete_report_for"]["Library QC Finished"][0], "review" + "", modified_orders[orderer]["delete_report_for"]["Library QC Finished"][0], "delete" ) url = f"{config_values.ORDER_PORTAL_URL}/api/v1/report/{op.all_orders[4]['reports'][0]['iuid']}" - indata = dict( - order=order_id, - name="Project Progress", - status="review", - ) - mock_post.assert_called_once_with( - url, headers={"X-OrderPortal-API-key": config_values.ORDER_PORTAL_API_KEY}, json=indata - ) + mock_delete.assert_called_once_with(url, headers={"X-OrderPortal-API-key": config_values.ORDER_PORTAL_API_KEY}) def test_get_and_process_orders_closed(data_repo_full, mock_project_data_record, get_env_file_path):