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

Commit

Permalink
BAU: Change progress endpoint to post (#132)
Browse files Browse the repository at this point in the history
* BAU: Change progress endpoint to post

- Start posting data as a json body as opposed to query params

* BAU: Fix unit tests for progress post endpoint

* BAU: Add todo comment on local data for post requests
  • Loading branch information
tferns authored Jan 12, 2023
1 parent 3d7702a commit a677356
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
48 changes: 31 additions & 17 deletions app/assess/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,23 @@ def get_assessment_progress(application_metadata):
]
}
endpoint_url = Config.ASSESSMENT_PROGRESS_ENDPOINT
response = get_data(endpoint=endpoint_url, payload=application_ids_list)
if response is not None:
[
x.update({"progress": res.get("progress")})
for res in response
for x in application_metadata
if res["application_id"] == x["application_id"]
]
current_app.logger.info(
f"Fetching assessment progress from '{endpoint_url}', with json"
f" payload: {application_ids_list}."
)
response = requests.post(endpoint_url, json=application_ids_list)

if not response.ok:
current_app.logger.error(
f"Could not get assessment progress for endpoint '{endpoint_url}'"
)
return application_metadata

response_json = response.json()
for res in response_json:
for am in application_metadata:
if am.get("application_id") == res.get("application_id"):
am["progress"] = res.get("progress")

return application_metadata

Expand Down Expand Up @@ -525,16 +534,21 @@ def get_file_response(file_name: str, application_id: str):
)

try:
obj = s3_client.get_object(Bucket=Config.AWS_BUCKET_NAME, Key=prefixed_file_name)

mimetype = obj["ResponseMetadata"]["HTTPHeaders"]["content-type"]
data = obj['Body'].read()
obj = s3_client.get_object(
Bucket=Config.AWS_BUCKET_NAME, Key=prefixed_file_name
)

response = Response(data,
mimetype=mimetype,
headers={'Content-Disposition': f'attachment;filename={file_name}'}
)
mimetype = obj["ResponseMetadata"]["HTTPHeaders"]["content-type"]
data = obj["Body"].read()

response = Response(
data,
mimetype=mimetype,
headers={
"Content-Disposition": f"attachment;filename={file_name}"
},
)
return response
except ClientError as e:
current_app.logger.error(e)
raise Exception(e)
raise Exception(e)
11 changes: 8 additions & 3 deletions app/assess/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,14 @@ def landing():
).assessment_deadline

post_processed_overviews = (
get_assessment_progress(application_overviews)
if application_overviews
else []
(
get_assessment_progress(application_overviews)
if application_overviews
else []
)
# TODO: remove this when we have local data for post requests.
if not Config.USE_LOCAL_DATA
else application_overviews
)

return render_template(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_initialisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def test_flask_initiates(flask_test_client):
If this test succeeds then our flask application
is AT LEAST up and running without errors.
"""
flask_test_client.set_cookie(
"localhost",
"fsd_user_token",
"",
)
response = flask_test_client.get("/", follow_redirects=True)
assert response.status_code == 200

Expand Down

0 comments on commit a677356

Please sign in to comment.