mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 09:21:39 -05:00
Merge pull request #3372 from alphagov/update-utils-coordinate-transformation-2
Update utils to bring in coordinate transformation (attempt 2)
This commit is contained in:
@@ -29,5 +29,5 @@ def cap_xml_polygon_to_list(polygon_string):
|
||||
[
|
||||
float(coordinate) for coordinate in pair.split(',')
|
||||
]
|
||||
for pair in polygon_string.split(' ')
|
||||
for pair in polygon_string.strip().split(' ')
|
||||
]
|
||||
|
||||
@@ -44,9 +44,17 @@ def create_broadcast():
|
||||
_validate_template(broadcast_json)
|
||||
|
||||
polygons = Polygons(list(chain.from_iterable((
|
||||
area['polygons'] for area in broadcast_json['areas']
|
||||
[
|
||||
[[y, x] for x, y in polygon]
|
||||
for polygon in area['polygons']
|
||||
] for area in broadcast_json['areas']
|
||||
))))
|
||||
|
||||
if len(polygons) > 12 or polygons.point_count > 250:
|
||||
simple_polygons = polygons.smooth.simplify
|
||||
else:
|
||||
simple_polygons = polygons
|
||||
|
||||
broadcast_message = BroadcastMessage(
|
||||
service_id=authenticated_service.id,
|
||||
content=broadcast_json['content'],
|
||||
@@ -56,7 +64,7 @@ def create_broadcast():
|
||||
'names': [
|
||||
area['name'] for area in broadcast_json['areas']
|
||||
],
|
||||
'simple_polygons': polygons.smooth.simplify.as_coordinate_pairs_long_lat,
|
||||
'simple_polygons': simple_polygons.as_coordinate_pairs_lat_long,
|
||||
},
|
||||
status=BroadcastStatusType.PENDING_APPROVAL,
|
||||
api_key_id=api_user.id,
|
||||
|
||||
@@ -36,7 +36,7 @@ notifications-python-client==6.0.2
|
||||
# PaaS
|
||||
awscli-cwlogs==1.4.6
|
||||
|
||||
git+https://github.com/alphagov/notifications-utils.git@48.1.0#egg=notifications-utils==48.1.0
|
||||
git+https://github.com/alphagov/notifications-utils.git@49.0.0#egg=notifications-utils==49.0.0
|
||||
|
||||
# gds-metrics requires prometheseus 0.2.0, override that requirement as 0.7.1 brings significant performance gains
|
||||
prometheus-client==0.10.1
|
||||
|
||||
@@ -40,7 +40,9 @@ cachetools==4.2.1
|
||||
celery[sqs]==5.2.0
|
||||
# via -r requirements.in
|
||||
certifi==2021.10.8
|
||||
# via requests
|
||||
# via
|
||||
# pyproj
|
||||
# requests
|
||||
cffi==1.14.5
|
||||
# via
|
||||
# -r requirements.in
|
||||
@@ -151,7 +153,7 @@ mistune==0.8.4
|
||||
# via notifications-utils
|
||||
notifications-python-client==6.0.2
|
||||
# via -r requirements.in
|
||||
notifications-utils @ git+https://github.com/alphagov/notifications-utils.git@48.1.0
|
||||
notifications-utils @ git+https://github.com/alphagov/notifications-utils.git@49.0.0
|
||||
# via -r requirements.in
|
||||
orderedset==2.0.3
|
||||
# via notifications-utils
|
||||
@@ -179,6 +181,8 @@ pyparsing==3.0.1
|
||||
# via packaging
|
||||
pypdf2==1.26.0
|
||||
# via notifications-utils
|
||||
pyproj==3.2.1
|
||||
# via notifications-utils
|
||||
pyrsistent==0.18.0
|
||||
# via jsonschema
|
||||
python-dateutil==2.8.2
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -105,9 +105,9 @@ def test_valid_post_cap_xml_broadcast_returns_201(
|
||||
assert response_json['service_id'] == str(sample_broadcast_service.id)
|
||||
|
||||
assert len(response_json['areas']['simple_polygons']) == 1
|
||||
assert len(response_json['areas']['simple_polygons'][0]) == 22
|
||||
assert response_json['areas']['simple_polygons'][0][0] == [53.10562, 0.244127]
|
||||
assert response_json['areas']['simple_polygons'][0][-1] == [53.10562, 0.244127]
|
||||
assert len(response_json['areas']['simple_polygons'][0]) == 29
|
||||
assert response_json['areas']['simple_polygons'][0][0] == [53.10569, 0.24453]
|
||||
assert response_json['areas']['simple_polygons'][0][-1] == [53.10569, 0.24453]
|
||||
assert response_json['areas']['names'] == ['River Steeping in Wainfleet All Saints']
|
||||
assert 'ids' not in response_json['areas'] # only for broadcasts created in Admin
|
||||
|
||||
@@ -119,6 +119,27 @@ def test_valid_post_cap_xml_broadcast_returns_201(
|
||||
assert response_json['updated_at'] is None
|
||||
|
||||
|
||||
def test_large_polygon_is_simplified(
|
||||
client,
|
||||
sample_broadcast_service,
|
||||
):
|
||||
auth_header = create_service_authorization_header(service_id=sample_broadcast_service.id)
|
||||
response = client.post(
|
||||
path='/v2/broadcast',
|
||||
data=sample_cap_xml_documents.WINDEMERE,
|
||||
headers=[('Content-Type', 'application/cap+xml'), auth_header],
|
||||
)
|
||||
assert response.status_code == 201
|
||||
|
||||
response_json = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert len(response_json['areas']['simple_polygons']) == 1
|
||||
assert len(response_json['areas']['simple_polygons'][0]) == 110
|
||||
|
||||
assert response_json['areas']['simple_polygons'][0][0] == [54.419546, -2.988521]
|
||||
assert response_json['areas']['simple_polygons'][0][-1] == [54.419546, -2.988521]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("training_mode_service", [True, False])
|
||||
def test_valid_post_cap_xml_broadcast_sets_stubbed_to_true_for_training_mode_services(
|
||||
client,
|
||||
|
||||
Reference in New Issue
Block a user