Hardcode service broadcast channel that API shows

We are in a weird situation where at the moment, we have services with
the broadcast permission that do not have a row in the
service_broadcast_settings table and therefore do not have defined
whether they should send messages on the 'test' or 'severe' channel.

We currently get around this when we send broadcast messages out as
such:
https://github.com/alphagov/notifications-api/blob/master/app/celery/broadcast_message_tasks.py#L51

We need to something equivalent for the broadcast channel that the API
says the service is on. In time, when we have added a row in the
service_broadcast_settings table for every service with the broadcast
permission then we can remove both of these two hardcodings.

Note, one option would have been to move the default of `test` on to the
`Service` model rather than having it in both the
broadcast_message_tasks file and the `ServiceSchema` class. However, I
went for the quickest thing which was to add it here.
This commit is contained in:
David McDonald
2021-02-12 15:26:03 +00:00
parent d846ed79d2
commit 42163813fe
2 changed files with 41 additions and 2 deletions

View File

@@ -292,6 +292,38 @@ def test_get_service_by_id_returns_allowed_broadcast_provider(notify_db, admin_r
assert json_resp['data']['allowed_broadcast_provider'] == 'ee'
def test_get_service_by_id_for_broadcast_service_takes_channel_from_service_broadcast_settings(
admin_request, sample_broadcast_service
):
assert sample_broadcast_service.broadcast_channel == 'severe'
json_resp = admin_request.get('service.get_service_by_id', service_id=sample_broadcast_service.id)
assert json_resp['data']['id'] == str(sample_broadcast_service.id)
assert json_resp['data']['broadcast_channel'] == 'severe'
def test_get_service_by_id_for_service_with_broadcast_permission_sets_channel_as_test_if_no_service_broadcast_settings(
admin_request, notify_db_session
):
service = create_service(service_permissions=[BROADCAST_TYPE])
assert BROADCAST_TYPE in [p.permission for p in service.permissions]
assert service.broadcast_channel == None
json_resp = admin_request.get('service.get_service_by_id', service_id=service.id)
assert json_resp['data']['id'] == str(service.id)
assert json_resp['data']['broadcast_channel'] == 'test'
def test_get_service_by_id_for_non_broadcast_service_sets_channel_as_none(
admin_request, sample_service
):
assert BROADCAST_TYPE not in [p.permission for p in sample_service.permissions]
json_resp = admin_request.get('service.get_service_by_id', service_id=sample_service.id)
assert json_resp['data']['id'] == str(sample_service.id)
assert json_resp['data']['broadcast_channel'] == None
@pytest.mark.parametrize('detailed', [True, False])
def test_get_service_by_id_returns_organisation_type(admin_request, sample_service, detailed):
json_resp = admin_request.get('service.get_service_by_id', service_id=sample_service.id, detailed=detailed)