mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
Merge pull request #3833 from alphagov/vary-bleed-by-population-density
Vary bleed amount based on population density
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from math import isclose
|
||||
|
||||
import pytest
|
||||
|
||||
from app.broadcast_areas import (
|
||||
@@ -10,6 +12,10 @@ from app.broadcast_areas.populations import (
|
||||
)
|
||||
|
||||
|
||||
def close_enough(a, b):
|
||||
return isclose(a, b, rel_tol=0.001) # Within 0.1% difference
|
||||
|
||||
|
||||
def test_loads_libraries():
|
||||
assert [
|
||||
(library.id, library.name, library.is_group) for library in sorted(broadcast_area_libraries)
|
||||
@@ -272,3 +278,75 @@ def test_estimate_number_of_smartphones_for_population(
|
||||
assert estimate_number_of_smartphones_for_population(
|
||||
population
|
||||
) == expected_estimate
|
||||
|
||||
|
||||
@pytest.mark.parametrize('area, expected_phones_per_square_mile', (
|
||||
(
|
||||
# Islington (most dense in UK)
|
||||
'lad20-E09000019', 21_348
|
||||
),
|
||||
(
|
||||
# Cordwainer Ward (City of London)
|
||||
# This is higher than Islington because we inflate the
|
||||
# popualtion to account for daytime workers
|
||||
'wd20-E05009300', 310_674
|
||||
),
|
||||
(
|
||||
# Crewe East
|
||||
'wd20-E05008621', 2_078),
|
||||
(
|
||||
# Eden (Cumbria, least dense in England)
|
||||
'lad20-E07000030', 25.57
|
||||
),
|
||||
(
|
||||
# Highland (least dense in UK)
|
||||
'lad20-S12000017', 4.40
|
||||
),
|
||||
))
|
||||
def test_phone_density(
|
||||
area, expected_phones_per_square_mile,
|
||||
):
|
||||
assert close_enough(
|
||||
broadcast_area_libraries.get_areas(area)[0].phone_density,
|
||||
expected_phones_per_square_mile,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('area, expected_bleed_in_m, expected_bleed_in_degrees', (
|
||||
(
|
||||
# Islington (most dense in UK)
|
||||
'lad20-E09000019', 500, 0.00449
|
||||
),
|
||||
(
|
||||
# Cordwainer Ward (City of London)
|
||||
# Special case because of inflated daytime population
|
||||
'wd20-E05009300', 500, 0.00449
|
||||
),
|
||||
(
|
||||
# Crewe East
|
||||
'wd20-E05008621', 1_752, 0.01574
|
||||
),
|
||||
(
|
||||
# Eden (Cumbria, least dense in England)
|
||||
'lad20-E07000030', 4_140, 0.0372
|
||||
),
|
||||
(
|
||||
# Highland (least dense in UK)
|
||||
'lad20-S12000017', 5_000, 0.0449
|
||||
),
|
||||
(
|
||||
# No population data available
|
||||
'test-santa-claus-village-rovaniemi', 1_500, 0.01347
|
||||
)
|
||||
))
|
||||
def test_estimated_bleed(
|
||||
area, expected_bleed_in_m, expected_bleed_in_degrees,
|
||||
):
|
||||
assert close_enough(
|
||||
broadcast_area_libraries.get_areas(area)[0].estimated_bleed_in_m,
|
||||
expected_bleed_in_m,
|
||||
)
|
||||
assert close_enough(
|
||||
broadcast_area_libraries.get_areas(area)[0].estimated_bleed_in_degrees,
|
||||
expected_bleed_in_degrees,
|
||||
)
|
||||
|
||||
@@ -623,7 +623,7 @@ def test_broadcast_page(
|
||||
'Scotland remove',
|
||||
], [
|
||||
'An area of 177,439.8 square miles Will get the alert',
|
||||
'An extra area of 3,058.9 square miles is Likely to get the alert',
|
||||
'An extra area of 6,392.3 square miles is Likely to get the alert',
|
||||
'40,000,000 phones estimated',
|
||||
]),
|
||||
([
|
||||
@@ -640,8 +640,17 @@ def test_broadcast_page(
|
||||
'Penrith West remove',
|
||||
], [
|
||||
'An area of 6.3 square miles Will get the alert',
|
||||
'An extra area of 14.4 square miles is Likely to get the alert',
|
||||
'9,000 to 30,000 phones',
|
||||
'An extra area of 22.6 square miles is Likely to get the alert',
|
||||
'9,000 to 40,000 phones',
|
||||
]),
|
||||
([
|
||||
'lad20-E09000019',
|
||||
], [
|
||||
'Islington remove',
|
||||
], [
|
||||
'An area of 9.7 square miles Will get the alert',
|
||||
'An extra area of 4.7 square miles is Likely to get the alert',
|
||||
'200,000 to 300,000 phones',
|
||||
]),
|
||||
))
|
||||
def test_preview_broadcast_areas_page(
|
||||
@@ -726,7 +735,7 @@ def test_preview_broadcast_areas_page_with_custom_polygons(
|
||||
for item in page.select('ul li.area-list-key')
|
||||
] == [
|
||||
'An area of 722.3 square miles Will get the alert',
|
||||
'An extra area of 1,402.5 square miles is Likely to get the alert',
|
||||
'An extra area of 1,498.5 square miles is Likely to get the alert',
|
||||
'Unknown number of phones',
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user