diff --git a/tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installation_details.py b/tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installation_details.py index 6aac6f121df053..6247e184bb8bbe 100644 --- a/tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installation_details.py +++ b/tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installation_details.py @@ -10,6 +10,8 @@ from sentry.sentry_apps.services.app import app_service from sentry.testutils.cases import APITestCase from sentry.testutils.silo import control_silo_test +from sentry.users.services.user.service import user_service +from sentry.utils import json class SentryAppInstallationDetailsTest(APITestCase): @@ -101,9 +103,10 @@ def test_no_access_outside_install_organization(self): class DeleteSentryAppInstallationDetailsTest(SentryAppInstallationDetailsTest): @responses.activate @patch("sentry.analytics.record") - def test_delete_install(self, record, request): + def test_delete_install(self, record): responses.add(url="https://example.com/webhook", method=responses.POST, body=b"") self.login_as(user=self.user) + rpc_user = user_service.get_user(user_id=self.user.id) response = self.client.delete(self.url, format="json") assert AuditLogEntry.objects.filter( event=audit_log.get_event_id("SENTRY_APP_UNINSTALL") @@ -115,6 +118,12 @@ def test_delete_install(self, record, request): sentry_app=self.orm_installation2.sentry_app.slug, ) + response_body = json.loads(responses.calls[0].request.body) + + assert response_body.get("installation").get("uuid") == self.orm_installation2.uuid + assert response_body.get("action") == "deleted" + assert response_body.get("actor")["id"] == rpc_user.id + assert response.status_code == 204 def test_member_cannot_delete_install(self): diff --git a/tests/sentry/sentry_apps/test_sentry_app_installation_creator.py b/tests/sentry/sentry_apps/test_sentry_app_installation_creator.py index 0c113ce2c58a46..414ac33fab96d9 100644 --- a/tests/sentry/sentry_apps/test_sentry_app_installation_creator.py +++ b/tests/sentry/sentry_apps/test_sentry_app_installation_creator.py @@ -87,14 +87,18 @@ def test_creates_audit_log_entry(self): ).exists() @responses.activate + # @patch("sentry.utils.sentry_apps.webhooks.send_and_save_webhook_request") def test_notifies_service(self): - responses.add(responses.POST, "https://example.com/webhook") rpc_user = user_service.get_user(user_id=self.user.id) with self.tasks(): - self.run_creator() - assert json.loads(responses.calls[0].request.body).get("action") == "created" - assert json.loads(responses.calls[0].request.body).get("actor")["id"] == rpc_user.id + responses.add(responses.POST, "https://example.com/webhook") + install = self.run_creator() + response_body = json.loads(responses.calls[0].request.body) + + assert response_body.get("installation").get("uuid") == install.uuid + assert response_body.get("action") == "created" + assert response_body.get("actor")["id"] == rpc_user.id @responses.activate def test_associations(self): diff --git a/tests/sentry/tasks/test_sentry_apps.py b/tests/sentry/tasks/test_sentry_apps.py index 362da543d5f91d..9e30c6dac46ef1 100644 --- a/tests/sentry/tasks/test_sentry_apps.py +++ b/tests/sentry/tasks/test_sentry_apps.py @@ -3,6 +3,7 @@ from unittest.mock import ANY, patch import pytest +import responses from celery import Task from django.core import mail from django.test import override_settings @@ -416,7 +417,6 @@ def test_sends_webhooks_to_all_installs(self, safe_urlopen): @control_silo_test -@patch("sentry.sentry_apps.installations.SentryAppInstallationNotifier.run") class TestInstallationWebhook(TestCase): def setUp(self): self.project = self.create_project() @@ -429,18 +429,29 @@ def setUp(self): organization=self.project.organization, slug=self.sentry_app.slug ) - def test_sends_installation_notification(self, run): + @responses.activate + def test_sends_installation_notification(self): + responses.add(responses.POST, "https://example.com/webhook") installation_webhook(self.install.id, self.user.id) - run.assert_called_with(install=self.install, user=self.rpc_user, action="created") + response_body = json.loads(responses.calls[0].request.body) + assert response_body.get("installation").get("uuid") == self.install.uuid + assert response_body.get("action") == "created" + assert response_body.get("actor")["id"] == self.rpc_user.id + + @responses.activate + def test_gracefully_handles_missing_install(self): + responses.add(responses.POST, "https://example.com/webhook") - def test_gracefully_handles_missing_install(self, run): installation_webhook(999, self.user.id) - assert len(run.mock_calls) == 0 + assert len(responses.calls) == 0 + + @responses.activate + def test_gracefully_handles_missing_user(self): + responses.add(responses.POST, "https://example.com/webhook") - def test_gracefully_handles_missing_user(self, run): installation_webhook(self.install.id, 999) - assert len(run.mock_calls) == 0 + assert len(responses.calls) == 0 @patch("sentry.utils.sentry_apps.webhooks.safe_urlopen", return_value=MockResponseInstance)