class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), ) self.creator = Creator(organization=self.org, slug='nulldb') def test_creates_api_authorization(self): install, grant = self.creator.call() assert ApiAuthorization.objects.get( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ) def test_creates_installation(self): install, grant = self.creator.call() assert install.pk def test_creates_api_grant(self): install, grant = self.creator.call() assert grant.pk def test_associations(self): install, grant = self.creator.call() assert install.api_grant == grant assert install.authorization is not None
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, ) def test_creates_api_authorization(self): install, grant = self.creator.call() assert ApiAuthorization.objects.get( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ) def test_creates_installation(self): install, grant = self.creator.call() assert install.pk def test_creates_api_grant(self): install, grant = self.creator.call() assert grant.pk @patch('sentry.tasks.app_platform.installation_webhook.delay') def test_notifies_service(self, installation_webhook): install, _ = self.creator.call() installation_webhook.assert_called_once_with(install.id, self.user.id) def test_associations(self): install, grant = self.creator.call() assert install.api_grant == grant assert install.authorization is not None
def test_installed_status(self): responses.add(responses.POST, "https://example.com/webhook") internal_app = self.create_internal_integration(name="internal", organization=self.org) creator = Creator(organization=self.org, slug=internal_app.slug, user=self.user) install = creator.call() assert install.status == SentryAppInstallationStatus.INSTALLED
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = SentryAppCreator.run( name='nulldb', user=self.user, scopes=('project:read',), webhook_url='http://example.com', ) self.creator = Creator(organization=self.org, slug='nulldb') def test_creates_api_authorization(self): install, grant = self.creator.call() assert ApiAuthorization.objects.get( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ) def test_creates_installation(self): install, grant = self.creator.call() assert install.pk def test_creates_api_grant(self): install, grant = self.creator.call() assert grant.pk def test_associations(self): install, grant = self.creator.call() assert install.api_grant == grant assert install.authorization is not None
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, ) def test_creates_api_authorization(self): self.creator.call() assert ApiAuthorization.objects.filter( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ).exists() def test_creates_installation(self): install = self.creator.call() assert install.pk def test_creates_api_grant(self): install = self.creator.call() assert ApiGrant.objects.filter(id=install.api_grant_id).exists() def test_creates_service_hook(self): install = self.creator.call() hook = ServiceHook.objects.get(organization_id=self.org.id) assert hook.application_id == self.sentry_app.application.id assert hook.actor_id == install.id assert hook.organization_id == self.org.id assert hook.events == self.sentry_app.events assert hook.url == self.sentry_app.webhook_url assert not ServiceHookProject.objects.all() @patch('sentry.tasks.sentry_apps.installation_webhook.delay') def test_notifies_service(self, installation_webhook): install = self.creator.call() installation_webhook.assert_called_once_with(install.id, self.user.id) def test_associations(self): install = self.creator.call() assert install.api_grant is not None assert install.authorization is not None
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) responses.add(responses.POST, 'https://example.com/webhook') self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, ) @responses.activate def test_creates_installation(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert install.pk @responses.activate def test_creates_api_grant(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert ApiGrant.objects.filter(id=install.api_grant_id).exists() @responses.activate def test_creates_service_hooks(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() hook = ServiceHook.objects.get(organization_id=self.org.id) assert hook.application_id == self.sentry_app.application.id assert hook.actor_id == install.id assert hook.organization_id == self.org.id assert hook.events == self.sentry_app.events assert hook.url == self.sentry_app.webhook_url assert not ServiceHookProject.objects.all() @responses.activate def test_creates_audit_log_entry(self): responses.add(responses.POST, 'https://example.com/webhook') request = self.make_request(user=self.user, method='GET') Creator.run( organization=self.org, slug='nulldb', user=self.user, request=request, ) assert AuditLogEntry.objects.filter( event=AuditLogEntryEvent.SENTRY_APP_INSTALL).exists() @responses.activate @patch('sentry.mediators.sentry_app_installations.InstallationNotifier.run' ) def test_notifies_service(self, run): with self.tasks(): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() run.assert_called_once_with(install=install, user=self.user, action='created') @responses.activate def test_associations(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert install.api_grant is not None @patch('sentry.analytics.record') def test_records_analytics(self, record): Creator.run( organization=self.org, slug='nulldb', user=self.user, request=self.make_request(user=self.user, method='GET'), ) record.assert_called_with( 'sentry_app.installed', user_id=self.user.id, organization_id=self.org.id, sentry_app='nulldb', )
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) responses.add(responses.POST, 'https://example.com/webhook') self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, ) @responses.activate def test_creates_api_authorization(self): responses.add(responses.POST, 'https://example.com/webhook') self.creator.call() assert ApiAuthorization.objects.filter( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ).exists() @responses.activate def test_creates_installation(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert install.pk @responses.activate def test_creates_api_grant(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert ApiGrant.objects.filter(id=install.api_grant_id).exists() @responses.activate def test_creates_service_hooks(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() hook = ServiceHook.objects.get(organization_id=self.org.id) assert hook.application_id == self.sentry_app.application.id assert hook.actor_id == install.id assert hook.organization_id == self.org.id assert hook.events == self.sentry_app.events assert hook.url == self.sentry_app.webhook_url assert not ServiceHookProject.objects.all() @responses.activate @patch('sentry.mediators.sentry_app_installations.InstallationNotifier.run' ) def test_notifies_service(self, run): with self.tasks(): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() run.assert_called_once_with(install=install, user=self.user, action='created') @responses.activate def test_associations(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert install.api_grant is not None assert install.authorization is not None
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) responses.add(responses.POST, "https://example.com/webhook") self.sentry_app = self.create_sentry_app( name="nulldb", organization=self.org, scopes=("project:read", ), events=("issue.created", ), ) self.creator = Creator(organization=self.org, slug="nulldb", user=self.user) @responses.activate def test_creates_installation(self): responses.add(responses.POST, "https://example.com/webhook") install = self.creator.call() assert install.pk @responses.activate def test_creates_api_grant(self): responses.add(responses.POST, "https://example.com/webhook") install = self.creator.call() assert ApiGrant.objects.filter(id=install.api_grant_id).exists() @responses.activate def test_creates_service_hooks(self): responses.add(responses.POST, "https://example.com/webhook") install = self.creator.call() hook = ServiceHook.objects.get(organization_id=self.org.id) assert hook.application_id == self.sentry_app.application.id assert hook.actor_id == install.id assert hook.organization_id == self.org.id assert hook.events == self.sentry_app.events assert hook.url == self.sentry_app.webhook_url assert not ServiceHookProject.objects.all() @responses.activate def test_creates_audit_log_entry(self): responses.add(responses.POST, "https://example.com/webhook") request = self.make_request(user=self.user, method="GET") Creator.run(organization=self.org, slug="nulldb", user=self.user, request=request) assert AuditLogEntry.objects.filter( event=AuditLogEntryEvent.SENTRY_APP_INSTALL).exists() @responses.activate @patch("sentry.mediators.sentry_app_installations.InstallationNotifier.run" ) def test_notifies_service(self, run): with self.tasks(): responses.add(responses.POST, "https://example.com/webhook") install = self.creator.call() run.assert_called_once_with(install=install, user=self.user, action="created") @responses.activate def test_associations(self): responses.add(responses.POST, "https://example.com/webhook") install = self.creator.call() assert install.api_grant is not None @responses.activate def test_pending_status(self): responses.add(responses.POST, "https://example.com/webhook") install = self.creator.call() assert install.status == SentryAppInstallationStatus.PENDING @responses.activate def test_installed_status(self): responses.add(responses.POST, "https://example.com/webhook") internal_app = self.create_internal_integration(name="internal", organization=self.org) creator = Creator(organization=self.org, slug=internal_app.slug, user=self.user) install = creator.call() assert install.status == SentryAppInstallationStatus.INSTALLED @patch("sentry.analytics.record") def test_records_analytics(self, record): Creator.run( organization=self.org, slug="nulldb", user=self.user, request=self.make_request(user=self.user, method="GET"), ) record.assert_called_with( "sentry_app.installed", user_id=self.user.id, organization_id=self.org.id, sentry_app="nulldb", )
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read',), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, ) def test_creates_api_authorization(self): self.creator.call() assert ApiAuthorization.objects.filter( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ).exists() def test_creates_installation(self): install = self.creator.call() assert install.pk def test_creates_api_grant(self): install = self.creator.call() assert ApiGrant.objects.filter(id=install.api_grant_id).exists() def test_creates_service_hooks(self): install = self.creator.call() hook = ServiceHook.objects.get(project_id=self.project1.id) assert hook.application_id == self.sentry_app.application.id assert hook.actor_id == install.id assert hook.project_id == self.project1.id assert hook.events == self.sentry_app.events assert hook.url == self.sentry_app.webhook_url def test_creates_service_hooks_for_all_projects(self): self.creator.call() assert ServiceHook.objects.get(project_id=self.project1.id).events == self.sentry_app.events assert ServiceHook.objects.get(project_id=self.project2.id).events == self.sentry_app.events @patch('sentry.tasks.app_platform.installation_webhook.delay') def test_notifies_service(self, installation_webhook): install = self.creator.call() installation_webhook.assert_called_once_with(install.id, self.user.id) def test_associations(self): install = self.creator.call() assert install.api_grant is not None assert install.authorization is not None
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) responses.add(responses.POST, 'https://example.com/webhook') self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read',), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, ) @responses.activate def test_creates_installation(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert install.pk @responses.activate def test_creates_api_grant(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert ApiGrant.objects.filter(id=install.api_grant_id).exists() @responses.activate def test_creates_service_hooks(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() hook = ServiceHook.objects.get(organization_id=self.org.id) assert hook.application_id == self.sentry_app.application.id assert hook.actor_id == install.id assert hook.organization_id == self.org.id assert hook.events == self.sentry_app.events assert hook.url == self.sentry_app.webhook_url assert not ServiceHookProject.objects.all() @responses.activate def test_creates_audit_log_entry(self): responses.add(responses.POST, 'https://example.com/webhook') request = self.make_request(user=self.user, method='GET') Creator.run( organization=self.org, slug='nulldb', user=self.user, request=request, ) assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_INSTALL).exists() @responses.activate @patch('sentry.mediators.sentry_app_installations.InstallationNotifier.run') def test_notifies_service(self, run): with self.tasks(): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() run.assert_called_once_with(install=install, user=self.user, action='created') @responses.activate def test_associations(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert install.api_grant is not None @patch('sentry.analytics.record') def test_records_analytics(self, record): Creator.run( organization=self.org, slug='nulldb', user=self.user, request=self.make_request(user=self.user, method='GET'), ) record.assert_called_with( 'sentry_app.installed', user_id=self.user.id, organization_id=self.org.id, sentry_app='nulldb', )