mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 07:46:06 -04:00
Merge pull request #3079 from alphagov/pass-language-to-lambda
Pass language through to lambda
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import json
|
import json
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from notifications_utils.template import non_gsm_characters
|
||||||
|
|
||||||
from app.config import BroadcastProvider
|
from app.config import BroadcastProvider
|
||||||
from app.utils import DATETIME_FORMAT, format_sequential_number
|
from app.utils import DATETIME_FORMAT, format_sequential_number
|
||||||
@@ -48,9 +50,19 @@ class CBCProxyClient:
|
|||||||
return proxy_classes[provider](self._lambda_client)
|
return proxy_classes[provider](self._lambda_client)
|
||||||
|
|
||||||
|
|
||||||
class CBCProxyClientBase:
|
class CBCProxyClientBase(ABC):
|
||||||
lambda_name = None
|
lambda_name = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def LANGUAGE_ENGLISH(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def LANGUAGE_WELSH(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def __init__(self, lambda_client):
|
def __init__(self, lambda_client):
|
||||||
self._lambda_client = lambda_client
|
self._lambda_client = lambda_client
|
||||||
|
|
||||||
@@ -111,6 +123,11 @@ class CBCProxyClientBase:
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def infer_language_from(self, content):
|
||||||
|
if non_gsm_characters(content):
|
||||||
|
return self.LANGUAGE_WELSH
|
||||||
|
return self.LANGUAGE_ENGLISH
|
||||||
|
|
||||||
|
|
||||||
class CBCProxyCanary(CBCProxyClientBase):
|
class CBCProxyCanary(CBCProxyClientBase):
|
||||||
"""
|
"""
|
||||||
@@ -119,6 +136,9 @@ class CBCProxyCanary(CBCProxyClientBase):
|
|||||||
"""
|
"""
|
||||||
lambda_name = 'canary'
|
lambda_name = 'canary'
|
||||||
|
|
||||||
|
LANGUAGE_ENGLISH = None
|
||||||
|
LANGUAGE_WELSH = None
|
||||||
|
|
||||||
def send_canary(
|
def send_canary(
|
||||||
self,
|
self,
|
||||||
identifier,
|
identifier,
|
||||||
@@ -129,6 +149,9 @@ class CBCProxyCanary(CBCProxyClientBase):
|
|||||||
class CBCProxyEE(CBCProxyClientBase):
|
class CBCProxyEE(CBCProxyClientBase):
|
||||||
lambda_name = 'bt-ee-1-proxy'
|
lambda_name = 'bt-ee-1-proxy'
|
||||||
|
|
||||||
|
LANGUAGE_ENGLISH = 'en-GB'
|
||||||
|
LANGUAGE_WELSH = 'cy-GB'
|
||||||
|
|
||||||
def send_link_test(
|
def send_link_test(
|
||||||
self,
|
self,
|
||||||
identifier,
|
identifier,
|
||||||
@@ -158,6 +181,7 @@ class CBCProxyEE(CBCProxyClientBase):
|
|||||||
'areas': areas,
|
'areas': areas,
|
||||||
'sent': sent,
|
'sent': sent,
|
||||||
'expires': expires,
|
'expires': expires,
|
||||||
|
'language': self.infer_language_from(description),
|
||||||
}
|
}
|
||||||
self._invoke_lambda(payload=payload)
|
self._invoke_lambda(payload=payload)
|
||||||
|
|
||||||
@@ -184,6 +208,9 @@ class CBCProxyEE(CBCProxyClientBase):
|
|||||||
class CBCProxyVodafone(CBCProxyClientBase):
|
class CBCProxyVodafone(CBCProxyClientBase):
|
||||||
lambda_name = 'vodafone-1-proxy'
|
lambda_name = 'vodafone-1-proxy'
|
||||||
|
|
||||||
|
LANGUAGE_ENGLISH = 'English'
|
||||||
|
LANGUAGE_WELSH = 'Welsh'
|
||||||
|
|
||||||
def send_link_test(
|
def send_link_test(
|
||||||
self,
|
self,
|
||||||
identifier,
|
identifier,
|
||||||
@@ -215,6 +242,7 @@ class CBCProxyVodafone(CBCProxyClientBase):
|
|||||||
'areas': areas,
|
'areas': areas,
|
||||||
'sent': sent,
|
'sent': sent,
|
||||||
'expires': expires,
|
'expires': expires,
|
||||||
|
'language': self.infer_language_from(description),
|
||||||
}
|
}
|
||||||
self._invoke_lambda(payload=payload)
|
self._invoke_lambda(payload=payload)
|
||||||
|
|
||||||
|
|||||||
@@ -59,10 +59,18 @@ def test_cbc_proxy_lambda_client_has_correct_keys(cbc_proxy_ee):
|
|||||||
assert secret == 'cbc-proxy-aws-secret-access-key'
|
assert secret == 'cbc-proxy-aws-secret-access-key'
|
||||||
|
|
||||||
|
|
||||||
def test_cbc_proxy_ee_create_and_send_invokes_function(mocker, cbc_proxy_ee):
|
@pytest.mark.parametrize('description, expected_language', (
|
||||||
|
('my-description', 'en-GB'),
|
||||||
|
('mŷ-description', 'cy-GB'),
|
||||||
|
))
|
||||||
|
def test_cbc_proxy_ee_create_and_send_invokes_function(
|
||||||
|
mocker,
|
||||||
|
cbc_proxy_ee,
|
||||||
|
description,
|
||||||
|
expected_language,
|
||||||
|
):
|
||||||
identifier = 'my-identifier'
|
identifier = 'my-identifier'
|
||||||
headline = 'my-headline'
|
headline = 'my-headline'
|
||||||
description = 'my-description'
|
|
||||||
|
|
||||||
sent = 'a-passed-through-sent-value'
|
sent = 'a-passed-through-sent-value'
|
||||||
expires = 'a-passed-through-expires-value'
|
expires = 'a-passed-through-expires-value'
|
||||||
@@ -117,6 +125,7 @@ def test_cbc_proxy_ee_create_and_send_invokes_function(mocker, cbc_proxy_ee):
|
|||||||
assert payload['areas'] == areas
|
assert payload['areas'] == areas
|
||||||
assert payload['sent'] == sent
|
assert payload['sent'] == sent
|
||||||
assert payload['expires'] == expires
|
assert payload['expires'] == expires
|
||||||
|
assert payload['language'] == expected_language
|
||||||
|
|
||||||
|
|
||||||
def test_cbc_proxy_ee_cancel_invokes_function(mocker, cbc_proxy_ee):
|
def test_cbc_proxy_ee_cancel_invokes_function(mocker, cbc_proxy_ee):
|
||||||
@@ -175,10 +184,18 @@ def test_cbc_proxy_ee_cancel_invokes_function(mocker, cbc_proxy_ee):
|
|||||||
assert payload['sent'] == sent
|
assert payload['sent'] == sent
|
||||||
|
|
||||||
|
|
||||||
def test_cbc_proxy_vodafone_create_and_send_invokes_function(mocker, cbc_proxy_vodafone):
|
@pytest.mark.parametrize('description, expected_language', (
|
||||||
|
('my-description', 'English'),
|
||||||
|
('mŷ-description', 'Welsh'),
|
||||||
|
))
|
||||||
|
def test_cbc_proxy_vodafone_create_and_send_invokes_function(
|
||||||
|
mocker,
|
||||||
|
cbc_proxy_vodafone,
|
||||||
|
description,
|
||||||
|
expected_language,
|
||||||
|
):
|
||||||
identifier = 'my-identifier'
|
identifier = 'my-identifier'
|
||||||
headline = 'my-headline'
|
headline = 'my-headline'
|
||||||
description = 'my-description'
|
|
||||||
|
|
||||||
sent = 'a-passed-through-sent-value'
|
sent = 'a-passed-through-sent-value'
|
||||||
expires = 'a-passed-through-expires-value'
|
expires = 'a-passed-through-expires-value'
|
||||||
@@ -233,6 +250,7 @@ def test_cbc_proxy_vodafone_create_and_send_invokes_function(mocker, cbc_proxy_v
|
|||||||
assert payload['areas'] == areas
|
assert payload['areas'] == areas
|
||||||
assert payload['sent'] == sent
|
assert payload['sent'] == sent
|
||||||
assert payload['expires'] == expires
|
assert payload['expires'] == expires
|
||||||
|
assert payload['language'] == expected_language
|
||||||
|
|
||||||
|
|
||||||
def test_cbc_proxy_vodafone_cancel_invokes_function(mocker, cbc_proxy_vodafone):
|
def test_cbc_proxy_vodafone_cancel_invokes_function(mocker, cbc_proxy_vodafone):
|
||||||
|
|||||||
Reference in New Issue
Block a user