44import responses
55from taskbroker_client .retry import RetryTaskError
66
7+ from sentry import audit_log
78from sentry .constants import ObjectStatus
89from sentry .integrations .github .integration import GitHubIntegrationProvider
910from sentry .integrations .github .tasks .sync_repos import sync_repos_for_org
1011from sentry .integrations .models .organization_integration import OrganizationIntegration
12+ from sentry .models .auditlogentry import AuditLogEntry
1113from sentry .models .repository import Repository
1214from sentry .silo .base import SiloMode
1315from sentry .testutils .cases import IntegrationTestCase
14- from sentry .testutils .silo import assume_test_silo_mode , control_silo_test
16+ from sentry .testutils .silo import assume_test_silo_mode , assume_test_silo_mode_of , control_silo_test
1517
1618
1719@control_silo_test
@@ -60,6 +62,13 @@ def test_creates_new_repos(self, _: MagicMock) -> None:
6062 assert repos [0 ].provider == "integrations:github"
6163 assert repos [1 ].name == "getsentry/snuba"
6264
65+ with assume_test_silo_mode_of (AuditLogEntry ):
66+ entries = AuditLogEntry .objects .filter (
67+ organization_id = self .organization .id ,
68+ event = audit_log .get_event_id ("REPO_ADDED" ),
69+ )
70+ assert entries .count () == 2
71+
6372 @responses .activate
6473 def test_disables_removed_repos (self , _ : MagicMock ) -> None :
6574 with assume_test_silo_mode (SiloMode .CELL ):
@@ -89,6 +98,16 @@ def test_disables_removed_repos(self, _: MagicMock) -> None:
8998 organization_id = self .organization .id , external_id = "1"
9099 ).exists ()
91100
101+ with assume_test_silo_mode_of (AuditLogEntry ):
102+ assert AuditLogEntry .objects .filter (
103+ organization_id = self .organization .id ,
104+ event = audit_log .get_event_id ("REPO_DISABLED" ),
105+ ).exists ()
106+ assert AuditLogEntry .objects .filter (
107+ organization_id = self .organization .id ,
108+ event = audit_log .get_event_id ("REPO_ADDED" ),
109+ ).exists ()
110+
92111 @responses .activate
93112 def test_re_enables_restored_repos (self , _ : MagicMock ) -> None :
94113 with assume_test_silo_mode (SiloMode .CELL ):
@@ -113,6 +132,12 @@ def test_re_enables_restored_repos(self, _: MagicMock) -> None:
113132 repo .refresh_from_db ()
114133 assert repo .status == ObjectStatus .ACTIVE
115134
135+ with assume_test_silo_mode_of (AuditLogEntry ):
136+ assert AuditLogEntry .objects .filter (
137+ organization_id = self .organization .id ,
138+ event = audit_log .get_event_id ("REPO_ENABLED" ),
139+ ).exists ()
140+
116141 @responses .activate
117142 def test_no_changes_needed (self , _ : MagicMock ) -> None :
118143 with assume_test_silo_mode (SiloMode .CELL ):
0 commit comments