Skip to content

Commit 3fd234d

Browse files
committed
Add test for dref notifications
1 parent d63e932 commit 3fd234d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

dref/test_views.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
from unittest import mock
3+
24

35
from django.conf import settings
46

@@ -23,6 +25,7 @@
2325
DisasterType,
2426
District
2527
)
28+
from dref.tasks import send_dref_email
2629

2730

2831
class DrefTestCase(APITestCase):
@@ -116,7 +119,8 @@ def test_get_dref(self):
116119
self.assertEqual(resp.status_code, 200)
117120
self.assertEqual(len(resp.data['results']), 0)
118121

119-
def test_post_dref_creation(self):
122+
@mock.patch('notifications.notification.send_notification')
123+
def test_post_dref_creation(self, send_notification):
120124
old_count = Dref.objects.count()
121125
national_society = Country.objects.create(name='xzz')
122126
disaster_type = DisasterType.objects.create(name='abc')
@@ -218,12 +222,20 @@ def test_post_dref_creation(self):
218222
]
219223
}
220224
],
225+
'users': [self.user.id]
221226
}
222227
url = '/api/v2/dref/'
223228
self.client.force_authenticate(self.user)
224229
response = self.client.post(url, data, format='json')
225230
self.assertEqual(response.status_code, 201)
226231
self.assertEqual(Dref.objects.count(), old_count + 1)
232+
instance = Dref.objects.get(id=response.data['id'])
233+
instance_user_email = [user.email for user in instance.users.all()]
234+
235+
# call email send task
236+
email_data = send_dref_email(instance.id, instance_user_email)
237+
self.assertTrue(send_notification.assert_called)
238+
self.assertEqual(email_data['title'], instance.title)
227239

228240
def test_event_date_in_dref(self):
229241
"""

0 commit comments

Comments
 (0)