1
1
from unittest .mock import patch
2
2
3
3
from django .core import mail
4
- from django .test import TestCase
4
+ from django .test import TestCase , override_settings
5
5
6
+ from openarchiefbeheer .destruction .tasks import delete_destruction_list
6
7
from openarchiefbeheer .emails .models import EmailConfig
7
8
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
+ )
10
15
11
16
12
17
class SignalsTests (TestCase ):
@@ -30,3 +35,34 @@ def test_no_email_sent_if_not_review_created(self, m):
30
35
31
36
# No extra email sent on update event
32
37
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