mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
Return 404 if reference from cancel message does not match
If the reference from cancel CAP XML we received via API does not match with any existing broadcast, return 404. Do the same if service id doesn't match. Also refactor code to cancel broadcast out into separate function It should be a separate function that is only called by create_broadcast function. This will prevent create_broadcast from becoming too big and complex and doing too many things.
This commit is contained in:
@@ -189,7 +189,7 @@ WITH_PLACEHOLDER_FOR_CONTENT = """
|
||||
|
||||
WINDEMERE = """
|
||||
<alert xmlns="urn:oasis:names:tc:emergency:cap:1.2">
|
||||
<identifier>50385fcb0ab7aa447bbd46d848ce8466E</identifier>
|
||||
<identifier>4f6d28b10ab7aa447bbd46d85f1e9effE</identifier>
|
||||
<sender>www.gov.uk/environment-agency</sender>
|
||||
<sent>2020-02-16T23:01:13-00:00</sent>
|
||||
<status>Actual</status>
|
||||
|
||||
@@ -205,8 +205,38 @@ def test_valid_cancel_broadcast_request_cancels_active_alert_and_returns_201(
|
||||
assert broadcast_message.updated_at is not None
|
||||
|
||||
|
||||
def test_cancel_request_does_not_cancel_broadcast_if_reference_does_not_match():
|
||||
pass
|
||||
def test_cancel_request_does_not_cancel_broadcast_if_reference_does_not_match(
|
||||
client,
|
||||
sample_broadcast_service
|
||||
):
|
||||
auth_header = create_service_authorization_header(service_id=sample_broadcast_service.id)
|
||||
|
||||
# create a broadcast
|
||||
response_for_create = client.post(
|
||||
path='/v2/broadcast',
|
||||
data=sample_cap_xml_documents.WINDEMERE,
|
||||
headers=[('Content-Type', 'application/cap+xml'), auth_header],
|
||||
)
|
||||
assert response_for_create.status_code == 201
|
||||
|
||||
response_json_for_create = json.loads(response_for_create.get_data(as_text=True))
|
||||
|
||||
assert response_json_for_create['cancelled_at'] is None
|
||||
assert response_json_for_create['cancelled_by_id'] is None
|
||||
assert response_json_for_create['reference'] == '4f6d28b10ab7aa447bbd46d85f1e9effE'
|
||||
assert response_json_for_create['status'] == 'pending-approval'
|
||||
|
||||
# try to cancel broadcast, but reference doesn't match
|
||||
response_for_cancel = client.post(
|
||||
path='/v2/broadcast',
|
||||
data=sample_cap_xml_documents.WAINFLEET_CANCEL,
|
||||
headers=[('Content-Type', 'application/cap+xml'), auth_header],
|
||||
)
|
||||
|
||||
assert response_for_cancel.status_code == 404
|
||||
response = json.loads(response_for_cancel.get_data(as_text=True))
|
||||
expected_error_message = "Broadcast message reference and service id didn't match with any existing broadcasts"
|
||||
assert response["errors"][0]["message"] == expected_error_message
|
||||
|
||||
|
||||
def test_large_polygon_is_simplified(
|
||||
|
||||
Reference in New Issue
Block a user