mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Merge pull request #3293 from alphagov/site-b-link-test-178738544
Trigger separate link test for failover lambda
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from unittest.mock import ANY, Mock, call
|
||||
|
||||
@@ -561,29 +560,14 @@ def test_send_broadcast_provider_message_delays_retry_exponentially(
|
||||
['vodafone', 'Vodafone'],
|
||||
])
|
||||
def test_trigger_link_tests_invokes_cbc_proxy_client(
|
||||
mocker, provider, provider_capitalised
|
||||
mocker, provider, provider_capitalised, client,
|
||||
):
|
||||
mock_send_link_test = mocker.patch(
|
||||
f'app.clients.cbc_proxy.CBCProxy{provider_capitalised}.send_link_test',
|
||||
)
|
||||
|
||||
trigger_link_test(provider)
|
||||
|
||||
assert mock_send_link_test.called
|
||||
# the 0th argument of the call to send_link_test
|
||||
identifier = mock_send_link_test.mock_calls[0][1][0]
|
||||
|
||||
try:
|
||||
uuid.UUID(identifier)
|
||||
except BaseException:
|
||||
pytest.fail(f"{identifier} is not a valid uuid")
|
||||
|
||||
# testing sequential number:
|
||||
if provider == 'vodafone':
|
||||
assert type(mock_send_link_test.mock_calls[0][1][1]) is str
|
||||
assert len(mock_send_link_test.mock_calls[0][1][1]) == 8
|
||||
else:
|
||||
assert not mock_send_link_test.mock_calls[0][1][1]
|
||||
assert mock_send_link_test.called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('retry_count, expected_delay', [
|
||||
|
||||
@@ -8,6 +8,7 @@ from unittest.mock import Mock, call
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError as BotoClientError
|
||||
|
||||
from app import db
|
||||
from app.clients.cbc_proxy import (
|
||||
CBCProxyClient,
|
||||
CBCProxyEE,
|
||||
@@ -81,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_test(mocker, cbc_proxy_ee):
|
||||
mock_send_link_test = mocker.patch.object(cbc_proxy_ee, '_send_link_test')
|
||||
cbc_proxy_ee.send_link_test()
|
||||
|
||||
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'),
|
||||
@@ -559,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,
|
||||
@@ -571,9 +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,
|
||||
sequential_number='0000007b',
|
||||
cbc_proxy._send_link_test(
|
||||
lambda_name=f'{cbc}-1-proxy'
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
@@ -586,14 +594,18 @@ 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'
|
||||
)
|
||||
|
||||
ld_client_mock = mocker.patch.object(
|
||||
cbc_proxy_vodafone,
|
||||
@@ -605,9 +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,
|
||||
sequential_number='0000007b',
|
||||
cbc_proxy_vodafone._send_link_test(
|
||||
lambda_name='vodafone-1-proxy'
|
||||
)
|
||||
|
||||
ld_client_mock.invoke.assert_called_once_with(
|
||||
@@ -620,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'] == '0000007b'
|
||||
assert payload['message_number'] == '00000001'
|
||||
assert payload['message_format'] == 'ibag'
|
||||
|
||||
Reference in New Issue
Block a user