From 73507b3abc6bd26ac3b957c3fcf474bf9d1a92af Mon Sep 17 00:00:00 2001 From: Toby Lorne Date: Tue, 20 Oct 2020 14:00:53 +0100 Subject: [PATCH] clients: cbc_proxy invokes hardcoded function right now we are doing an end-to-end journey with a CBC from Notify (the CBE) and we would like to approve a broadcast in notify and have it appear on our test handset in order to do this, we: * hook up the lambda that we made in the correct VPC to cbc_proxy client * test that it is called correctly Signed-off-by: Toby Lorne Co-authored-by: Pea Co-authored-by: Katie --- app/clients/cbc_proxy.py | 16 +++++++++++--- tests/app/clients/test_cbc_proxy.py | 34 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/app/clients/cbc_proxy.py b/app/clients/cbc_proxy.py index 5bf3655b2..7e3cf6ba4 100644 --- a/app/clients/cbc_proxy.py +++ b/app/clients/cbc_proxy.py @@ -1,3 +1,5 @@ +import json + import boto3 # Noop = no operation @@ -44,9 +46,17 @@ class CBCProxyClient: self, identifier, headline, description, ): - # identifier=broadcast_message.identifier, - # headline="GOV.UK Notify Broadcast", - # description=broadcast_message.description, + payload_bytes = bytes(json.dumps({ + 'identifier': identifier, + 'headline': headline, + 'description': description, + }), encoding='utf8') + + self._ld_client.invoke( + FunctionName='bt-ee-1-proxy', + InvocationType='RequestResponse', + Payload=payload_bytes, + ) pass # We have not implementated updating a broadcast diff --git a/tests/app/clients/test_cbc_proxy.py b/tests/app/clients/test_cbc_proxy.py index 58ed5b8c6..bc8fe429f 100644 --- a/tests/app/clients/test_cbc_proxy.py +++ b/tests/app/clients/test_cbc_proxy.py @@ -1,3 +1,5 @@ +import json + import pytest from app.clients.cbc_proxy import CBCProxyClient @@ -25,3 +27,35 @@ def test_cbc_proxy_ld_client_has_correct_keys(cbc_proxy): assert key == 'cbc-proxy-aws-access-key-id' assert secret == 'cbc-proxy-aws-secret-access-key' + + +def test_cbc_proxy_create_and_send_invokes_function(mocker, cbc_proxy): + identifier = 'my-identifier' + headline = 'my-headline' + description = 'my-description' + + ld_client_mock = mocker.patch.object( + cbc_proxy, + '_ld_client', + create=True, + ) + + cbc_proxy.create_and_send_broadcast( + identifier=identifier, + headline=headline, + description=description, + ) + + 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 payload['headline'] == headline + assert payload['description'] == description