Skip to content

Commit f1ed308

Browse files
committed
✅ [#93] Test notification on failure
1 parent e7f6972 commit f1ed308

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

backend/src/openarchiefbeheer/destruction/tests/test_signals.py

+39-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
from unittest.mock import patch
22

33
from django.core import mail
4-
from django.test import TestCase
4+
from django.test import TestCase, override_settings
55

6+
from openarchiefbeheer.destruction.tasks import delete_destruction_list
67
from openarchiefbeheer.emails.models import EmailConfig
78

8-
from ..constants import ReviewDecisionChoices
9-
from .factories import DestructionListReviewFactory
9+
from ..constants import ListStatus, ReviewDecisionChoices
10+
from .factories import (
11+
DestructionListFactory,
12+
DestructionListItemFactory,
13+
DestructionListReviewFactory,
14+
)
1015

1116

1217
class SignalsTests(TestCase):
@@ -30,3 +35,34 @@ def test_no_email_sent_if_not_review_created(self, m):
3035

3136
# No extra email sent on update event
3237
self.assertEqual(len(mail.outbox), 1)
38+
39+
@override_settings(CELERY_TASK_ALWAYS_EAGER=True)
40+
def test_failure_during_deletion_sends_signal(self):
41+
destruction_list = DestructionListFactory.create(
42+
status=ListStatus.ready_to_delete, author__email="[email protected]"
43+
)
44+
DestructionListItemFactory.create_batch(2, destruction_list=destruction_list)
45+
46+
with (
47+
patch(
48+
"openarchiefbeheer.destruction.models.delete_zaak_and_related_objects",
49+
side_effect=Exception,
50+
),
51+
patch(
52+
"openarchiefbeheer.destruction.utils.EmailConfig.get_solo",
53+
return_value=EmailConfig(
54+
subject_error_during_deletion="FAILURE!!",
55+
body_error_during_deletion="ERROR AAAh!",
56+
),
57+
),
58+
self.assertRaises(Exception),
59+
):
60+
delete_destruction_list(destruction_list)
61+
62+
self.assertEqual(len(mail.outbox), 1)
63+
64+
email = mail.outbox[0]
65+
66+
self.assertEqual(email.subject, "FAILURE!!")
67+
self.assertEqual(email.body, "ERROR AAAh!")
68+
self.assertEqual(email.to[0], "[email protected]")

0 commit comments

Comments
 (0)