Skip to content

Commit 1d88eb1

Browse files
committed
tests lol
1 parent 5863db8 commit 1d88eb1

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/sentry/sentry_apps/models/sentry_app_installation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from collections.abc import Collection, Mapping
55
from typing import TYPE_CHECKING, Any, ClassVar, overload
66

7-
from django.db import models
7+
from django.db import models, router, transaction
88
from django.utils import timezone
99
from jsonschema import ValidationError
1010

@@ -124,6 +124,12 @@ def save(self, *args, **kwargs):
124124
self.date_updated = timezone.now()
125125
return super().save(*args, **kwargs)
126126

127+
def delete(self, *args, **kwargs):
128+
with outbox_context(transaction.atomic(using=router.db_for_write(SentryAppInstallation))):
129+
for outbox in self.outboxes_for_delete():
130+
outbox.save()
131+
return super().delete(*args, **kwargs)
132+
127133
@property
128134
def api_application_id(self) -> int | None:
129135
from sentry.sentry_apps.models.sentry_app import SentryApp

tests/sentry/deletions/test_sentry_app_installations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from sentry.silo.base import SiloMode
1818
from sentry.silo.safety import unguarded_write
1919
from sentry.testutils.cases import TestCase
20+
from sentry.testutils.helpers.options import override_options
2021
from sentry.testutils.outbox import outbox_runner
2122
from sentry.testutils.silo import assume_test_silo_mode, control_silo_test
2223
from sentry.workflow_engine.models import Action
@@ -111,6 +112,7 @@ def test_soft_deletes_installation(self) -> None:
111112

112113
assert c.fetchone()[0] == 1
113114

115+
@override_options({"workflow_engine.sentry-app-actions-outbox": True})
114116
def test_disables_actions(self) -> None:
115117
action = self.create_action(
116118
type=Action.Type.SENTRY_APP,
@@ -129,6 +131,8 @@ def test_disables_actions(self) -> None:
129131
},
130132
)
131133
deletions.exec_sync(self.install)
134+
with outbox_runner():
135+
pass
132136

133137
action.refresh_from_db()
134138
assert action.status == ObjectStatus.DISABLED

tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installation_details.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@
88
SentryAppInstallationUpdatedEvent,
99
)
1010
from sentry.analytics.events.sentry_app_uninstalled import SentryAppUninstalledEvent
11-
from sentry.constants import SentryAppInstallationStatus
11+
from sentry.constants import ObjectStatus, SentryAppInstallationStatus
1212
from sentry.deletions.tasks.scheduled import run_scheduled_deletions_control
1313
from sentry.models.auditlogentry import AuditLogEntry
14+
from sentry.notifications.models.notificationaction import ActionTarget
1415
from sentry.sentry_apps.models.sentry_app_installation import SentryAppInstallation
1516
from sentry.sentry_apps.token_exchange.grant_exchanger import GrantExchanger
1617
from sentry.testutils.cases import APITestCase
1718
from sentry.testutils.helpers.analytics import assert_last_analytics_event
19+
from sentry.testutils.helpers.options import override_options
20+
from sentry.testutils.outbox import outbox_runner
1821
from sentry.testutils.silo import control_silo_test
1922
from sentry.users.services.user.service import user_service
2023
from sentry.utils import json
24+
from sentry.workflow_engine.models.action import Action
25+
from sentry.workflow_engine.typings.notification_action import SentryAppIdentifier
2126

2227

2328
class SentryAppInstallationDetailsTest(APITestCase):
@@ -103,6 +108,7 @@ def test_no_access_outside_install_organization(self) -> None:
103108
class DeleteSentryAppInstallationDetailsTest(SentryAppInstallationDetailsTest):
104109
@responses.activate
105110
@patch("sentry.analytics.record")
111+
@override_options({"workflow_engine.sentry-app-actions-outbox": True})
106112
def test_delete_install(self, record: MagicMock) -> None:
107113
responses.add(url="https://example.com/webhook", method=responses.POST, body=b"")
108114
self.login_as(user=self.user)
@@ -122,9 +128,24 @@ def test_delete_install(self, record: MagicMock) -> None:
122128
),
123129
)
124130

131+
action = self.create_action(
132+
type=Action.Type.SENTRY_APP,
133+
config={
134+
"target_identifier": self.installation2.uuid,
135+
"sentry_app_identifier": SentryAppIdentifier.SENTRY_APP_INSTALLATION_UUID,
136+
"target_type": ActionTarget.SENTRY_APP,
137+
},
138+
)
139+
125140
with self.tasks():
126141
run_scheduled_deletions_control()
127142

143+
with outbox_runner():
144+
pass
145+
146+
action.refresh_from_db()
147+
assert action.status == ObjectStatus.DISABLED
148+
128149
assert not SentryAppInstallation.objects.filter(id=self.installation2.id).exists()
129150

130151
response_body = json.loads(responses.calls[0].request.body)

0 commit comments

Comments
 (0)