From 09f798ea146953622bab67f07ec0dfda62933ad8 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 6 Feb 2020 11:23:50 +0000 Subject: [PATCH] Fix None type error in last-used endpoint. --- app/template_statistics/rest.py | 2 +- tests/app/template_statistics/test_rest.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/template_statistics/rest.py b/app/template_statistics/rest.py index abc011881..3c5653936 100644 --- a/app/template_statistics/rest.py +++ b/app/template_statistics/rest.py @@ -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) diff --git a/tests/app/template_statistics/test_rest.py b/tests/app/template_statistics/test_rest.py index dd0a17998..6733cb293 100644 --- a/tests/app/template_statistics/test_rest.py +++ b/tests/app/template_statistics/test_rest.py @@ -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 ):