From 53fd5b886938fda9ee4377122e2a4af5f44f70b2 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 12 Aug 2020 12:02:56 +0100 Subject: [PATCH] Exclude grouped areas from examples The given examples should match the choices offered when you visit the next page. The choices offered on the next page are either the areas (when a library is not grouped) or the groups (when a library is grouped). This commit makes the examples match the choices by excluding sub-areas, ie those that have a grouping ID. --- app/broadcast_areas/repo.py | 7 +++++-- tests/app/broadcast_areas/test_broadcast_area.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/broadcast_areas/repo.py b/app/broadcast_areas/repo.py index dca7c2188..171e544ba 100644 --- a/app/broadcast_areas/repo.py +++ b/app/broadcast_areas/repo.py @@ -114,8 +114,11 @@ class BroadcastAreasRepository(object): def get_library_description(self, library_id): q = """ WITH - areas AS (SELECT * FROM broadcast_areas - WHERE broadcast_area_library_id = ?), + areas AS ( + SELECT * FROM broadcast_areas + WHERE broadcast_area_library_id = ? + AND broadcast_area_library_group_id IS NULL + ), area_count AS (SELECT COUNT(*) AS c FROM areas), subset_area_count AS (SELECT c - 4 FROM area_count), description_area_names AS (SELECT name FROM areas LIMIT 4), diff --git a/tests/app/broadcast_areas/test_broadcast_area.py b/tests/app/broadcast_areas/test_broadcast_area.py index 4e8459de6..66226ea7d 100644 --- a/tests/app/broadcast_areas/test_broadcast_area.py +++ b/tests/app/broadcast_areas/test_broadcast_area.py @@ -61,7 +61,7 @@ def test_examples(): wards = broadcast_area_libraries.get( 'electoral-wards-of-the-united-kingdom', ).get_examples() - assert wards == 'Abbey, Alibon, Becontree, Chadwell Heath, and 8970 more…' + assert wards == 'Hartlepool, Middlesbrough, Redcar and Cleveland, Stockton-on-Tees, and 375 more…' @pytest.mark.parametrize('id', (