mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 01:33:13 -04:00
Merge pull request #3124 from alphagov/handle-xml-with-declaration
Handle XML files that have a declaration
This commit is contained in:
@@ -27,7 +27,7 @@ def create_broadcast():
|
|||||||
status_code=415,
|
status_code=415,
|
||||||
)
|
)
|
||||||
|
|
||||||
cap_xml = request.get_data(as_text=True)
|
cap_xml = request.get_data()
|
||||||
|
|
||||||
if not validate_xml(cap_xml, 'CAP-v1.2.xsd'):
|
if not validate_xml(cap_xml, 'CAP-v1.2.xsd'):
|
||||||
raise BadRequestError(
|
raise BadRequestError(
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
from flask import json
|
from flask import json
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
@@ -109,15 +111,20 @@ def test_valid_post_cap_xml_broadcast_returns_201(
|
|||||||
assert response_json['updated_at'] is None
|
assert response_json['updated_at'] is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('xml_document', (
|
||||||
|
'<alert>Oh no</alert>',
|
||||||
|
'<?xml version="1.0" encoding="utf-8" ?><foo><bar/></foo>',
|
||||||
|
))
|
||||||
def test_invalid_post_cap_xml_broadcast_returns_400(
|
def test_invalid_post_cap_xml_broadcast_returns_400(
|
||||||
client,
|
client,
|
||||||
sample_broadcast_service,
|
sample_broadcast_service,
|
||||||
|
xml_document,
|
||||||
):
|
):
|
||||||
auth_header = create_authorization_header(service_id=sample_broadcast_service.id)
|
auth_header = create_authorization_header(service_id=sample_broadcast_service.id)
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path='/v2/broadcast',
|
path='/v2/broadcast',
|
||||||
data="<alert>Oh no</alert>",
|
data=xml_document,
|
||||||
headers=[('Content-Type', 'application/cap+xml'), auth_header],
|
headers=[('Content-Type', 'application/cap+xml'), auth_header],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user