New service_api_client to get stats for variable days
This commit is contained in:
Rebecca Law
2018-07-25 10:47:29 +01:00
parent 0081a70d4b
commit e806cf036e
6 changed files with 33 additions and 11 deletions

View File

@@ -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

View File

@@ -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(

View File

@@ -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)

View File

@@ -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,

View File

@@ -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):

View File

@@ -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(