mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 03:13:42 -05:00
Use arguments rather than passing around a dict
This makes it harder to write code which will pass tests but fail in real life.
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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'
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user