mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 08:21:13 -05:00
Add cancel routes to cbc proxy clients
Also clean the code up a bit.
This commit is contained in:
@@ -62,13 +62,12 @@ class CBCProxyClientBase:
|
|||||||
def send_link_test(
|
def send_link_test(
|
||||||
self,
|
self,
|
||||||
identifier,
|
identifier,
|
||||||
sequential_number,
|
sequential_number
|
||||||
message_format
|
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def create_and_send_broadcast(
|
def create_and_send_broadcast(
|
||||||
self, identifier, message_number, message_format, headline, description, areas, sent, expires,
|
self, identifier, headline, description, areas, sent, expires, message_number=None
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -76,7 +75,7 @@ class CBCProxyClientBase:
|
|||||||
def update_and_send_broadcast(
|
def update_and_send_broadcast(
|
||||||
self,
|
self,
|
||||||
identifier, previous_provider_messages, headline, description, areas,
|
identifier, previous_provider_messages, headline, description, areas,
|
||||||
sent, expires, message_number, message_format
|
sent, expires, message_number=None
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -84,7 +83,7 @@ class CBCProxyClientBase:
|
|||||||
def cancel_broadcast(
|
def cancel_broadcast(
|
||||||
self,
|
self,
|
||||||
identifier, previous_provider_messages, headline, description, areas,
|
identifier, previous_provider_messages, headline, description, areas,
|
||||||
sent, expires, message_number, message_format
|
sent, expires, message_number=None
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -134,7 +133,6 @@ class CBCProxyEE(CBCProxyClientBase):
|
|||||||
identifier,
|
identifier,
|
||||||
sequential_number=None,
|
sequential_number=None,
|
||||||
):
|
):
|
||||||
pass
|
|
||||||
"""
|
"""
|
||||||
link test - open up a connection to a specific provider, and send them an xml payload with a <msgType> of
|
link test - open up a connection to a specific provider, and send them an xml payload with a <msgType> of
|
||||||
test.
|
test.
|
||||||
@@ -150,7 +148,6 @@ class CBCProxyEE(CBCProxyClientBase):
|
|||||||
def create_and_send_broadcast(
|
def create_and_send_broadcast(
|
||||||
self, identifier, headline, description, areas, sent, expires, message_number=None
|
self, identifier, headline, description, areas, sent, expires, message_number=None
|
||||||
):
|
):
|
||||||
pass
|
|
||||||
payload = {
|
payload = {
|
||||||
'message_type': 'alert',
|
'message_type': 'alert',
|
||||||
'identifier': identifier,
|
'identifier': identifier,
|
||||||
@@ -163,6 +160,22 @@ class CBCProxyEE(CBCProxyClientBase):
|
|||||||
}
|
}
|
||||||
self._invoke_lambda(payload=payload)
|
self._invoke_lambda(payload=payload)
|
||||||
|
|
||||||
|
def cancel_broadcast(
|
||||||
|
self,
|
||||||
|
identifier, previous_provider_messages,
|
||||||
|
sent, message_number=None
|
||||||
|
):
|
||||||
|
payload = {
|
||||||
|
'message_type': 'cancel',
|
||||||
|
'identifier': identifier,
|
||||||
|
'message_format': 'cap',
|
||||||
|
"references": [
|
||||||
|
{"message_id": str(message.id), "sent": message.created_at} for message in previous_provider_messages
|
||||||
|
],
|
||||||
|
'sent': sent,
|
||||||
|
}
|
||||||
|
self._invoke_lambda(payload=payload)
|
||||||
|
|
||||||
|
|
||||||
class CBCProxyVodafone(CBCProxyClientBase):
|
class CBCProxyVodafone(CBCProxyClientBase):
|
||||||
lambda_name = 'vodafone-1-proxy'
|
lambda_name = 'vodafone-1-proxy'
|
||||||
@@ -172,7 +185,6 @@ class CBCProxyVodafone(CBCProxyClientBase):
|
|||||||
identifier,
|
identifier,
|
||||||
sequential_number,
|
sequential_number,
|
||||||
):
|
):
|
||||||
pass
|
|
||||||
"""
|
"""
|
||||||
link test - open up a connection to a specific provider, and send them an xml payload with a <msgType> of
|
link test - open up a connection to a specific provider, and send them an xml payload with a <msgType> of
|
||||||
test.
|
test.
|
||||||
@@ -189,7 +201,6 @@ class CBCProxyVodafone(CBCProxyClientBase):
|
|||||||
def create_and_send_broadcast(
|
def create_and_send_broadcast(
|
||||||
self, identifier, message_number, headline, description, areas, sent, expires,
|
self, identifier, message_number, headline, description, areas, sent, expires,
|
||||||
):
|
):
|
||||||
pass
|
|
||||||
payload = {
|
payload = {
|
||||||
'message_type': 'alert',
|
'message_type': 'alert',
|
||||||
'identifier': identifier,
|
'identifier': identifier,
|
||||||
@@ -202,3 +213,22 @@ class CBCProxyVodafone(CBCProxyClientBase):
|
|||||||
'expires': expires,
|
'expires': expires,
|
||||||
}
|
}
|
||||||
self._invoke_lambda(payload=payload)
|
self._invoke_lambda(payload=payload)
|
||||||
|
|
||||||
|
def cancel_broadcast(
|
||||||
|
self, identifier, previous_provider_messages, sent, message_number
|
||||||
|
):
|
||||||
|
payload = {
|
||||||
|
'message_type': 'cancel',
|
||||||
|
'identifier': identifier,
|
||||||
|
'message_number': message_number,
|
||||||
|
'message_format': 'ibag',
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"message_id": str(message.id),
|
||||||
|
"message_number": message.message_number,
|
||||||
|
"sent": message.created_at
|
||||||
|
} for message in previous_provider_messages
|
||||||
|
],
|
||||||
|
'sent': sent,
|
||||||
|
}
|
||||||
|
self._invoke_lambda(payload=payload)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
from collections import namedtuple
|
||||||
from unittest.mock import Mock
|
from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -116,6 +117,60 @@ def test_cbc_proxy_ee_create_and_send_invokes_function(mocker, cbc_proxy_ee):
|
|||||||
assert payload['expires'] == expires
|
assert payload['expires'] == expires
|
||||||
|
|
||||||
|
|
||||||
|
def test_cbc_proxy_ee_cancel_invokes_function(mocker, cbc_proxy_ee):
|
||||||
|
identifier = 'my-identifier'
|
||||||
|
MockProviderMessage = namedtuple('BroadcastProviderMessage', ['id', 'message_number', 'created_at'])
|
||||||
|
|
||||||
|
provider_messages = [
|
||||||
|
MockProviderMessage(uuid.uuid4(), '0000007b', '2020-12-10 11:19:44.130585'),
|
||||||
|
MockProviderMessage(uuid.uuid4(), '0000004e', '2020-12-10 12:19:44.130585')
|
||||||
|
]
|
||||||
|
sent = '2020-12-10 14:19:44.130585'
|
||||||
|
|
||||||
|
ld_client_mock = mocker.patch.object(
|
||||||
|
cbc_proxy_ee,
|
||||||
|
'_lambda_client',
|
||||||
|
create=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
ld_client_mock.invoke.return_value = {
|
||||||
|
'StatusCode': 200,
|
||||||
|
}
|
||||||
|
|
||||||
|
cbc_proxy_ee.cancel_broadcast(
|
||||||
|
identifier=identifier,
|
||||||
|
message_number='00000050',
|
||||||
|
previous_provider_messages=provider_messages,
|
||||||
|
sent=sent
|
||||||
|
)
|
||||||
|
|
||||||
|
ld_client_mock.invoke.assert_called_once_with(
|
||||||
|
FunctionName='bt-ee-1-proxy',
|
||||||
|
InvocationType='RequestResponse',
|
||||||
|
Payload=mocker.ANY,
|
||||||
|
)
|
||||||
|
|
||||||
|
kwargs = ld_client_mock.invoke.mock_calls[0][-1]
|
||||||
|
payload_bytes = kwargs['Payload']
|
||||||
|
payload = json.loads(payload_bytes)
|
||||||
|
|
||||||
|
assert payload['identifier'] == identifier
|
||||||
|
assert 'message_number' not in payload
|
||||||
|
assert payload['message_format'] == 'cap'
|
||||||
|
assert payload['message_type'] == 'cancel'
|
||||||
|
assert payload['references'] == [
|
||||||
|
{
|
||||||
|
"message_id": str(provider_messages[0].id),
|
||||||
|
"sent": provider_messages[0].created_at
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"message_id": str(provider_messages[1].id),
|
||||||
|
"sent": provider_messages[1].created_at
|
||||||
|
},
|
||||||
|
]
|
||||||
|
assert payload['sent'] == sent
|
||||||
|
|
||||||
|
|
||||||
def test_cbc_proxy_vodafone_create_and_send_invokes_function(mocker, cbc_proxy_vodafone):
|
def test_cbc_proxy_vodafone_create_and_send_invokes_function(mocker, cbc_proxy_vodafone):
|
||||||
identifier = 'my-identifier'
|
identifier = 'my-identifier'
|
||||||
headline = 'my-headline'
|
headline = 'my-headline'
|
||||||
@@ -176,6 +231,62 @@ def test_cbc_proxy_vodafone_create_and_send_invokes_function(mocker, cbc_proxy_v
|
|||||||
assert payload['expires'] == expires
|
assert payload['expires'] == expires
|
||||||
|
|
||||||
|
|
||||||
|
def test_cbc_proxy_vodafone_cancel_invokes_function(mocker, cbc_proxy_vodafone):
|
||||||
|
identifier = 'my-identifier'
|
||||||
|
MockProviderMessage = namedtuple('BroadcastProviderMessage', ['id', 'message_number', 'created_at'])
|
||||||
|
|
||||||
|
provider_messages = [
|
||||||
|
MockProviderMessage(uuid.uuid4(), '0000007b', '2020-12-10 11:19:44.130585'),
|
||||||
|
MockProviderMessage(uuid.uuid4(), '0000004e', '2020-12-10 12:19:44.130585')
|
||||||
|
]
|
||||||
|
sent = '2020-12-10 14:19:44.130585'
|
||||||
|
|
||||||
|
ld_client_mock = mocker.patch.object(
|
||||||
|
cbc_proxy_vodafone,
|
||||||
|
'_lambda_client',
|
||||||
|
create=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
ld_client_mock.invoke.return_value = {
|
||||||
|
'StatusCode': 200,
|
||||||
|
}
|
||||||
|
|
||||||
|
cbc_proxy_vodafone.cancel_broadcast(
|
||||||
|
identifier=identifier,
|
||||||
|
message_number='00000050',
|
||||||
|
previous_provider_messages=provider_messages,
|
||||||
|
sent=sent
|
||||||
|
)
|
||||||
|
|
||||||
|
ld_client_mock.invoke.assert_called_once_with(
|
||||||
|
FunctionName='vodafone-1-proxy',
|
||||||
|
InvocationType='RequestResponse',
|
||||||
|
Payload=mocker.ANY,
|
||||||
|
)
|
||||||
|
|
||||||
|
kwargs = ld_client_mock.invoke.mock_calls[0][-1]
|
||||||
|
payload_bytes = kwargs['Payload']
|
||||||
|
payload = json.loads(payload_bytes)
|
||||||
|
|
||||||
|
assert payload['identifier'] == identifier
|
||||||
|
assert payload['message_number'] == '00000050'
|
||||||
|
assert payload['message_format'] == 'ibag'
|
||||||
|
assert payload['message_type'] == 'cancel'
|
||||||
|
assert payload['references'] == [
|
||||||
|
{
|
||||||
|
"message_id": str(provider_messages[0].id),
|
||||||
|
"message_number": provider_messages[0].message_number,
|
||||||
|
"sent": provider_messages[0].created_at
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"message_id": str(provider_messages[1].id),
|
||||||
|
"message_number": provider_messages[1].message_number,
|
||||||
|
"sent": provider_messages[1].created_at
|
||||||
|
},
|
||||||
|
]
|
||||||
|
assert payload['sent'] == sent
|
||||||
|
|
||||||
|
|
||||||
def test_cbc_proxy_create_and_send_handles_invoke_error(mocker, cbc_proxy_ee):
|
def test_cbc_proxy_create_and_send_handles_invoke_error(mocker, cbc_proxy_ee):
|
||||||
identifier = 'my-identifier'
|
identifier = 'my-identifier'
|
||||||
headline = 'my-headline'
|
headline = 'my-headline'
|
||||||
|
|||||||
Reference in New Issue
Block a user