use service statistics endpoint instead of detailed service

we're not actually looking at the detailed service aspects - just
the stats. We're doing this in three places:

* dashboard
* notification activity page
* when checking jobs to see if we're over the daily limit

change these places to use a new api endpoint (service/id/statistics),
which hopefully be a little more performant, and will definitely be a
little more organised - moving away from generic endpoints with loads
of optional parameters.

We still need the detailed endpoints for the platform admin page tho.

Depends on https://github.com/alphagov/notifications-api/pull/1865
This commit is contained in:
Leo Hemsted
2018-05-09 13:53:02 +01:00
parent e47a459757
commit 78a6f86043
11 changed files with 93 additions and 136 deletions

View File

@@ -27,20 +27,23 @@ def test_client_posts_archived_true_when_deleting_template(mocker):
mock_post.assert_called_once_with(expected_url, data=expected_data)
@pytest.mark.parametrize(
'function,params', [
(ServiceAPIClient.get_service, {}),
(ServiceAPIClient.get_detailed_service, {'detailed': True}),
(ServiceAPIClient.get_detailed_service_for_today, {'detailed': True, 'today_only': True})
],
ids=lambda x: x.__name__
)
def test_client_gets_service(mocker, function, params):
def test_client_gets_service(mocker):
client = ServiceAPIClient()
mock_get = mocker.patch.object(client, 'get', return_value={})
function(client, 'foo')
mock_get.assert_called_once_with('/service/foo', params=params)
client.get_service('foo')
mock_get.assert_called_once_with('/service/foo')
@pytest.mark.parametrize('today_only', [True, False])
def test_client_gets_service_statistics(mocker, today_only):
client = ServiceAPIClient()
mock_get = mocker.patch.object(client, 'get', return_value={'data': {'a': 'b'}})
ret = client.get_service_statistics('foo', today_only)
assert ret == {'a': 'b'}
mock_get.assert_called_once_with('/service/foo/statistics', params={'today_only': today_only})
def test_client_only_updates_allowed_attributes(mocker):
@@ -169,7 +172,7 @@ def test_client_returns_count_of_service_templates(
],
None,
[
call('/service/{}'.format(SERVICE_ONE_ID), params={})
call('/service/{}'.format(SERVICE_ONE_ID))
],
[
call(