diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index b4906b17a..4c9c31d51 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -321,7 +321,7 @@ def get_dashboard_partials(service_id): add_rate_to_job(job) for job in job_api_client.get_jobs(service_id, limit_days=7, statuses=statuses_to_display)['data'] ] - stats = service_api_client.get_service_statistics(service_id, today_only=False) + stats = service_api_client.get_service_statistics(service_id) column_width, max_notifiction_count = get_column_properties( number_of_columns=( 3 if 'letter' in current_service['permissions'] else 2 diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 5527c6367..a5c1b23be 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -258,7 +258,8 @@ def get_notifications(service_id, message_type, status_override=None): status_filters=get_status_filters( current_service, message_type, - service_api_client.get_service_statistics(service_id, today_only=False) + service_api_client.get_service_statistics(service_id, + limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS']) ) ), 'notifications': render_template( diff --git a/app/main/views/send.py b/app/main/views/send.py index 90c75d01b..c591aa602 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -510,7 +510,7 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_ users = user_api_client.get_users_for_service(service_id=service_id) - statistics = service_api_client.get_service_statistics(service_id, today_only=True) + statistics = service_api_client.get_service_statistics_for_today(service_id) remaining_messages = (current_service['message_limit'] - sum(stat['requested'] for stat in statistics.values())) contents = s3download(service_id, upload_id) diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 6f0ff50bb..bc0e61096 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -384,7 +384,7 @@ def test_upload_csvfile_with_errors_shows_check_page_with_errors( mock_get_service_template_with_placeholders, mock_s3_upload, mock_get_users_by_service, - mock_get_service_statistics, + mock_get_service_statistics_for_today, mock_get_job_doesnt_exist, fake_uuid, ): @@ -509,7 +509,7 @@ def test_upload_csvfile_with_missing_columns_shows_error( mock_get_service_template_with_placeholders, mock_s3_upload, mock_get_users_by_service, - mock_get_service_statistics, + mock_get_service_statistics_for_today, mock_get_job_doesnt_exist, service_one, fake_uuid, @@ -590,7 +590,7 @@ def test_upload_valid_csv_shows_preview_and_table( mock_get_live_service, mock_get_service_template_with_placeholders, mock_get_users_by_service, - mock_get_service_statistics, + mock_get_service_statistics_for_today, mock_get_job_doesnt_exist, mock_s3_set_metadata, fake_uuid, diff --git a/tests/app/notify_client/test_service_api_client.py b/tests/app/notify_client/test_service_api_client.py index 7bc4afd4f..b318da388 100644 --- a/tests/app/notify_client/test_service_api_client.py +++ b/tests/app/notify_client/test_service_api_client.py @@ -35,15 +35,24 @@ def test_client_gets_service(mocker): mock_get.assert_called_once_with('/service/foo') -@pytest.mark.parametrize('today_only', [True, False]) -def test_client_gets_service_statistics(mocker, today_only): +def test_client_gets_service_statistics(mocker): client = ServiceAPIClient() mock_get = mocker.patch.object(client, 'get', return_value={'data': {'a': 'b'}}) - ret = client.get_service_statistics('foo', today_only) + ret = client.get_service_statistics('foo') assert ret == {'a': 'b'} - mock_get.assert_called_once_with('/service/foo/statistics', params={'today_only': today_only}) + mock_get.assert_called_once_with('/service/foo/statistics') + + +def test_client_gets_service_statistics_for_today(mocker): + client = ServiceAPIClient() + mock_get = mocker.patch.object(client, 'get', return_value={'data': {'a': 'b'}}) + + ret = client.get_service_statistics_for_today('foo') + + assert ret == {'a': 'b'} + mock_get.assert_called_once_with('/service/foo/statistics', params={'today_only': True}) def test_client_only_updates_allowed_attributes(mocker): diff --git a/tests/conftest.py b/tests/conftest.py index 9d6f20ee4..d744da947 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -523,7 +523,7 @@ def mock_get_international_service(mocker, api_user_active): @pytest.fixture(scope='function') def mock_get_service_statistics(mocker, api_user_active): - def _get(service_id, today_only): + def _get(service_id, limit_days=7): return { 'email': {'requested': 0, 'delivered': 0, 'failed': 0}, 'sms': {'requested': 0, 'delivered': 0, 'failed': 0}, @@ -533,6 +533,18 @@ def mock_get_service_statistics(mocker, api_user_active): return mocker.patch('app.service_api_client.get_service_statistics', side_effect=_get) +@pytest.fixture(scope='function') +def mock_get_service_statistics_for_today(mocker, api_user_active): + def _get(service_id): + return { + 'email': {'requested': 0, 'delivered': 0, 'failed': 0}, + 'sms': {'requested': 0, 'delivered': 0, 'failed': 0}, + 'letter': {'requested': 0, 'delivered': 0, 'failed': 0} + } + + return mocker.patch('app.service_api_client.get_service_statistics_for_today', side_effect=_get) + + @pytest.fixture(scope='function') def mock_get_detailed_services(mocker, fake_uuid): service_one = service_json(