Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #119 from communitiesuk/FPASF-143-fix-download-report
Browse files Browse the repository at this point in the history
FPASF-143: fix download report
  • Loading branch information
gidsg authored Jun 14, 2024
2 parents bd18752 + 22e597e commit df286df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ def download():
content_type, file_content = process_api_response(query_params)

current_app.logger.info(
"Request for download by {user_id=} with {query_params=}",
"Request for download by {user_id} with {query_params}",
extra={
"user_id": g.account_id,
"email": g.user.email,
"query_params": query_params,
"request_type": "download",
},
)
return send_file(
Expand Down
4 changes: 2 additions & 2 deletions scripts/extract_download_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def main(args):
logGroupName=f"/copilot/post-award-{ENVIRONMENT}-data-frontend",
queryString="""fields @timestamp, @message
| sort @timestamp asc
| limit 1000
| filter request_type = 'download'""",
| limit 10000
| filter message LIKE /Request for download./ OR request_type = 'download'""",
startTime=int(datetime.datetime.timestamp(start_time)),
endTime=int(datetime.datetime.timestamp(end_time)),
)["queryId"]
Expand Down
11 changes: 11 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest


@pytest.mark.usefixtures("mock_get_response_xlsx")
def test_download_logging(flask_test_client, caplog):
flask_test_client.post("/download", data={"file_format": "xlsx"})
log_line = [record for record in caplog.records if hasattr(record, "request_type")]
assert len(log_line) == 1
assert log_line[0].request_type == "download"
assert log_line[0].user_id == "test-user"
assert log_line[0].query_params == {"file_format": "xlsx"}

0 comments on commit df286df

Please sign in to comment.