2021-08-24 15:01:53 +01:00
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
from app.broadcast_areas.utils import aggregate_areas
|
|
|
|
|
|
from app.models.broadcast_message import BroadcastMessage
|
|
|
|
|
|
from tests import broadcast_message_json
|
|
|
|
|
|
from tests.app.broadcast_areas.custom_polygons import (
|
|
|
|
|
|
BRISTOL,
|
|
|
|
|
|
BURFORD,
|
|
|
|
|
|
CHELTENHAM,
|
2021-08-24 15:49:46 +01:00
|
|
|
|
CHELTENHAM_AND_GLOUCESTER,
|
2021-08-24 15:01:53 +01:00
|
|
|
|
SANTA_A,
|
2021-08-24 15:49:46 +01:00
|
|
|
|
SEVERN_ESTUARY,
|
2021-08-24 15:01:53 +01:00
|
|
|
|
SKYE,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(('area_ids', 'expected_area_names'), [
|
2021-08-24 15:49:46 +01:00
|
|
|
|
(
|
|
|
|
|
|
[
|
|
|
|
|
|
'wd20-E05009336', # Whitechapel, Tower Hamlets (electoral ward)
|
|
|
|
|
|
'wd20-E05009372', # Hackney Central, Hackney (electoral ward)
|
|
|
|
|
|
'wd20-E05009374', # Hackney Wick, Hackney (electoral ward)
|
|
|
|
|
|
], [
|
|
|
|
|
|
'Hackney', # in Greater London* (DB doesn't know this)
|
|
|
|
|
|
'Tower Hamlets', # in Greater London*
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2021-08-24 15:01:53 +01:00
|
|
|
|
(
|
|
|
|
|
|
[
|
|
|
|
|
|
'wd20-E05004294', # Hester’s Way, Cheltenham (electoral ward)
|
|
|
|
|
|
'wd20-E05010981', # Painswick & Upton, Stroud (electoral ward)
|
|
|
|
|
|
], [
|
|
|
|
|
|
'Cheltenham', # in Gloucestershire (upper tier authority)
|
|
|
|
|
|
'Stroud', # in Gloucestershire
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
[
|
|
|
|
|
|
'wd20-E05004294', # Hester’s Way, Cheltenham (electoral ward)
|
|
|
|
|
|
'wd20-E05009372', # Hackney Central (electoral ward)
|
|
|
|
|
|
], [
|
|
|
|
|
|
'Cheltenham', # in Gloucestershire (upper tier authority)
|
|
|
|
|
|
'Hackney', # in Greater London* (DB doesn't know this)
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2021-08-24 15:49:46 +01:00
|
|
|
|
(
|
|
|
|
|
|
[
|
|
|
|
|
|
'wd20-E05004294', # Hester’s Way, Cheltenham (electoral ward)
|
|
|
|
|
|
'wd20-E05010981', # Painswick & Upton, Stroud (electoral ward)
|
|
|
|
|
|
'wd20-E05009372', # Hackney Central, Hackney (electoral ward)
|
|
|
|
|
|
], [
|
|
|
|
|
|
'Gloucestershire', # upper tier authority
|
|
|
|
|
|
'Hackney', # in Greater London* (DB doesn't know this)
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2021-08-24 15:01:53 +01:00
|
|
|
|
(
|
|
|
|
|
|
[
|
|
|
|
|
|
'lad20-E07000037', # High Peak (lower tier authority)
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'High Peak', # in Derbyshire (upper tier authority)
|
|
|
|
|
|
]
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
[
|
|
|
|
|
|
'lad20-E07000037', # High Peak (lower tier authority)
|
|
|
|
|
|
'lad20-E07000035', # Derbyshire Dales (lower tier authority)
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'Derbyshire Dales', # in Derbyshire (upper tier authority)
|
|
|
|
|
|
'High Peak', # in Derbyshire
|
|
|
|
|
|
]
|
|
|
|
|
|
),
|
2021-08-24 15:49:46 +01:00
|
|
|
|
(
|
|
|
|
|
|
[
|
|
|
|
|
|
'lad20-E07000037', # High Peak (lower tier authority)
|
|
|
|
|
|
'lad20-E07000035', # Derbyshire Dales (lower tier authority)
|
|
|
|
|
|
'ctyua19-E10000028', # Staffordshire (upper tier authority)
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'Derbyshire', # upper tier authority
|
|
|
|
|
|
'Staffordshire',
|
|
|
|
|
|
]
|
|
|
|
|
|
),
|
2021-08-24 15:01:53 +01:00
|
|
|
|
(
|
|
|
|
|
|
[
|
|
|
|
|
|
'ctry19-E92000001', # England
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'England',
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_aggregate_areas(
|
|
|
|
|
|
area_ids,
|
|
|
|
|
|
expected_area_names,
|
|
|
|
|
|
):
|
|
|
|
|
|
broadcast_message = BroadcastMessage(
|
|
|
|
|
|
broadcast_message_json(area_ids=area_ids)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-08-27 14:58:45 +01:00
|
|
|
|
assert [
|
2021-08-24 15:01:53 +01:00
|
|
|
|
area.name for area in aggregate_areas(broadcast_message.areas)
|
2021-08-27 14:58:45 +01:00
|
|
|
|
] == expected_area_names
|
2021-08-24 15:11:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(('simple_polygons', 'expected_area_names'), [
|
|
|
|
|
|
(
|
|
|
|
|
|
[SKYE], [
|
|
|
|
|
|
# Area covers a single unitary authority
|
|
|
|
|
|
'Highland',
|
|
|
|
|
|
]
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
[BRISTOL], [
|
|
|
|
|
|
# Area covers a single unitary authority
|
|
|
|
|
|
'Bristol, City of',
|
|
|
|
|
|
]
|
|
|
|
|
|
),
|
2021-08-24 15:49:46 +01:00
|
|
|
|
(
|
|
|
|
|
|
[SEVERN_ESTUARY], [
|
|
|
|
|
|
# Area covers various lower-tier authorities
|
|
|
|
|
|
# with more than three in Gloucestershire so
|
|
|
|
|
|
# we aggregate them into that
|
|
|
|
|
|
'Bristol, City of',
|
|
|
|
|
|
'Gloucestershire',
|
|
|
|
|
|
'Monmouthshire',
|
|
|
|
|
|
'Newport',
|
|
|
|
|
|
'North Somerset',
|
|
|
|
|
|
'South Gloucestershire',
|
|
|
|
|
|
]
|
|
|
|
|
|
),
|
2021-08-24 15:11:00 +01:00
|
|
|
|
(
|
|
|
|
|
|
[CHELTENHAM], [
|
|
|
|
|
|
# Area covers three lower-tier authorities
|
|
|
|
|
|
# in Gloucestershire (upper tier authority)
|
|
|
|
|
|
'Cheltenham',
|
|
|
|
|
|
'Cotswold',
|
|
|
|
|
|
'Tewkesbury',
|
|
|
|
|
|
]
|
|
|
|
|
|
),
|
2021-08-24 15:49:46 +01:00
|
|
|
|
(
|
|
|
|
|
|
[CHELTENHAM_AND_GLOUCESTER], [
|
|
|
|
|
|
# Area covers more than 3 lower-tier authorities
|
|
|
|
|
|
# in Gloucestershire so we aggregate them
|
|
|
|
|
|
'Gloucestershire',
|
|
|
|
|
|
]
|
|
|
|
|
|
),
|
2021-08-24 15:11:00 +01:00
|
|
|
|
(
|
|
|
|
|
|
[BURFORD], [
|
2021-08-24 15:49:46 +01:00
|
|
|
|
# Area covers one lower-tier authority in
|
|
|
|
|
|
# Gloucestershire and one in Oxfordshire (both
|
|
|
|
|
|
# upper tier authorities)
|
2021-08-24 15:11:00 +01:00
|
|
|
|
'Cotswold',
|
|
|
|
|
|
'West Oxfordshire',
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2021-08-24 15:49:46 +01:00
|
|
|
|
(
|
|
|
|
|
|
[CHELTENHAM_AND_GLOUCESTER, BURFORD], [
|
|
|
|
|
|
# Area covers many lower-tier authorities
|
|
|
|
|
|
# in Gloucestershire but only one in Oxfordshire
|
|
|
|
|
|
'Gloucestershire',
|
|
|
|
|
|
'West Oxfordshire',
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2021-08-24 15:11:00 +01:00
|
|
|
|
(
|
|
|
|
|
|
[SANTA_A], [
|
|
|
|
|
|
# Does not overlap with the UK
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_aggregate_areas_for_custom_polygons(
|
|
|
|
|
|
simple_polygons,
|
|
|
|
|
|
expected_area_names,
|
|
|
|
|
|
):
|
|
|
|
|
|
broadcast_message = BroadcastMessage(
|
|
|
|
|
|
broadcast_message_json(
|
2021-09-06 10:02:01 +01:00
|
|
|
|
areas={
|
|
|
|
|
|
'names': [f'polygon {i}' for i, _ in enumerate(simple_polygons)],
|
|
|
|
|
|
'simple_polygons': simple_polygons
|
|
|
|
|
|
}
|
2021-08-24 15:11:00 +01:00
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-08-27 14:58:45 +01:00
|
|
|
|
assert [
|
2021-08-24 15:11:00 +01:00
|
|
|
|
area.name for area in aggregate_areas(broadcast_message.areas)
|
2021-08-27 14:58:45 +01:00
|
|
|
|
] == expected_area_names
|