mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-28 09:59:59 -04:00
add new send_notification api call
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from app.notify_client import NotifyAdminAPIClient
|
||||
from app.notify_client import _attach_current_user, NotifyAdminAPIClient
|
||||
|
||||
|
||||
class NotificationApiClient(NotifyAdminAPIClient):
|
||||
@@ -55,5 +55,14 @@ class NotificationApiClient(NotifyAdminAPIClient):
|
||||
params=params
|
||||
)
|
||||
|
||||
def send_notification(self, service_id, *, template_id, recipient, personalisation=None):
|
||||
data = {
|
||||
'template_id': template_id,
|
||||
'to': recipient,
|
||||
'personalisation': personalisation,
|
||||
}
|
||||
data = _attach_current_user(data)
|
||||
return self.post(url='/service/{}/send-notification'.format(service_id), data=data)
|
||||
|
||||
def get_notification(self, service_id, notification_id):
|
||||
return self.get(url='/service/{}/notifications/{}'.format(service_id, notification_id))
|
||||
|
||||
@@ -35,6 +35,20 @@ def test_client_gets_notifications_for_service_and_job_by_page(mocker, arguments
|
||||
mock_get.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('foo', template_id='bar', recipient='07700900001')
|
||||
mock_post.assert_called_once_with(
|
||||
url='/service/foo/send-notification',
|
||||
data={
|
||||
'template_id': 'bar',
|
||||
'to': '07700900001',
|
||||
'personalisation': None,
|
||||
'created_by': active_user_with_permissions.id
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_get_notification(mocker):
|
||||
mock_get = mocker.patch('app.notify_client.notification_api_client.NotificationApiClient.get')
|
||||
NotificationApiClient().get_notification('foo', 'bar')
|
||||
|
||||
Reference in New Issue
Block a user