diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 520888e04..a139d4b7e 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -38,7 +38,7 @@ def service_dashboard(service_id): return render_template( 'views/dashboard/dashboard.html', statistics=add_rates_to( - statistics_api_client.get_statistics_for_service(service_id)['data'] + statistics_api_client.get_statistics_for_service(service_id, limit_days=7)['data'] ), templates=service_api_client.get_service_templates(service_id)['data'], template_statistics=aggregate_usage( @@ -50,15 +50,11 @@ def service_dashboard(service_id): @main.route("/services//dashboard.json") @login_required def service_dashboard_updates(service_id): - - statistics = statistics_api_client.get_statistics_for_service(service_id)['data'] - template_statistics = aggregate_usage(template_statistics_client.get_template_statistics_for_service(service_id)) - return jsonify(**{ 'today': render_template( 'views/dashboard/today.html', statistics=add_rates_to( - statistics_api_client.get_statistics_for_service(service_id)['data'] + statistics_api_client.get_statistics_for_service(service_id, limit_days=7)['data'] ), template_statistics=aggregate_usage( template_statistics_client.get_template_statistics_for_service(service_id) diff --git a/app/notify_client/statistics_api_client.py b/app/notify_client/statistics_api_client.py index 9ef40bbd6..3d4292c36 100644 --- a/app/notify_client/statistics_api_client.py +++ b/app/notify_client/statistics_api_client.py @@ -12,7 +12,10 @@ class StatisticsApiClient(BaseAPIClient): self.client_id = app.config['ADMIN_CLIENT_USER_NAME'] self.secret = app.config['ADMIN_CLIENT_SECRET'] - def get_statistics_for_service(self, service_id): + def get_statistics_for_service(self, service_id, limit_days=None): + params = {} + if limit_days is not None: + params['limit_days'] = limit_days return self.get( url='/service/{}/notifications-statistics'.format(service_id), ) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 5fd096c9b..9717e60c2 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -77,7 +77,7 @@ def test_should_show_recent_templates_on_dashboard(app_, assert response.status_code == 200 response.get_data(as_text=True) - mock_get_service_statistics.assert_called_once_with(SERVICE_ONE_ID) + mock_get_service_statistics.assert_called_once_with(SERVICE_ONE_ID, limit_days=7) mock_template_stats.assert_called_once_with(SERVICE_ONE_ID) page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') diff --git a/tests/conftest.py b/tests/conftest.py index 8a522ea89..9bb02a77c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -172,7 +172,7 @@ def mock_delete_service(mocker, mock_get_service): @pytest.fixture(scope='function') def mock_get_service_statistics(mocker): - def _create(service_id): + def _create(service_id, limit_days=None): return {'data': [{}]} return mocker.patch(