|
1 | 1 | import os |
| 2 | +from unittest import mock |
| 3 | + |
2 | 4 |
|
3 | 5 | from django.conf import settings |
4 | 6 |
|
|
23 | 25 | DisasterType, |
24 | 26 | District |
25 | 27 | ) |
| 28 | +from dref.tasks import send_dref_email |
26 | 29 |
|
27 | 30 |
|
28 | 31 | class DrefTestCase(APITestCase): |
@@ -116,7 +119,8 @@ def test_get_dref(self): |
116 | 119 | self.assertEqual(resp.status_code, 200) |
117 | 120 | self.assertEqual(len(resp.data['results']), 0) |
118 | 121 |
|
119 | | - def test_post_dref_creation(self): |
| 122 | + @mock.patch('notifications.notification.send_notification') |
| 123 | + def test_post_dref_creation(self, send_notification): |
120 | 124 | old_count = Dref.objects.count() |
121 | 125 | national_society = Country.objects.create(name='xzz') |
122 | 126 | disaster_type = DisasterType.objects.create(name='abc') |
@@ -218,12 +222,20 @@ def test_post_dref_creation(self): |
218 | 222 | ] |
219 | 223 | } |
220 | 224 | ], |
| 225 | + 'users': [self.user.id] |
221 | 226 | } |
222 | 227 | url = '/api/v2/dref/' |
223 | 228 | self.client.force_authenticate(self.user) |
224 | 229 | response = self.client.post(url, data, format='json') |
225 | 230 | self.assertEqual(response.status_code, 201) |
226 | 231 | 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) |
227 | 239 |
|
228 | 240 | def test_event_date_in_dref(self): |
229 | 241 | """ |
|
0 commit comments