mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-03-12 22:32:18 -04:00
Merge pull request #4105 from alphagov/post-on-search
Update `get_notifications_for_service` to make POST requests
This commit is contained in:
@@ -19,7 +19,6 @@ class NotificationApiClient(NotifyAdminAPIClient):
|
||||
to=None,
|
||||
include_one_off=None,
|
||||
):
|
||||
# TODO: if "to" is included, this should be a POST
|
||||
params = {
|
||||
'page': page,
|
||||
'page_size': page_size,
|
||||
@@ -35,17 +34,22 @@ class NotificationApiClient(NotifyAdminAPIClient):
|
||||
|
||||
params = {k: v for k, v in params.items() if v is not None}
|
||||
|
||||
# if `to` is set it is likely PII like an email address or mobile which
|
||||
# we do not want in our logs, so we do a POST request instead of a GET
|
||||
method = self.post if to else self.get
|
||||
kwargs = {'data': params} if to else {'params': params}
|
||||
|
||||
if job_id:
|
||||
return self.get(
|
||||
return method(
|
||||
url='/service/{}/job/{}/notifications'.format(service_id, job_id),
|
||||
params=params
|
||||
**kwargs
|
||||
)
|
||||
else:
|
||||
if limit_days is not None:
|
||||
params['limit_days'] = limit_days
|
||||
return self.get(
|
||||
return method(
|
||||
url='/service/{}/notifications'.format(service_id),
|
||||
params=params
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def send_notification(self, service_id, *, template_id, recipient, personalisation, sender_id):
|
||||
|
||||
@@ -23,6 +23,10 @@ from tests import notification_json, single_notification_json
|
||||
{'include_from_test_key': True},
|
||||
{'url': '/service/abcd1234/notifications', 'params': {'include_from_test_key': True}}
|
||||
),
|
||||
(
|
||||
{'page': 48, 'limit_days': 3},
|
||||
{'url': '/service/abcd1234/notifications', 'params': {'page': 48, 'limit_days': 3}}
|
||||
),
|
||||
(
|
||||
{'job_id': 'efgh5678'},
|
||||
{'url': '/service/abcd1234/job/efgh5678/notifications', 'params': {}}
|
||||
@@ -30,7 +34,11 @@ from tests import notification_json, single_notification_json
|
||||
(
|
||||
{'job_id': 'efgh5678', 'page': 48},
|
||||
{'url': '/service/abcd1234/job/efgh5678/notifications', 'params': {'page': 48}}
|
||||
)
|
||||
),
|
||||
(
|
||||
{'job_id': 'efgh5678', 'page': 48, 'limit_days': 3},
|
||||
{'url': '/service/abcd1234/job/efgh5678/notifications', 'params': {'page': 48}}
|
||||
),
|
||||
])
|
||||
def test_client_gets_notifications_for_service_and_job_by_page(mocker, arguments, expected_call):
|
||||
|
||||
@@ -39,6 +47,35 @@ def test_client_gets_notifications_for_service_and_job_by_page(mocker, arguments
|
||||
mock_get.assert_called_once_with(**expected_call)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arguments,expected_call", [
|
||||
(
|
||||
{'to': "0793433"},
|
||||
{'url': '/service/abcd1234/notifications', 'data': {'to': "0793433"}}
|
||||
),
|
||||
(
|
||||
{'to': "0793433", 'job_id': 'efgh5678'},
|
||||
{'url': '/service/abcd1234/job/efgh5678/notifications', 'data': {'to': "0793433"}}
|
||||
),
|
||||
(
|
||||
{'to': "0793433", 'page': 99},
|
||||
{'url': '/service/abcd1234/notifications', 'data': {'to': "0793433", 'page': 99}}
|
||||
),
|
||||
(
|
||||
{'to': "0793433", 'limit_days': 3},
|
||||
{'url': '/service/abcd1234/notifications', 'data': {'to': "0793433", 'limit_days': 3}}
|
||||
),
|
||||
(
|
||||
{'to': "0793433", 'job_id': 'efgh5678', 'limit_days': 3},
|
||||
{'url': '/service/abcd1234/job/efgh5678/notifications', 'data': {'to': "0793433"}}
|
||||
),
|
||||
])
|
||||
def test_client_gets_notifications_for_service_and_job_by_page_posts_for_to(mocker, arguments, expected_call):
|
||||
|
||||
mock_post = mocker.patch('app.notify_client.notification_api_client.NotificationApiClient.post')
|
||||
NotificationApiClient().get_notifications_for_service('abcd1234', **arguments)
|
||||
mock_post.assert_called_once_with(**expected_call)
|
||||
|
||||
|
||||
def test_send_notification(mocker, logged_in_client, active_user_with_permissions):
|
||||
mock_post = mocker.patch('app.notify_client.notification_api_client.NotificationApiClient.post')
|
||||
NotificationApiClient().send_notification(
|
||||
|
||||
Reference in New Issue
Block a user