pass 'today_only' flag to the back-end from send page

also bump notification-utils requirement to 8.7.0 for changes
to RecipientCSV
This commit is contained in:
Leo Hemsted
2016-07-25 15:26:43 +01:00
parent 45debe0d5b
commit eaf9b6dc54
3 changed files with 24 additions and 17 deletions

View File

@@ -42,13 +42,13 @@ class ServiceAPIClient(NotificationsAPIClient):
return self.delete(endpoint, data)
def get_service(self, service_id):
return self._get_service(service_id, False, today_only=False)
return self._get_service(service_id, detailed=False, today_only=False)
def get_detailed_service(self, service_id):
return self._get_service(service_id, True, today_only=False)
return self._get_service(service_id, detailed=True, today_only=False)
def get_detailed_service_for_today(self, service_id):
return self._get_service(service_id, False, today_only=True)
return self._get_service(service_id, detailed=True, today_only=True)
def _get_service(self, service_id, detailed, today_only):
"""
@@ -57,7 +57,12 @@ class ServiceAPIClient(NotificationsAPIClient):
:param detailed - return additional details, including notification statistics
:param today_only - return statistics only for today. No effect if detailed not passed in
"""
params = {'detailed': True} if detailed else {}
params = {}
if detailed:
params['detailed'] = detailed
if today_only:
params['today_only'] = today_only
return self.get(
'/service/{0}'.format(service_id),
params=params)

View File

@@ -19,4 +19,4 @@ pytz==2016.4
git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0
git+https://github.com/alphagov/notifications-utils.git@8.4.2#egg=notifications-utils==8.4.2
git+https://github.com/alphagov/notifications-utils.git@8.7.0#egg=notifications-utils==8.7.0

View File

@@ -1,3 +1,5 @@
import pytest
from app.notify_client.service_api_client import ServiceAPIClient
from tests.conftest import fake_uuid
@@ -21,17 +23,17 @@ def test_client_posts_archived_true_when_deleting_template(mocker):
mock_post.assert_called_once_with(expected_url, data=expected_data)
def test_client_gets_service_with_no_params(mocker):
@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):
client = ServiceAPIClient()
mock_post = mocker.patch('app.notify_client.service_api_client.ServiceAPIClient.get')
mock_post = mocker.patch.object(client, 'get')
client.get_service('foo')
mock_post.assert_called_once_with('/service/foo', params={})
def test_client_gets_service_with_detailed_params(mocker):
client = ServiceAPIClient()
mock_post = mocker.patch('app.notify_client.service_api_client.ServiceAPIClient.get')
client.get_detailed_service('foo')
mock_post.assert_called_once_with('/service/foo', params={'detailed': True})
function(client, 'foo')
mock_post.assert_called_once_with('/service/foo', params=params)