1
+ from sentry import audit_log
1
2
from sentry .api .serializers import serialize
3
+ from sentry .deletions .models .scheduleddeletion import RegionScheduledDeletion
4
+ from sentry .deletions .tasks .scheduled import run_scheduled_deletions
5
+ from sentry .models .auditlogentry import AuditLogEntry
6
+ from sentry .silo .base import SiloMode
2
7
from sentry .testutils .cases import APITestCase
3
- from sentry .testutils .silo import region_silo_test
8
+ from sentry .testutils .helpers import TaskRunner
9
+ from sentry .testutils .outbox import outbox_runner
10
+ from sentry .testutils .silo import assume_test_silo_mode , region_silo_test
11
+ from sentry .workflow_engine .models import Action , DataConditionGroup
12
+ from tests .sentry .workflow_engine .test_base import BaseWorkflowTest
4
13
5
14
6
15
class OrganizationWorkflowDetailsBaseTest (APITestCase ):
@@ -20,3 +29,92 @@ def test_simple(self):
20
29
21
30
def test_does_not_exist (self ):
22
31
self .get_error_response (self .organization .slug , 3 , status_code = 404 )
32
+
33
+
34
+ @region_silo_test
35
+ class OrganizationDeleteWorkflowTest (OrganizationWorkflowDetailsBaseTest , BaseWorkflowTest ):
36
+ method = "DELETE"
37
+
38
+ def tasks (self ):
39
+ return TaskRunner ()
40
+
41
+ def setUp (self ):
42
+ super ().setUp ()
43
+ self .workflow = self .create_workflow (organization_id = self .organization .id )
44
+
45
+ def test_simple (self ):
46
+ with outbox_runner ():
47
+ self .get_success_response (self .organization .slug , self .workflow .id )
48
+
49
+ assert RegionScheduledDeletion .objects .filter (
50
+ model_name = "Workflow" ,
51
+ object_id = self .workflow .id ,
52
+ ).exists ()
53
+
54
+ def test_audit_entry (self ):
55
+ with outbox_runner ():
56
+ self .get_success_response (self .organization .slug , self .workflow .id )
57
+
58
+ with assume_test_silo_mode (SiloMode .CONTROL ):
59
+ assert AuditLogEntry .objects .filter (
60
+ target_object = self .workflow .id ,
61
+ event = audit_log .get_event_id ("WORKFLOW_REMOVE" ),
62
+ actor = self .user ,
63
+ ).exists ()
64
+
65
+ def test_does_not_exist (self ):
66
+ with outbox_runner ():
67
+ response = self .get_error_response (self .organization .slug , - 1 )
68
+ assert response .status_code == 404
69
+
70
+ # Ensure it wasn't deleted
71
+ assert not RegionScheduledDeletion .objects .filter (
72
+ model_name = "Workflow" ,
73
+ object_id = self .workflow .id ,
74
+ ).exists ()
75
+
76
+ def test_delete_configured_workflow__action (self ):
77
+ action_condition_group , action = self .create_workflow_action (workflow = self .workflow )
78
+
79
+ with outbox_runner ():
80
+ self .get_success_response (self .organization .slug , self .workflow .id )
81
+
82
+ # Ensure the workflow is scheduled for deletion
83
+ assert RegionScheduledDeletion .objects .filter (
84
+ model_name = "Workflow" ,
85
+ object_id = self .workflow .id ,
86
+ ).exists ()
87
+
88
+ # Delete the workflow
89
+ with self .tasks ():
90
+ run_scheduled_deletions ()
91
+
92
+ # Ensure action is removed
93
+ assert not Action .objects .filter (id = action .id ).exists ()
94
+
95
+ def test_delete_configured_workflow__action_condition (self ):
96
+ action_condition_group , action = self .create_workflow_action (workflow = self .workflow )
97
+
98
+ with outbox_runner ():
99
+ self .get_success_response (self .organization .slug , self .workflow .id )
100
+
101
+ # Ensure the workflow is scheduled for deletion
102
+ assert RegionScheduledDeletion .objects .filter (
103
+ model_name = "Workflow" ,
104
+ object_id = self .workflow .id ,
105
+ ).exists ()
106
+
107
+ # Actually delete the workflow
108
+ with self .tasks ():
109
+ run_scheduled_deletions ()
110
+
111
+ assert not DataConditionGroup .objects .filter (id = action_condition_group .id ).exists ()
112
+
113
+ def test_without_permissions (self ):
114
+ # Create a workflow with a different organization
115
+ new_org = self .create_organization ()
116
+ workflow = self .create_workflow (organization_id = new_org .id )
117
+
118
+ with outbox_runner ():
119
+ response = self .get_error_response (self .organization .slug , workflow .id )
120
+ assert response .status_code == 404
0 commit comments