Skip to content

Commit

Permalink
Merge pull request #41 from aanil/fix_git
Browse files Browse the repository at this point in the history
Fix for when files are committed, log message changes
  • Loading branch information
aanil authored May 29, 2024
2 parents 002caa9 + e2af7c0 commit 61f9b7a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions daily_read/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)


Expand Down
6 changes: 3 additions & 3 deletions daily_read/order_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/test_order_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_get_and_process_orders_open_upload_fail(data_repo_full, mock_project_da
"<html>test data</html>", 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):
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 61f9b7a

Please sign in to comment.