From 25a6788d66422ec5fc29e326c3e718ced4b7c6f7 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 11 Mar 2021 10:52:03 +0000 Subject: [PATCH] Use arguments rather than passing around a dict This makes it harder to write code which will pass tests but fail in real life. --- app/main/views/performance.py | 17 +++++++++-------- app/navigation.py | 4 ++++ .../performance_dashboard_api_client.py | 15 +++++++++++++-- .../test_performance_platform_api_client.py | 14 +++++++++++--- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/main/views/performance.py b/app/main/views/performance.py index 9dce4c4e7..74e3f4835 100644 --- a/app/main/views/performance.py +++ b/app/main/views/performance.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from flask import jsonify +from flask import render_template from app import performance_dashboard_api_client from app.main import main @@ -8,10 +8,11 @@ from app.main import main @main.route("/performance") def performance(): - api_args = {} - - api_args['start_date'] = (datetime.utcnow() - timedelta(days=90)).date() - api_args['end_date'] = datetime.utcnow().date() - - stats = performance_dashboard_api_client.get_performance_dashboard_stats(api_args) - return jsonify(stats) + stats = performance_dashboard_api_client.get_performance_dashboard_stats( + start_date=(datetime.utcnow() - timedelta(days=90)).date(), + end_date=datetime.utcnow().date(), + ) + return render_template( + 'views/performance.html', + **stats + ) diff --git a/app/navigation.py b/app/navigation.py index 58027c8c8..a3bd4c29f 100644 --- a/app/navigation.py +++ b/app/navigation.py @@ -246,6 +246,7 @@ class HeaderNavigation(Navigation): 'organisation_settings', 'organisation_preview_email_branding', 'organisation_preview_letter_branding', + 'performance', 'privacy', 'public_agreement', 'public_download_agreement', @@ -648,6 +649,7 @@ class MainNavigation(Navigation): 'organisation_preview_letter_branding', 'organisation_settings', 'organisations', + 'performance', 'performance_platform_xlsx', 'platform_admin', 'platform_admin_list_complaints', @@ -916,6 +918,7 @@ class CaseworkNavigation(Navigation): 'organisation_preview_letter_branding', 'organisation_settings', 'organisations', + 'performance', 'performance_platform_xlsx', 'platform_admin_list_complaints', 'platform_admin_reports', @@ -1235,6 +1238,7 @@ class OrgNavigation(Navigation): 'old_terms', 'old_using_notify', 'organisations', + 'performance', 'performance_platform_xlsx', 'platform_admin', 'platform_admin_list_complaints', diff --git a/app/notify_client/performance_dashboard_api_client.py b/app/notify_client/performance_dashboard_api_client.py index 20f7d895c..ffb913ca1 100644 --- a/app/notify_client/performance_dashboard_api_client.py +++ b/app/notify_client/performance_dashboard_api_client.py @@ -3,8 +3,19 @@ from app.notify_client import NotifyAdminAPIClient class PerformanceDashboardAPIClient(NotifyAdminAPIClient): - def get_performance_dashboard_stats(self, params_dict=None): - return self.get("/performance-dashboard", params=params_dict) + def get_performance_dashboard_stats( + self, + *, + start_date, + end_date, + ): + return self.get( + '/performance-dashboard', + params={ + 'start_date': str(start_date), + 'end_date': str(end_date), + } + ) performance_dashboard_api_client = PerformanceDashboardAPIClient() diff --git a/tests/app/notify_client/test_performance_platform_api_client.py b/tests/app/notify_client/test_performance_platform_api_client.py index ed516c73c..b9e8cfcd9 100644 --- a/tests/app/notify_client/test_performance_platform_api_client.py +++ b/tests/app/notify_client/test_performance_platform_api_client.py @@ -1,3 +1,5 @@ +from datetime import date + from app.notify_client.performance_dashboard_api_client import ( PerformanceDashboardAPIClient, ) @@ -6,7 +8,13 @@ from app.notify_client.performance_dashboard_api_client import ( def test_get_aggregate_platform_stats(mocker): client = PerformanceDashboardAPIClient() mock = mocker.patch.object(client, 'get') - params_dict = {'start_date': '2021-03-01', 'end_date': '2021-03-31'} - client.get_performance_dashboard_stats(params_dict=params_dict) - mock.assert_called_once_with('/performance-dashboard', params=params_dict) + client.get_performance_dashboard_stats( + start_date=date(2021, 3, 1), + end_date=date(2021, 3, 31), + ) + + mock.assert_called_once_with('/performance-dashboard', params={ + 'start_date': '2021-03-01', + 'end_date': '2021-03-31' + })