Accept CAP XML

This commit makes the existing endpoint also accept CAP XML, should the
appropriate `Content-Type` header be set.

It uses the translation code we added in a previous commit to convert
the CAP to a dict. We can then validate that dict against with the JSON
schema to ensure it’s something we can work with.
This commit is contained in:
Chris Hill-Scott
2021-01-18 10:01:46 +00:00
parent f98aca05e9
commit 38f07db23e
3 changed files with 95 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ from flask import json
from freezegun import freeze_time
from tests import create_authorization_header
from unittest.mock import ANY
from . import sample_cap_xml_documents
def test_broadcast_for_service_without_permission_returns_400(
@@ -73,3 +74,51 @@ def test_valid_post_broadcast_returns_201(
assert response_json['template_name'] is None
assert response_json['template_version'] is None
assert response_json['updated_at'] is None
def test_valid_post_cap_xml_broadcast_returns_201(
client,
sample_broadcast_service,
):
auth_header = create_authorization_header(service_id=sample_broadcast_service.id)
response = client.post(
path='/v2/broadcast',
data=sample_cap_xml_documents.WAINFLEET,
headers=[('Content-Type', 'application/cap+xml'), auth_header],
)
assert response.status_code == 201
response_json = json.loads(response.get_data(as_text=True))
assert response_json['approved_at'] is None
assert response_json['approved_by_id'] == None
assert response_json['areas'] == [
'River Steeping in Wainfleet All Saints'
]
assert response_json['cancelled_at'] == None
assert response_json['cancelled_by_id'] == None
assert response_json['content'].startswith(
'A severe flood warning has been issued. Storm Dennis'
)
assert response_json['content'].endswith(
'closely monitoring the situation throughout the night. '
)
assert response_json['reference'] == '50385fcb0ab7aa447bbd46d848ce8466E'
assert response_json['created_at'] # datetime generated by the DB so cant freeze it
assert response_json['created_by_id'] == None
assert response_json['finishes_at'] is None
assert response_json['id'] == ANY
assert response_json['personalisation'] is None
assert response_json['service_id'] == str(sample_broadcast_service.id)
assert len(response_json['simple_polygons']) == 1
assert len(response_json['simple_polygons'][0]) == 29
assert response_json['simple_polygons'][0][0] == [53.10569, 0.24453]
assert response_json['simple_polygons'][0][-1] == [53.10569, 0.24453]
assert response_json['starts_at'] is None
assert response_json['status'] == 'pending-approval'
assert response_json['template_id'] is None
assert response_json['template_name'] is None
assert response_json['template_version'] is None
assert response_json['updated_at'] is None