mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-07 11:08:26 -04:00
Merge pull request #2990 from alphagov/serialise-broadcast-content
Serialise content in broadcast message response
This commit is contained in:
@@ -2242,6 +2242,12 @@ class BroadcastMessage(db.Model):
|
|||||||
approved_by = db.relationship('User', foreign_keys=[approved_by_id])
|
approved_by = db.relationship('User', foreign_keys=[approved_by_id])
|
||||||
cancelled_by = db.relationship('User', foreign_keys=[cancelled_by_id])
|
cancelled_by = db.relationship('User', foreign_keys=[cancelled_by_id])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def content(self):
|
||||||
|
return self.template._as_utils_template_with_personalisation(
|
||||||
|
self.personalisation
|
||||||
|
).content_with_placeholders_filled_in
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def personalisation(self):
|
def personalisation(self):
|
||||||
if self._personalisation:
|
if self._personalisation:
|
||||||
@@ -2261,6 +2267,7 @@ class BroadcastMessage(db.Model):
|
|||||||
'template_id': str(self.template_id),
|
'template_id': str(self.template_id),
|
||||||
'template_version': self.template_version,
|
'template_version': self.template_version,
|
||||||
'template_name': self.template.name,
|
'template_name': self.template.name,
|
||||||
|
'content': self.content,
|
||||||
|
|
||||||
'personalisation': self.personalisation,
|
'personalisation': self.personalisation,
|
||||||
'areas': self.areas.get("areas", []),
|
'areas': self.areas.get("areas", []),
|
||||||
|
|||||||
@@ -10,11 +10,21 @@ from tests.app.db import create_broadcast_message, create_template, create_servi
|
|||||||
|
|
||||||
|
|
||||||
def test_get_broadcast_message(admin_request, sample_broadcast_service):
|
def test_get_broadcast_message(admin_request, sample_broadcast_service):
|
||||||
t = create_template(sample_broadcast_service, BROADCAST_TYPE)
|
t = create_template(
|
||||||
bm = create_broadcast_message(t, areas={
|
sample_broadcast_service,
|
||||||
"areas": ['place A', 'region B'],
|
BROADCAST_TYPE,
|
||||||
"simple_polygons": [[[50.1, 1.2], [50.12, 1.2], [50.13, 1.2]]]
|
content='This is a ((thing))'
|
||||||
})
|
)
|
||||||
|
bm = create_broadcast_message(
|
||||||
|
t,
|
||||||
|
areas={
|
||||||
|
"areas": ['place A', 'region B'],
|
||||||
|
"simple_polygons": [[[50.1, 1.2], [50.12, 1.2], [50.13, 1.2]]],
|
||||||
|
},
|
||||||
|
personalisation={
|
||||||
|
'thing': 'test',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
response = admin_request.get(
|
response = admin_request.get(
|
||||||
'broadcast_message.get_broadcast_message',
|
'broadcast_message.get_broadcast_message',
|
||||||
@@ -24,12 +34,14 @@ def test_get_broadcast_message(admin_request, sample_broadcast_service):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert response['id'] == str(bm.id)
|
assert response['id'] == str(bm.id)
|
||||||
|
assert response['template_id'] == str(t.id)
|
||||||
|
assert response['content'] == 'This is a test'
|
||||||
assert response['template_name'] == t.name
|
assert response['template_name'] == t.name
|
||||||
assert response['status'] == BroadcastStatusType.DRAFT
|
assert response['status'] == BroadcastStatusType.DRAFT
|
||||||
assert response['created_at'] is not None
|
assert response['created_at'] is not None
|
||||||
assert response['starts_at'] is None
|
assert response['starts_at'] is None
|
||||||
assert response['areas'] == ['place A', 'region B']
|
assert response['areas'] == ['place A', 'region B']
|
||||||
assert response['personalisation'] == {}
|
assert response['personalisation'] == {'thing': 'test'}
|
||||||
|
|
||||||
|
|
||||||
def test_get_broadcast_message_404s_if_message_doesnt_exist(admin_request, sample_broadcast_service):
|
def test_get_broadcast_message_404s_if_message_doesnt_exist(admin_request, sample_broadcast_service):
|
||||||
|
|||||||
Reference in New Issue
Block a user