From baf20e00751f6cfc6b84ce969988a85d04cc3a0d Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Mon, 6 Sep 2021 11:57:32 +0100 Subject: [PATCH] Support broadcasts with no areas data Previously we used to return an empty CustomBroadcastAreas object, which doesn't make sense for broadcasts created in this app. --- app/models/broadcast_message.py | 13 +++++++++---- tests/app/models/test_broadcast_message.py | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/broadcast_message.py b/app/models/broadcast_message.py index 247edc478..3a180dba2 100644 --- a/app/models/broadcast_message.py +++ b/app/models/broadcast_message.py @@ -99,10 +99,15 @@ class BroadcastMessage(JSONModel): ) return library_areas - return CustomBroadcastAreas( - names=self._dict['areas']['names'], - polygons=self._dict['areas']['simple_polygons'], - ) + polygons = self._dict['areas'].get('simple_polygons', []) + + if polygons: + return CustomBroadcastAreas( + names=self._dict['areas']['names'], + polygons=polygons, + ) + + return [] @property def area_ids(self): diff --git a/tests/app/models/test_broadcast_message.py b/tests/app/models/test_broadcast_message.py index 423bf2db2..025cd24f1 100644 --- a/tests/app/models/test_broadcast_message.py +++ b/tests/app/models/test_broadcast_message.py @@ -41,6 +41,7 @@ def test_content_comes_from_attribute_not_template(): @pytest.mark.parametrize(('areas', 'expected_length'), [ ({'ids': []}, 0), ({'ids': ['wd20-E05009372']}, 1), + ({'no data': 'just created'}, 0), ({'names': ['somewhere'], 'simple_polygons': [[[3.5, 1.5]]]}, 1) ]) def test_areas(