mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04: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 datetime import datetime, timedelta
|
||||||
|
|
||||||
from flask import jsonify
|
from flask import render_template
|
||||||
|
|
||||||
from app import performance_dashboard_api_client
|
from app import performance_dashboard_api_client
|
||||||
from app.main import main
|
from app.main import main
|
||||||
@@ -8,10 +8,11 @@ from app.main import main
|
|||||||
|
|
||||||
@main.route("/performance")
|
@main.route("/performance")
|
||||||
def performance():
|
def performance():
|
||||||
api_args = {}
|
stats = performance_dashboard_api_client.get_performance_dashboard_stats(
|
||||||
|
start_date=(datetime.utcnow() - timedelta(days=90)).date(),
|
||||||
api_args['start_date'] = (datetime.utcnow() - timedelta(days=90)).date()
|
end_date=datetime.utcnow().date(),
|
||||||
api_args['end_date'] = datetime.utcnow().date()
|
)
|
||||||
|
return render_template(
|
||||||
stats = performance_dashboard_api_client.get_performance_dashboard_stats(api_args)
|
'views/performance.html',
|
||||||
return jsonify(stats)
|
**stats
|
||||||
|
)
|
||||||
|
|||||||
@@ -246,6 +246,7 @@ class HeaderNavigation(Navigation):
|
|||||||
'organisation_settings',
|
'organisation_settings',
|
||||||
'organisation_preview_email_branding',
|
'organisation_preview_email_branding',
|
||||||
'organisation_preview_letter_branding',
|
'organisation_preview_letter_branding',
|
||||||
|
'performance',
|
||||||
'privacy',
|
'privacy',
|
||||||
'public_agreement',
|
'public_agreement',
|
||||||
'public_download_agreement',
|
'public_download_agreement',
|
||||||
@@ -648,6 +649,7 @@ class MainNavigation(Navigation):
|
|||||||
'organisation_preview_letter_branding',
|
'organisation_preview_letter_branding',
|
||||||
'organisation_settings',
|
'organisation_settings',
|
||||||
'organisations',
|
'organisations',
|
||||||
|
'performance',
|
||||||
'performance_platform_xlsx',
|
'performance_platform_xlsx',
|
||||||
'platform_admin',
|
'platform_admin',
|
||||||
'platform_admin_list_complaints',
|
'platform_admin_list_complaints',
|
||||||
@@ -916,6 +918,7 @@ class CaseworkNavigation(Navigation):
|
|||||||
'organisation_preview_letter_branding',
|
'organisation_preview_letter_branding',
|
||||||
'organisation_settings',
|
'organisation_settings',
|
||||||
'organisations',
|
'organisations',
|
||||||
|
'performance',
|
||||||
'performance_platform_xlsx',
|
'performance_platform_xlsx',
|
||||||
'platform_admin_list_complaints',
|
'platform_admin_list_complaints',
|
||||||
'platform_admin_reports',
|
'platform_admin_reports',
|
||||||
@@ -1235,6 +1238,7 @@ class OrgNavigation(Navigation):
|
|||||||
'old_terms',
|
'old_terms',
|
||||||
'old_using_notify',
|
'old_using_notify',
|
||||||
'organisations',
|
'organisations',
|
||||||
|
'performance',
|
||||||
'performance_platform_xlsx',
|
'performance_platform_xlsx',
|
||||||
'platform_admin',
|
'platform_admin',
|
||||||
'platform_admin_list_complaints',
|
'platform_admin_list_complaints',
|
||||||
|
|||||||
@@ -3,8 +3,19 @@ from app.notify_client import NotifyAdminAPIClient
|
|||||||
|
|
||||||
class PerformanceDashboardAPIClient(NotifyAdminAPIClient):
|
class PerformanceDashboardAPIClient(NotifyAdminAPIClient):
|
||||||
|
|
||||||
def get_performance_dashboard_stats(self, params_dict=None):
|
def get_performance_dashboard_stats(
|
||||||
return self.get("/performance-dashboard", params=params_dict)
|
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()
|
performance_dashboard_api_client = PerformanceDashboardAPIClient()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from datetime import date
|
||||||
|
|
||||||
from app.notify_client.performance_dashboard_api_client import (
|
from app.notify_client.performance_dashboard_api_client import (
|
||||||
PerformanceDashboardAPIClient,
|
PerformanceDashboardAPIClient,
|
||||||
)
|
)
|
||||||
@@ -6,7 +8,13 @@ from app.notify_client.performance_dashboard_api_client import (
|
|||||||
def test_get_aggregate_platform_stats(mocker):
|
def test_get_aggregate_platform_stats(mocker):
|
||||||
client = PerformanceDashboardAPIClient()
|
client = PerformanceDashboardAPIClient()
|
||||||
mock = mocker.patch.object(client, 'get')
|
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)
|
client.get_performance_dashboard_stats(
|
||||||
mock.assert_called_once_with('/performance-dashboard', params=params_dict)
|
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