separate cbc proxy into separate clients

this is a pretty big and convoluted refactor unfortunately.

Previously:

There was one global `cbc_proxy_client` object in apps. This class has
the information about how to invoke the bt-ee lambda, and handles all
calls to lambda. This includes calls to the canary too (which is a
separate lambda).

The future:

There's one global `cbc_proxy_client`. This knows about the different
provider functions and lambdas, and you'll need to ask this client for a
proxy for your chosen provider. call cbc_proxy_client.get_proxy('ee')`
and it'll return you a proxy that knows what ee's lambda function is,
how to transform any content in a way that is exclusive to ee, and in
future how to parse any response from ee.

The present:

I also cleaned up some duplicate tests.
I'm really not sure about the names of some of these variables - in
particular `cbc_proxy_client` isn't a client - it's more of a java style
factory, where you call a function on it to get the client of your
choice.
This commit is contained in:
Leo Hemsted
2020-11-17 12:35:22 +00:00
parent 0257774cfa
commit 087cc5053d
7 changed files with 110 additions and 193 deletions

View File

@@ -48,7 +48,7 @@ def test_send_broadcast_provider_message_sends_data_correctly(mocker, sample_ser
event = create_broadcast_event(broadcast_message)
mock_create_broadcast = mocker.patch(
'app.cbc_proxy_client.create_and_send_broadcast',
'app.clients.cbc_proxy.CBCProxyEE.create_and_send_broadcast',
)
assert event.get_provider_message('ee') is None
@@ -95,7 +95,7 @@ def test_send_broadcast_provider_message_sends_update_with_references(mocker, sa
update_event = create_broadcast_event(broadcast_message, message_type=BroadcastEventMessageType.UPDATE)
mock_update_broadcast = mocker.patch(
'app.cbc_proxy_client.update_and_send_broadcast',
'app.clients.cbc_proxy.CBCProxyEE.update_and_send_broadcast',
)
send_broadcast_provider_message(provider='ee', broadcast_event_id=str(update_event.id))
@@ -140,7 +140,7 @@ def test_send_broadcast_provider_message_sends_cancel_with_references(mocker, sa
create_broadcast_provider_message(update_event, 'ee')
mock_cancel_broadcast = mocker.patch(
'app.cbc_proxy_client.cancel_broadcast',
'app.clients.cbc_proxy.CBCProxyEE.cancel_broadcast',
)
send_broadcast_provider_message(provider='ee', broadcast_event_id=str(cancel_event.id))
@@ -181,7 +181,7 @@ def test_send_broadcast_provider_message_errors(mocker, sample_service):
event = create_broadcast_event(broadcast_message)
mock_create_broadcast = mocker.patch(
'app.cbc_proxy_client.create_and_send_broadcast',
'app.clients.cbc_proxy.CBCProxyEE.create_and_send_broadcast',
side_effect=Exception('oh no'),
)
@@ -210,10 +210,10 @@ def test_trigger_link_tests_invokes_cbc_proxy_client(
mocker,
):
mock_send_link_test = mocker.patch(
'app.cbc_proxy_client.send_link_test',
'app.clients.cbc_proxy.CBCProxyEE.send_link_test',
)
trigger_link_test('some-provider')
trigger_link_test('ee')
assert mock_send_link_test.called
# the 0th argument of the call to send_link_test

View File

@@ -561,9 +561,10 @@ def test_check_for_services_with_high_failure_rates_or_sending_to_tv_numbers(
def test_send_canary_to_cbc_proxy_invokes_cbc_proxy_client(
mocker,
notify_api
):
mock_send_canary = mocker.patch(
'app.cbc_proxy_client.send_canary',
'app.clients.cbc_proxy.CBCProxyCanary.send_canary',
)
scheduled_tasks.send_canary_to_cbc_proxy()