Merge pull request #2710 from alphagov/fix-last-used-bug

Fix None type error in last-used endpoint.
This commit is contained in:
Rebecca Law
2020-02-06 11:51:21 +00:00
committed by GitHub
2 changed files with 12 additions and 1 deletions

View File

@@ -64,4 +64,4 @@ def get_last_used_datetime_for_template(service_id, template_id):
last_date_used = dao_get_last_date_template_was_used(template_id=template_id,
service_id=service_id)
return jsonify(last_date_used=last_date_used.strftime(DATETIME_FORMAT))
return jsonify(last_date_used=last_date_used.strftime(DATETIME_FORMAT) if last_date_used else last_date_used)

View File

@@ -210,6 +210,17 @@ def test_get_last_used_datetime_for_template(
assert json_resp['last_date_used'] == date_from_notification.strftime(DATETIME_FORMAT)
def test_get_last_used_datetime_for_template_returns_none_if_no_usage_of_template(
admin_request, sample_template
):
json_resp = admin_request.get(
'template_statistics.get_last_used_datetime_for_template',
service_id=str(sample_template.service_id),
template_id=sample_template.id
)
assert json_resp['last_date_used'] is None
def test_get_last_used_datetime_for_template_returns_400_if_service_does_not_exist(
admin_request, sample_template
):