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

Delete reports instead of hiding them #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions daily_read/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions daily_read/order_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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
Expand Down
15 changes: 4 additions & 11 deletions tests/test_order_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading