mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 03:13:42 -05:00
Add method to get wards for custom polygon
This will be used as part of the area aggregation in the following commits.
This commit is contained in:
@@ -162,6 +162,13 @@ class CustomBroadcastArea(BaseBroadcastArea):
|
||||
|
||||
simple_polygons = polygons
|
||||
|
||||
@cached_property
|
||||
def overlapping_electoral_wards(self):
|
||||
return [
|
||||
area for area in self.nearby_electoral_wards
|
||||
if area.simple_polygons.intersects(self.polygons)
|
||||
]
|
||||
|
||||
@cached_property
|
||||
def nearby_electoral_wards(self):
|
||||
if not self.polygons:
|
||||
|
||||
@@ -13,3 +13,11 @@ SKYE = [
|
||||
[57.7334, -6.8280],
|
||||
[57.1004, -6.8280],
|
||||
]
|
||||
|
||||
SANTA_A = [
|
||||
[25.8890, 66.5500],
|
||||
[25.8890, 66.551],
|
||||
[25.8910, 66.551],
|
||||
[25.8910, 66.5500],
|
||||
[25.889, 66.55000],
|
||||
]
|
||||
|
||||
20
tests/app/broadcast_areas/test_models.py
Normal file
20
tests/app/broadcast_areas/test_models.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import pytest
|
||||
|
||||
from app.broadcast_areas.models import CustomBroadcastArea
|
||||
from tests.app.broadcast_areas.custom_polygons import BRISTOL, SANTA_A, SKYE
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('simple_polygon', 'expected_wards_length'), [
|
||||
(SKYE, 2),
|
||||
(BRISTOL, 12),
|
||||
(SANTA_A, 0) # does not overlap with UK
|
||||
])
|
||||
def test_custom_broadcast_area_overlapping_electoral_wards(
|
||||
simple_polygon,
|
||||
expected_wards_length,
|
||||
):
|
||||
custom_area = CustomBroadcastArea(
|
||||
name='foo', polygons=[simple_polygon]
|
||||
)
|
||||
|
||||
assert len(custom_area.overlapping_electoral_wards) == expected_wards_length
|
||||
Reference in New Issue
Block a user