mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Merge pull request #3309 from alphagov/update-utils-coordinate-transformation
Update utils to bring in coordinate transformation
This commit is contained in:
@@ -28,5 +28,5 @@ def cap_xml_polygon_to_list(polygon_string):
|
|||||||
[
|
[
|
||||||
float(coordinate) for coordinate in pair.split(',')
|
float(coordinate) for coordinate in pair.split(',')
|
||||||
]
|
]
|
||||||
for pair in polygon_string.split(' ')
|
for pair in polygon_string.strip().split(' ')
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ def create_broadcast():
|
|||||||
validate(broadcast_json, post_broadcast_schema)
|
validate(broadcast_json, post_broadcast_schema)
|
||||||
|
|
||||||
polygons = Polygons(list(chain.from_iterable((
|
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']
|
||||||
))))
|
))))
|
||||||
|
|
||||||
template = BroadcastMessageTemplate.from_content(
|
template = BroadcastMessageTemplate.from_content(
|
||||||
@@ -62,6 +65,11 @@ def create_broadcast():
|
|||||||
status_code=400,
|
status_code=400,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if len(polygons) > 12 or polygons.point_count > 250:
|
||||||
|
simple_polygons = polygons.smooth.simplify
|
||||||
|
else:
|
||||||
|
simple_polygons = polygons
|
||||||
|
|
||||||
broadcast_message = BroadcastMessage(
|
broadcast_message = BroadcastMessage(
|
||||||
service_id=authenticated_service.id,
|
service_id=authenticated_service.id,
|
||||||
content=broadcast_json['content'],
|
content=broadcast_json['content'],
|
||||||
@@ -70,7 +78,7 @@ def create_broadcast():
|
|||||||
'areas': [
|
'areas': [
|
||||||
area['name'] for area in broadcast_json['areas']
|
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,
|
status=BroadcastStatusType.PENDING_APPROVAL,
|
||||||
api_key_id=api_user.id,
|
api_key_id=api_user.id,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ notifications-python-client==6.0.2
|
|||||||
# PaaS
|
# PaaS
|
||||||
awscli-cwlogs==1.4.6
|
awscli-cwlogs==1.4.6
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@44.5.1#egg=notifications-utils==44.5.1
|
git+https://github.com/alphagov/notifications-utils.git@45.0.1#egg=notifications-utils==45.0.1
|
||||||
|
|
||||||
# gds-metrics requires prometheseus 0.2.0, override that requirement as 0.7.1 brings significant performance gains
|
# gds-metrics requires prometheseus 0.2.0, override that requirement as 0.7.1 brings significant performance gains
|
||||||
prometheus-client==0.10.1
|
prometheus-client==0.10.1
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ notifications-python-client==6.0.2
|
|||||||
# PaaS
|
# PaaS
|
||||||
awscli-cwlogs==1.4.6
|
awscli-cwlogs==1.4.6
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@44.5.1#egg=notifications-utils==44.5.1
|
git+https://github.com/alphagov/notifications-utils.git@45.0.1#egg=notifications-utils==45.0.1
|
||||||
|
|
||||||
# gds-metrics requires prometheseus 0.2.0, override that requirement as 0.7.1 brings significant performance gains
|
# gds-metrics requires prometheseus 0.2.0, override that requirement as 0.7.1 brings significant performance gains
|
||||||
prometheus-client==0.10.1
|
prometheus-client==0.10.1
|
||||||
@@ -51,16 +51,16 @@ alembic==1.6.5
|
|||||||
amqp==1.4.9
|
amqp==1.4.9
|
||||||
anyjson==0.3.3
|
anyjson==0.3.3
|
||||||
attrs==21.2.0
|
attrs==21.2.0
|
||||||
awscli==1.20.8
|
awscli==1.20.24
|
||||||
bcrypt==3.2.0
|
bcrypt==3.2.0
|
||||||
billiard==3.3.0.23
|
billiard==3.3.0.23
|
||||||
bleach==3.3.0
|
bleach==3.3.0
|
||||||
blinker==1.4
|
blinker==1.4
|
||||||
boto==2.49.0
|
boto==2.49.0
|
||||||
boto3==1.18.8
|
boto3==1.18.24
|
||||||
botocore==1.21.8
|
botocore==1.21.24
|
||||||
certifi==2021.5.30
|
certifi==2021.5.30
|
||||||
charset-normalizer==2.0.3
|
charset-normalizer==2.0.4
|
||||||
click==8.0.1
|
click==8.0.1
|
||||||
colorama==0.4.3
|
colorama==0.4.3
|
||||||
dnspython==1.16.0
|
dnspython==1.16.0
|
||||||
@@ -68,8 +68,9 @@ docutils==0.15.2
|
|||||||
flask-redis==0.4.0
|
flask-redis==0.4.0
|
||||||
geojson==2.5.0
|
geojson==2.5.0
|
||||||
govuk-bank-holidays==0.9
|
govuk-bank-holidays==0.9
|
||||||
greenlet==1.1.0
|
greenlet==1.1.1
|
||||||
idna==3.2
|
idna==3.2
|
||||||
|
importlib-metadata==4.6.4
|
||||||
Jinja2==3.0.1
|
Jinja2==3.0.1
|
||||||
jmespath==0.10.0
|
jmespath==0.10.0
|
||||||
kombu==3.0.37
|
kombu==3.0.37
|
||||||
@@ -78,11 +79,12 @@ MarkupSafe==2.0.1
|
|||||||
mistune==0.8.4
|
mistune==0.8.4
|
||||||
orderedset==2.0.3
|
orderedset==2.0.3
|
||||||
packaging==21.0
|
packaging==21.0
|
||||||
phonenumbers==8.12.28
|
phonenumbers==8.12.30
|
||||||
pyasn1==0.4.8
|
pyasn1==0.4.8
|
||||||
pycparser==2.20
|
pycparser==2.20
|
||||||
pyparsing==2.4.7
|
pyparsing==2.4.7
|
||||||
PyPDF2==1.26.0
|
PyPDF2==1.26.0
|
||||||
|
pyproj==3.0.1
|
||||||
pyrsistent==0.18.0
|
pyrsistent==0.18.0
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
python-editor==1.0.4
|
python-editor==1.0.4
|
||||||
@@ -98,5 +100,7 @@ six==1.16.0
|
|||||||
smartypants==2.0.1
|
smartypants==2.0.1
|
||||||
soupsieve==2.2.1
|
soupsieve==2.2.1
|
||||||
statsd==3.3.0
|
statsd==3.3.0
|
||||||
|
typing-extensions==3.10.0.0
|
||||||
urllib3==1.26.6
|
urllib3==1.26.6
|
||||||
webencodings==0.5.1
|
webencodings==0.5.1
|
||||||
|
zipp==3.5.0
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -103,9 +103,9 @@ def test_valid_post_cap_xml_broadcast_returns_201(
|
|||||||
assert response_json['personalisation'] is None
|
assert response_json['personalisation'] is None
|
||||||
assert response_json['service_id'] == str(sample_broadcast_service.id)
|
assert response_json['service_id'] == str(sample_broadcast_service.id)
|
||||||
assert len(response_json['simple_polygons']) == 1
|
assert len(response_json['simple_polygons']) == 1
|
||||||
assert len(response_json['simple_polygons'][0]) == 23
|
assert len(response_json['simple_polygons'][0]) == 29
|
||||||
assert response_json['simple_polygons'][0][0] == [53.10562, 0.244127]
|
assert response_json['simple_polygons'][0][0] == [53.10569, 0.24453]
|
||||||
assert response_json['simple_polygons'][0][-1] == [53.10562, 0.244127]
|
assert response_json['simple_polygons'][0][-1] == [53.10569, 0.24453]
|
||||||
assert response_json['starts_at'] is None
|
assert response_json['starts_at'] is None
|
||||||
assert response_json['status'] == 'pending-approval'
|
assert response_json['status'] == 'pending-approval'
|
||||||
assert response_json['template_id'] is None
|
assert response_json['template_id'] is None
|
||||||
@@ -114,6 +114,27 @@ def test_valid_post_cap_xml_broadcast_returns_201(
|
|||||||
assert response_json['updated_at'] is None
|
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['simple_polygons']) == 1
|
||||||
|
assert len(response_json['simple_polygons'][0]) == 110
|
||||||
|
|
||||||
|
assert response_json['simple_polygons'][0][0] == [54.419546, -2.988521]
|
||||||
|
assert response_json['simple_polygons'][0][-1] == [54.419546, -2.988521]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("training_mode_service", [True, False])
|
@pytest.mark.parametrize("training_mode_service", [True, False])
|
||||||
def test_valid_post_cap_xml_broadcast_sets_stubbed_to_true_for_training_mode_services(
|
def test_valid_post_cap_xml_broadcast_sets_stubbed_to_true_for_training_mode_services(
|
||||||
client,
|
client,
|
||||||
|
|||||||
Reference in New Issue
Block a user