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:
Chris Hill-Scott
2021-01-26 12:00:19 +00:00
parent c9d55039eb
commit b85fcafd46
2 changed files with 19 additions and 51 deletions

View File

@@ -21,22 +21,22 @@ def create_broadcast():
authenticated_service.permissions,
)
if request.content_type == 'application/json':
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:
if request.content_type != 'application/cap+xml':
raise BadRequestError(
message=f'Content type {request.content_type} not supported',
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)
polygons = Polygons(list(chain.from_iterable((

View File

@@ -51,46 +51,14 @@ def test_valid_post_broadcast_returns_201(
headers=[('Content-Type', 'application/json'), 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'] == [
'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 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 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
assert response.status_code == 400
assert json.loads(response.get_data(as_text=True)) == {
'errors': [{
'error': 'BadRequestError',
'message': 'Content type application/json not supported'
}],
'status_code': 400,
}
def test_valid_post_cap_xml_broadcast_returns_201(