Merge pull request #3463 from alphagov/clear-redis-on-cancelling-broadcast

Clear cache when cancelling broadcast via the API
This commit is contained in:
Chris Hill-Scott
2022-02-23 16:04:19 +00:00
committed by GitHub
2 changed files with 9 additions and 1 deletions

View File

@@ -5,7 +5,7 @@ from notifications_utils.polygons import Polygons
from notifications_utils.template import BroadcastMessageTemplate
from sqlalchemy.orm.exc import MultipleResultsFound
from app import api_user, authenticated_service
from app import api_user, authenticated_service, redis_store
from app.broadcast_message.translators import cap_xml_to_dict
from app.broadcast_message.utils import (
validate_and_update_broadcast_message_status,
@@ -126,6 +126,9 @@ def _cancel_or_reject_broadcast(references_to_original_broadcast, service_id):
new_status,
api_key_id=api_user.id
)
redis_store.delete(
f'service-{broadcast_message.service_id}-broadcast-message-{broadcast_message.id}'
)
return broadcast_message

View File

@@ -134,6 +134,8 @@ def test_valid_cancel_broadcast_request_calls_validate_and_update_broadcast_mess
api_key = create_api_key(service=sample_broadcast_service)
auth_header = create_service_authorization_header(service_id=sample_broadcast_service.id)
mock_redis_delete = mocker.patch('app.redis_store.delete')
# create a broadcast
response_for_create = client.post(
path='/v2/broadcast',
@@ -165,6 +167,9 @@ def test_valid_cancel_broadcast_request_calls_validate_and_update_broadcast_mess
expected_status,
api_key_id=api_key.id
)
mock_redis_delete.assert_called_once_with(
f'service-{sample_broadcast_service.id}-broadcast-message-{broadcast_message.id}'
)
@pytest.mark.parametrize('cap_xml_document, expected_status, expected_error', (