@@ -159,6 +159,45 @@ def test_task_new_rule_project_id(self, mock_set_value: MagicMock) -> None:
159159 ]
160160 assert rule .created_by_id == self .user .id
161161
162+ @responses .activate
163+ @patch .object (RedisRuleStatus , "set_value" , return_value = None )
164+ def test_task_new_rule_with_owner (self , mock_set_value : MagicMock ) -> None :
165+ """Test that owner identifier string is deserialized to Actor correctly."""
166+ team = self .create_team (organization = self .organization )
167+ owner_identifier = f"team:{ team .id } "
168+
169+ data = {
170+ "name" : "New Rule with Owner" ,
171+ "environment" : None ,
172+ "project_id" : self .project .id ,
173+ "action_match" : "all" ,
174+ "filter_match" : "all" ,
175+ "conditions" : [
176+ {"id" : "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition" }
177+ ],
178+ "actions" : [
179+ {
180+ "channel" : "#my-channel" ,
181+ "id" : "sentry.integrations.slack.notify_action.SlackNotifyServiceAction" ,
182+ "tags" : "" ,
183+ "workspace" : self .integration .id ,
184+ }
185+ ],
186+ "frequency" : 5 ,
187+ "uuid" : self .uuid ,
188+ "user_id" : self .user .id ,
189+ "owner" : owner_identifier ,
190+ }
191+
192+ with self .tasks ():
193+ find_channel_id_for_rule (** data )
194+
195+ rule = Rule .objects .exclude (label__in = [DEFAULT_RULE_LABEL ]).get (project_id = self .project .id )
196+ mock_set_value .assert_called_with ("success" , rule .id )
197+ assert rule .label == "New Rule with Owner"
198+ assert rule .owner_team_id == team .id
199+ assert rule .owner_user_id is None
200+
162201 @responses .activate
163202 @patch .object (RedisRuleStatus , "set_value" , return_value = None )
164203 def test_task_existing_rule (self , mock_set_value : MagicMock ) -> None :
@@ -205,6 +244,48 @@ def test_task_existing_rule(self, mock_set_value: MagicMock) -> None:
205244 }
206245 ]
207246
247+ @responses .activate
248+ @patch .object (RedisRuleStatus , "set_value" , return_value = None )
249+ def test_task_existing_rule_with_owner (self , mock_set_value : MagicMock ) -> None :
250+ """Test that owner identifier string is deserialized to Actor correctly during update."""
251+ action_data = {"id" : "sentry.rules.actions.notify_event.NotifyEventAction" }
252+ condition_data = {"id" : "sentry.rules.conditions.every_event.EveryEventCondition" }
253+ rule = Rule .objects .create (
254+ project = self .project , data = {"actions" : [action_data ], "conditions" : [condition_data ]}
255+ )
256+
257+ owner_identifier = f"user:{ self .user .id } "
258+
259+ data = {
260+ "name" : "Updated Rule with Owner" ,
261+ "environment" : None ,
262+ "project_id" : self .project .id ,
263+ "action_match" : "all" ,
264+ "filter_match" : "all" ,
265+ "conditions" : [condition_data ],
266+ "actions" : [
267+ {
268+ "channel" : "#my-channel" ,
269+ "id" : "sentry.integrations.slack.notify_action.SlackNotifyServiceAction" ,
270+ "tags" : "" ,
271+ "workspace" : self .integration .id ,
272+ }
273+ ],
274+ "frequency" : 5 ,
275+ "uuid" : self .uuid ,
276+ "rule_id" : rule .id ,
277+ "owner" : owner_identifier ,
278+ }
279+
280+ with self .tasks ():
281+ find_channel_id_for_rule (** data )
282+
283+ updated_rule = Rule .objects .get (id = rule .id )
284+ mock_set_value .assert_called_with ("success" , rule .id )
285+ assert updated_rule .label == "Updated Rule with Owner"
286+ assert updated_rule .owner_user_id == self .user .id
287+ assert updated_rule .owner_team_id is None
288+
208289 @responses .activate
209290 @patch .object (RedisRuleStatus , "set_value" , return_value = None )
210291 @patch (
0 commit comments