mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 02:23:19 -04:00
Check that all areas are in the library
We should assume to start with that areas come either from the library or from the JSON, and not a combination of the two.
This commit is contained in:
@@ -78,9 +78,17 @@ class BroadcastMessage(JSONModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def areas(self):
|
def areas(self):
|
||||||
return self.get_areas(
|
library_areas = self.get_areas(areas=self._dict['areas'])
|
||||||
areas=self._dict['areas']
|
|
||||||
) or CustomBroadcastAreas(
|
if library_areas:
|
||||||
|
if len(library_areas) != len(self._dict['areas']):
|
||||||
|
raise RuntimeError(
|
||||||
|
f'BroadcastMessage has {len(self._dict["areas"])} areas '
|
||||||
|
f'but {len(library_areas)} found in the library'
|
||||||
|
)
|
||||||
|
return library_areas
|
||||||
|
|
||||||
|
return CustomBroadcastAreas(
|
||||||
areas=self._dict['areas'],
|
areas=self._dict['areas'],
|
||||||
polygons=self._dict['simple_polygons'],
|
polygons=self._dict['simple_polygons'],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
from app.models.broadcast_message import BroadcastMessage
|
from app.models.broadcast_message import BroadcastMessage
|
||||||
from tests import broadcast_message_json
|
from tests import broadcast_message_json
|
||||||
|
|
||||||
@@ -45,3 +47,24 @@ def test_content_comes_from_attribute_not_template(fake_uuid):
|
|||||||
created_by_id=fake_uuid,
|
created_by_id=fake_uuid,
|
||||||
))
|
))
|
||||||
assert broadcast_message.content == 'This is a test'
|
assert broadcast_message.content == 'This is a test'
|
||||||
|
|
||||||
|
|
||||||
|
def test_raises_for_missing_areas(fake_uuid):
|
||||||
|
broadcast_message = BroadcastMessage(broadcast_message_json(
|
||||||
|
id_=fake_uuid,
|
||||||
|
service_id=fake_uuid,
|
||||||
|
template_id=fake_uuid,
|
||||||
|
status='draft',
|
||||||
|
created_by_id=fake_uuid,
|
||||||
|
areas=[
|
||||||
|
'wd20-E05009372',
|
||||||
|
'something else',
|
||||||
|
],
|
||||||
|
))
|
||||||
|
|
||||||
|
with pytest.raises(RuntimeError) as exception:
|
||||||
|
broadcast_message.areas
|
||||||
|
|
||||||
|
assert str(exception.value) == (
|
||||||
|
'BroadcastMessage has 2 areas but 1 found in the library'
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user