mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Move ID generation into link test method
Unlike the other IDs which are stored in the DB, this isn't relevant for the Celery task as it invokes a link test. Moving it into the proxy client will also enable us to generate a second ID in the next commits, where we start doing a link test for the failover lambda.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from flask import current_app
|
||||
@@ -250,5 +249,4 @@ def send_broadcast_provider_message(self, broadcast_event_id, provider):
|
||||
|
||||
@notify_celery.task(name='trigger-link-test')
|
||||
def trigger_link_test(provider):
|
||||
identifier = str(uuid.uuid4())
|
||||
cbc_proxy_client.get_proxy(provider).send_link_test(identifier)
|
||||
cbc_proxy_client.get_proxy(provider).send_link_tests()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import uuid
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import boto3
|
||||
@@ -77,11 +78,11 @@ class CBCProxyClientBase(ABC):
|
||||
def __init__(self, lambda_client):
|
||||
self._lambda_client = lambda_client
|
||||
|
||||
def send_link_test(
|
||||
self,
|
||||
identifier,
|
||||
):
|
||||
pass
|
||||
def send_link_tests(self):
|
||||
self._send_link_test(self.lambda_name)
|
||||
self._send_link_test(self.failover_lambda_name)
|
||||
|
||||
def _send_link_test(self): pass
|
||||
|
||||
def create_and_send_broadcast(
|
||||
self, identifier, headline, description, areas, sent, expires, channel, message_number=None
|
||||
@@ -159,9 +160,9 @@ class CBCProxyOne2ManyClient(CBCProxyClientBase):
|
||||
LANGUAGE_ENGLISH = 'en-GB'
|
||||
LANGUAGE_WELSH = 'cy-GB'
|
||||
|
||||
def send_link_test(
|
||||
def _send_link_test(
|
||||
self,
|
||||
identifier,
|
||||
lambda_name,
|
||||
):
|
||||
"""
|
||||
link test - open up a connection to a specific provider, and send them an xml payload with a <msgType> of
|
||||
@@ -169,11 +170,11 @@ class CBCProxyOne2ManyClient(CBCProxyClientBase):
|
||||
"""
|
||||
payload = {
|
||||
'message_type': 'test',
|
||||
'identifier': identifier,
|
||||
'identifier': str(uuid.uuid4()),
|
||||
'message_format': 'cap'
|
||||
}
|
||||
|
||||
self._invoke_lambda(lambda_name=self.lambda_name, payload=payload)
|
||||
self._invoke_lambda(lambda_name=lambda_name, payload=payload)
|
||||
|
||||
def create_and_send_broadcast(
|
||||
self, identifier, headline, description, areas, sent, expires, channel, message_number=None
|
||||
@@ -234,9 +235,9 @@ class CBCProxyVodafone(CBCProxyClientBase):
|
||||
LANGUAGE_ENGLISH = 'English'
|
||||
LANGUAGE_WELSH = 'Welsh'
|
||||
|
||||
def send_link_test(
|
||||
def _send_link_test(
|
||||
self,
|
||||
identifier,
|
||||
lambda_name,
|
||||
):
|
||||
"""
|
||||
link test - open up a connection to a specific provider, and send them an xml payload with a <msgType> of
|
||||
@@ -249,12 +250,12 @@ class CBCProxyVodafone(CBCProxyClientBase):
|
||||
|
||||
payload = {
|
||||
'message_type': 'test',
|
||||
'identifier': identifier,
|
||||
'identifier': str(uuid.uuid4()),
|
||||
'message_number': formatted_seq_number,
|
||||
'message_format': 'ibag'
|
||||
}
|
||||
|
||||
self._invoke_lambda(lambda_name=self.lambda_name, payload=payload)
|
||||
self._invoke_lambda(lambda_name=lambda_name, payload=payload)
|
||||
|
||||
def create_and_send_broadcast(
|
||||
self, identifier, message_number, headline, description, areas, sent, expires, channel
|
||||
|
||||
@@ -566,10 +566,8 @@ def test_trigger_link_tests_invokes_cbc_proxy_client(
|
||||
f'app.clients.cbc_proxy.CBCProxy{provider_capitalised}.send_link_test',
|
||||
)
|
||||
|
||||
mocker.patch('app.celery.broadcast_message_tasks.uuid.uuid4', return_value=123)
|
||||
|
||||
trigger_link_test(provider)
|
||||
assert mock_send_link_test.called_once_with('123')
|
||||
assert mock_send_link_test.called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('retry_count, expected_delay', [
|
||||
|
||||
@@ -82,6 +82,14 @@ def test_cbc_proxy_lambda_client_has_correct_keys(cbc_proxy_ee):
|
||||
assert secret == 'cbc-proxy-aws-secret-access-key'
|
||||
|
||||
|
||||
def test_cbc_proxy_send_link_tests(mocker, cbc_proxy_ee):
|
||||
mock_send_link_test = mocker.patch.object(cbc_proxy_ee, '_send_link_test')
|
||||
cbc_proxy_ee.send_link_tests()
|
||||
|
||||
mock_send_link_test.assert_any_call(cbc_proxy_ee.lambda_name)
|
||||
mock_send_link_test.assert_any_call(cbc_proxy_ee.failover_lambda_name)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('description, expected_language', (
|
||||
('my-description', 'en-GB'),
|
||||
('mŷ-description', 'cy-GB'),
|
||||
@@ -560,7 +568,7 @@ def test_cbc_proxy_create_and_send_tries_failover_lambda_on_function_error_and_r
|
||||
def test_cbc_proxy_one_2_many_send_link_test_invokes_function(mocker, cbc_proxy_client, cbc):
|
||||
cbc_proxy = cbc_proxy_client.get_proxy(cbc)
|
||||
|
||||
identifier = str(uuid.uuid4())
|
||||
mocker.patch('app.clients.cbc_proxy.uuid.uuid4', return_value=123)
|
||||
|
||||
ld_client_mock = mocker.patch.object(
|
||||
cbc_proxy,
|
||||
@@ -572,8 +580,8 @@ def test_cbc_proxy_one_2_many_send_link_test_invokes_function(mocker, cbc_proxy_
|
||||
'StatusCode': 200,
|
||||
}
|
||||
|
||||
cbc_proxy.send_link_test(
|
||||
identifier=identifier,
|
||||
cbc_proxy._send_link_test(
|
||||
lambda_name=f'{cbc}-1-proxy'
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
@@ -586,14 +594,14 @@ def test_cbc_proxy_one_2_many_send_link_test_invokes_function(mocker, cbc_proxy_
|
||||
payload_bytes = kwargs['Payload']
|
||||
payload = json.loads(payload_bytes)
|
||||
|
||||
assert payload['identifier'] == identifier
|
||||
assert payload['identifier'] == '123'
|
||||
assert payload['message_type'] == 'test'
|
||||
assert 'message_number' not in payload
|
||||
assert payload['message_format'] == 'cap'
|
||||
|
||||
|
||||
def test_cbc_proxy_vodafone_send_link_test_invokes_function(mocker, cbc_proxy_vodafone):
|
||||
identifier = str(uuid.uuid4())
|
||||
mocker.patch('app.clients.cbc_proxy.uuid.uuid4', return_value=123)
|
||||
|
||||
db.session.connection().execute(
|
||||
'ALTER SEQUENCE broadcast_provider_message_number_seq RESTART WITH 1'
|
||||
@@ -609,8 +617,8 @@ def test_cbc_proxy_vodafone_send_link_test_invokes_function(mocker, cbc_proxy_vo
|
||||
'StatusCode': 200,
|
||||
}
|
||||
|
||||
cbc_proxy_vodafone.send_link_test(
|
||||
identifier=identifier,
|
||||
cbc_proxy_vodafone._send_link_test(
|
||||
lambda_name='vodafone-1-proxy'
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
@@ -623,7 +631,7 @@ def test_cbc_proxy_vodafone_send_link_test_invokes_function(mocker, cbc_proxy_vo
|
||||
payload_bytes = kwargs['Payload']
|
||||
payload = json.loads(payload_bytes)
|
||||
|
||||
assert payload['identifier'] == identifier
|
||||
assert payload['identifier'] == '123'
|
||||
assert payload['message_type'] == 'test'
|
||||
assert payload['message_number'] == '00000001'
|
||||
assert payload['message_format'] == 'ibag'
|
||||
|
||||
Reference in New Issue
Block a user