4040from sentry .types .activity import ActivityType
4141from sentry .users .models .user_option import UserOption
4242from sentry .users .models .useremail import UserEmail
43+ from sentry .viewer_context import ActorType , ViewerContext , get_viewer_context
4344
4445
4546class InvalidateReleaseCacheTest (TestCase ):
@@ -326,7 +327,15 @@ def test_matching_author_with_assignment(self) -> None:
326327 )
327328 author .preload_users ()
328329
329- with self .assertLogs ("sentry.issues.action_log" , level = "INFO" ) as logs :
330+ captured_contexts : list [ViewerContext | None ] = []
331+ with (
332+ self .assertLogs ("sentry.issues.action_log" , level = "INFO" ) as logs ,
333+ patch ("sentry.models.groupassignee.issue_assigned.send_robust" ) as send_robust ,
334+ self .capture_on_commit_callbacks (execute = True ),
335+ ):
336+ send_robust .side_effect = lambda ** kwargs : captured_contexts .append (
337+ get_viewer_context ()
338+ )
330339 commit = Commit .objects .create (
331340 key = sha1 (uuid4 ().hex .encode ("utf-8" )).hexdigest (),
332341 organization_id = group .organization .id ,
@@ -338,6 +347,14 @@ def test_matching_author_with_assignment(self) -> None:
338347 self .assertLinkedFromCommitDeferred (group , commit )
339348
340349 assert GroupAssignee .objects .filter (group = group , user_id = user .id ).exists ()
350+ assert captured_contexts == [
351+ ViewerContext (
352+ organization_id = group .organization .id ,
353+ project_id = group .project_id ,
354+ user_id = user .id ,
355+ actor_type = ActorType .USER ,
356+ )
357+ ]
341358
342359 # The self-assign is attributed to the commit author, not logged as a system action.
343360 assign_records = [r for r in logs .records if r .__dict__ .get ("action" ) == "assign" ]
@@ -452,7 +469,15 @@ def test_matching_external_actor_sets_activity_user(self) -> None:
452469 )
453470 author = self ._create_pull_request_author ("newdev" , group .organization .id )
454471
455- pull_request = self ._create_resolving_pull_request (group , repo , author )
472+ captured_contexts : list [ViewerContext | None ] = []
473+ with (
474+ patch ("sentry.models.groupassignee.issue_assigned.send_robust" ) as send_robust ,
475+ self .capture_on_commit_callbacks (execute = True ),
476+ ):
477+ send_robust .side_effect = lambda ** kwargs : captured_contexts .append (
478+ get_viewer_context ()
479+ )
480+ pull_request = self ._create_resolving_pull_request (group , repo , author )
456481
457482 activity = Activity .objects .get (
458483 group = group ,
@@ -461,6 +486,14 @@ def test_matching_external_actor_sets_activity_user(self) -> None:
461486 assert activity .user_id == user .id
462487 assert activity .data == {"pull_request" : pull_request .id }
463488 assert GroupAssignee .objects .filter (group = group , user_id = user .id ).exists ()
489+ assert captured_contexts == [
490+ ViewerContext (
491+ organization_id = group .organization .id ,
492+ project_id = group .project_id ,
493+ user_id = user .id ,
494+ actor_type = ActorType .USER ,
495+ )
496+ ]
464497
465498 @receivers_raise_on_send ()
466499 def test_author_from_different_organization_does_not_set_activity_user (self ) -> None :
0 commit comments