diff --git a/daily_read/__init__.py b/daily_read/__init__.py index b7a88be..75cc646 100644 --- a/daily_read/__init__.py +++ b/daily_read/__init__.py @@ -1,4 +1,3 @@ -""" DailyRead version -""" +"""DailyRead version""" __version__ = "0.0.1" 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..8240a41 100644 --- a/daily_read/order_portal.py +++ b/daily_read/order_portal.py @@ -58,7 +58,7 @@ def get_orders(self, node=None, status=None, orderer=None, recent=True): try: self.all_orders = self.all_orders + response.json()["items"] - except requests.exceptions.JSONDecodeError as e: + except requests.exceptions.JSONDecodeError: log.critical( f"Could not fetch orders for {{node: {node}, status: {status}, orderer={orderer}, recent={recent}}}" ) @@ -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,11 +159,14 @@ 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" - if response.status_code == 200: + operation = "updated" if report else "deleted" + # 200 OK or 204 No Content for successful report upload and deletion respectively + if response.status_code == 200 or response.status_code == 204: log.info(f"Report {operation} for order with project id: {project.project_id}") return True else: 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):