mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 13:38:53 -04:00
Don’t allow broadcasts to be created from JSON
Until we know we’re going to have real users for this, let’s not expose it.
This commit is contained in:
@@ -21,22 +21,22 @@ def create_broadcast():
|
|||||||
authenticated_service.permissions,
|
authenticated_service.permissions,
|
||||||
)
|
)
|
||||||
|
|
||||||
if request.content_type == 'application/json':
|
if request.content_type != 'application/cap+xml':
|
||||||
broadcast_json = request.get_json()
|
|
||||||
elif request.content_type == 'application/cap+xml':
|
|
||||||
cap_xml = request.get_data(as_text=True)
|
|
||||||
if not validate_xml(cap_xml, 'CAP-v1.2.xsd'):
|
|
||||||
raise BadRequestError(
|
|
||||||
message=f'Request data is not valid CAP XML',
|
|
||||||
status_code=400,
|
|
||||||
)
|
|
||||||
broadcast_json = cap_xml_to_dict(cap_xml)
|
|
||||||
else:
|
|
||||||
raise BadRequestError(
|
raise BadRequestError(
|
||||||
message=f'Content type {request.content_type} not supported',
|
message=f'Content type {request.content_type} not supported',
|
||||||
status_code=400,
|
status_code=400,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cap_xml = request.get_data(as_text=True)
|
||||||
|
|
||||||
|
if not validate_xml(cap_xml, 'CAP-v1.2.xsd'):
|
||||||
|
raise BadRequestError(
|
||||||
|
message=f'Request data is not valid CAP XML',
|
||||||
|
status_code=400,
|
||||||
|
)
|
||||||
|
|
||||||
|
broadcast_json = cap_xml_to_dict(cap_xml)
|
||||||
|
|
||||||
validate(broadcast_json, post_broadcast_schema)
|
validate(broadcast_json, post_broadcast_schema)
|
||||||
|
|
||||||
polygons = Polygons(list(chain.from_iterable((
|
polygons = Polygons(list(chain.from_iterable((
|
||||||
|
|||||||
@@ -51,46 +51,14 @@ def test_valid_post_broadcast_returns_201(
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header],
|
headers=[('Content-Type', 'application/json'), auth_header],
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 201
|
assert response.status_code == 400
|
||||||
|
assert json.loads(response.get_data(as_text=True)) == {
|
||||||
response_json = json.loads(response.get_data(as_text=True))
|
'errors': [{
|
||||||
|
'error': 'BadRequestError',
|
||||||
assert response_json['approved_at'] is None
|
'message': 'Content type application/json not supported'
|
||||||
assert response_json['approved_by_id'] == None
|
}],
|
||||||
assert response_json['areas'] == [
|
'status_code': 400,
|
||||||
'Hackney Marshes'
|
}
|
||||||
]
|
|
||||||
assert response_json['cancelled_at'] == None
|
|
||||||
assert response_json['cancelled_by_id'] == None
|
|
||||||
assert response_json['content'] == 'This is a test'
|
|
||||||
assert response_json['reference'] == 'abc123'
|
|
||||||
assert response_json['created_at'] # datetime generated by the DB so can’t 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 response_json['simple_polygons'] == [[
|
|
||||||
[-0.03817522145265898, 51.557381351011166],
|
|
||||||
[-0.03791399800364216, 51.55758039392131],
|
|
||||||
[-0.030362635618559567, 51.56141279571522],
|
|
||||||
[-0.02986997783677049, 51.56152875195115],
|
|
||||||
[-0.029379069367567606, 51.561405599957745],
|
|
||||||
[-0.023537043373602105, 51.5583323982824],
|
|
||||||
[-0.02328416546450603, 51.55813395976017],
|
|
||||||
[-0.02355422144186266, 51.557933308587664],
|
|
||||||
[-0.0313493058222969, 51.55414241384808],
|
|
||||||
[-0.031840673207720764, 51.55403463730992],
|
|
||||||
[-0.032327132941933706, 51.55416275685022],
|
|
||||||
[-0.037918974384948616, 51.55717594115094],
|
|
||||||
[-0.03817522145265898, 51.557381351011166],
|
|
||||||
]]
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def test_valid_post_cap_xml_broadcast_returns_201(
|
def test_valid_post_cap_xml_broadcast_returns_201(
|
||||||
|
|||||||
Reference in New Issue
Block a user