diff --git a/daily_read/__main__.py b/daily_read/__main__.py index 04d797e..a0c7065 100644 --- a/daily_read/__main__.py +++ b/daily_read/__main__.py @@ -100,20 +100,18 @@ def generate_all(ctx, upload=False, develop=False): for upload_category, report_state in {"projects": "published", "delete_report_for": "review"}.items(): for status in modified_orders[owner][upload_category].keys(): for project in modified_orders[owner][upload_category][status]: - uploaded = False + request_success = False report_upload = report if upload_category == "projects" else "" try: - uploaded = op.upload_report_to_order_portal(report_upload, project, report_state) - # Stage changes only if report was uploaded - if uploaded: + request_success = op.upload_report_to_order_portal(report_upload, project, report_state) + # Stage changes + if request_success: op.projects_data.stage_data_for_project(project) # catch any and every exception during upload except Exception as e: log.error( f"Exception Raised: Issue in uploading/hiding reports for {project.project_id}: {e}\nContinuing to next project" ) - # Commit all uploaded projects - op.projects_data.commit_staged_data(f"Commit reports updates for {datetime.datetime.now()}") else: log.info("Saving report to disk instead of uploading") @@ -123,6 +121,10 @@ def generate_all(ctx, upload=False, develop=False): config_values.STATUS_PRIORITY, out_dir=config_values.REPORTS_LOCATION, ) + if upload: + # Commit all uploaded projects + op.projects_data.commit_staged_data(f"Commit reports updates for {datetime.datetime.now()}") + daily_read.utils.error_reporting(log) diff --git a/daily_read/order_portal.py b/daily_read/order_portal.py index 1b58224..eba449e 100644 --- a/daily_read/order_portal.py +++ b/daily_read/order_portal.py @@ -161,12 +161,12 @@ def upload_report_to_order_portal(self, report, project, status): # TODO: check Encoded to utf-8 to display special characters properly response = requests.post(url, headers=self.headers, json=indata) + operation = "updated" if report else "hidden" if response.status_code == 200: - operation = "Updated" if report else "Hid" - log.info(f"{operation} report for order with project id: {project.project_id}") + log.info(f"Report {operation} for order with project id: {project.project_id}") return True else: log.error( - f"Report not uploaded for order with project id: {project.project_id}\nReason: {response.status_code} {response.reason}" + f"Report not {operation} for order with project id: {project.project_id}\nReason: {response.status_code} {response.reason}" ) return False diff --git a/tests/test_order_portal.py b/tests/test_order_portal.py index 5a24687..d77b202 100644 --- a/tests/test_order_portal.py +++ b/tests/test_order_portal.py @@ -29,7 +29,7 @@ def test_get_and_process_orders_open_upload_fail(data_repo_full, mock_project_da "test data", modified_orders[orderer]["projects"]["Library QC finished"][0], "published" ) assert not uploaded - assert f"Report not uploaded for order with project id: {order_id}\nReason: 404" in caplog.text + assert f"Report not updated for order with project id: {order_id}\nReason: 404" in caplog.text def test_get_and_process_orders_open_and_upload(data_repo_full, mock_project_data_record, get_env_file_path): @@ -108,7 +108,7 @@ def test_get_and_process_orders_open_with_report_and_upload( mock_post.assert_called_once_with( url, headers={"X-OrderPortal-API-key": config_values.ORDER_PORTAL_API_KEY}, json=indata ) - assert f"Updated report for order with project id: {order_id}" in caplog.text + assert f"Report updated for order with project id: {order_id}" in caplog.text def test_get_and_process_orders_open_to_aborted_with_report_and_upload(