Example #1
0
 def test_updates_service_hook_events(self):
     sentry_app = self.create_sentry_app(
         name='sentry',
         organization=self.org,
         scopes=('project:read', 'event:read',),
         events=('event.alert',),
     )
     self.create_sentry_app_installation(slug='sentry')
     updater = Updater(sentry_app=sentry_app, events=('issue',), user=self.user)
     updater.call()
     assert set(sentry_app.events) == expand_events(['issue'])
     service_hook = ServiceHook.objects.filter(application=sentry_app.application)[0]
     assert set(service_hook.events) == expand_events(['issue'])
Example #2
0
 def test_updates_service_hook_events(self):
     sentry_app = self.create_sentry_app(
         name='sentry',
         organization=self.org,
         scopes=('project:read', 'event:read',),
         events=('event.alert',),
     )
     self.create_sentry_app_installation(slug='sentry')
     updater = Updater(sentry_app=sentry_app, events=('issue',), user=self.user)
     updater.call()
     assert set(sentry_app.events) == expand_events(['issue'])
     service_hook = ServiceHook.objects.filter(application=sentry_app.application)[0]
     assert set(service_hook.events) == expand_events(['issue'])
Example #3
0
 def test_updates_service_hook_events(self):
     sentry_app = self.create_sentry_app(
         name="sentry",
         organization=self.org,
         scopes=("project:read", "event:read"),
         events=("event.alert",),
     )
     self.create_sentry_app_installation(slug="sentry")
     updater = Updater(sentry_app=sentry_app, events=("issue",), user=self.user)
     updater.call()
     assert set(sentry_app.events) == expand_events(["issue"])
     service_hook = ServiceHook.objects.filter(application=sentry_app.application)[0]
     assert set(service_hook.events) == expand_events(["issue"])
Example #4
0
 def test_expand_events(self):
     assert expand_events(['issue']) == set([
         'issue.created',
         'issue.resolved',
         'issue.ignored',
         'issue.assigned',
     ])
 def test_expand_events(self):
     assert expand_events(['issue']) == set([
         'issue.created',
         'issue.resolved',
         'issue.ignored',
         'issue.assigned',
     ])
Example #6
0
 def test_expand_events(self):
     assert expand_events(["issue"]) == {
         "issue.created",
         "issue.resolved",
         "issue.ignored",
         "issue.assigned",
     }
Example #7
0
    def _create_sentry_app(self):
        from sentry.mediators.service_hooks.creator import expand_events

        kwargs = {
            "name": self.name,
            "slug": self.slug,
            "author": self.author,
            "application_id": self.api_app.id,
            "owner_id": self.organization.id,
            "proxy_user_id": self.proxy.id,
            "scope_list": self.scopes,
            "events": expand_events(self.events),
            "schema": self.schema or {},
            "webhook_url": self.webhook_url,
            "redirect_url": self.redirect_url,
            "is_alertable": self.is_alertable,
            "verify_install": self.verify_install,
            "overview": self.overview,
            "popularity": self.popularity or SentryApp._meta.get_field("popularity").default,
            "creator_user": self.user,
            "creator_label": self.user.email
            or self.user.username,  # email is not required for some users (sentry apps)
        }

        if self.is_internal:
            kwargs["status"] = SentryAppStatus.INTERNAL

        return SentryApp.objects.create(**kwargs)
Example #8
0
    def _update_events(self):
        for event in self.events:
            needed_scope = REQUIRED_EVENT_PERMISSIONS[event]
            if needed_scope not in self.sentry_app.scope_list:
                raise APIError(f"{event} webhooks require the {needed_scope} permission.")

        from sentry.mediators.service_hooks.creator import expand_events

        self.sentry_app.events = expand_events(self.events)
Example #9
0
    def _update_events(self):
        for event in self.events:
            needed_scope = REQUIRED_EVENT_PERMISSIONS[event]
            if needed_scope not in self.sentry_app.scope_list:
                raise APIError(
                    u'{} webhooks require the {} permission.'.format(event, needed_scope),
                )

        from sentry.mediators.service_hooks.creator import expand_events
        self.sentry_app.events = expand_events(self.events)
        self._update_service_hook_events()
Example #10
0
 def test_create_service_hook_on_update(self):
     self.create_project(organization=self.org)
     internal_app = self.create_internal_integration(
         name="Internal", organization=self.org, webhook_url=None, scopes=("event:read",)
     )
     assert len(ServiceHook.objects.filter(application=internal_app.application)) == 0
     updater = Updater(sentry_app=internal_app, user=self.user)
     updater.webhook_url = "https://sentry.io/hook"
     updater.events = ("issue",)
     updater.call()
     service_hook = ServiceHook.objects.get(application=internal_app.application)
     assert service_hook.url == "https://sentry.io/hook"
     assert set(service_hook.events) == expand_events(["issue"])
Example #11
0
    def _create_sentry_app(self):
        from sentry.mediators.service_hooks.creator import expand_events

        return SentryApp.objects.create(
            name=self.name,
            application_id=self.api_app.id,
            owner_id=self.organization.id,
            proxy_user_id=self.proxy.id,
            scope_list=self.scopes,
            events=expand_events(self.events),
            webhook_url=self.webhook_url,
            redirect_url=self.redirect_url,
            is_alertable=self.is_alertable,
            overview=self.overview,
        )
Example #12
0
    def _create_sentry_app(self):
        from sentry.mediators.service_hooks.creator import expand_events

        return SentryApp.objects.create(
            name=self.name,
            application_id=self.api_app.id,
            owner_id=self.organization.id,
            proxy_user_id=self.proxy.id,
            scope_list=self.scopes,
            events=expand_events(self.events),
            webhook_url=self.webhook_url,
            redirect_url=self.redirect_url,
            is_alertable=self.is_alertable,
            overview=self.overview,
        )
Example #13
0
 def test_updates_webhook_url(self):
     sentry_app = self.create_sentry_app(
         name="sentry",
         organization=self.org,
         scopes=("project:read", "event:read"),
         events=("event.alert",),
     )
     self.create_sentry_app_installation(slug="sentry")
     updater = Updater(
         sentry_app=sentry_app, webhook_url="http://example.com/hooks", user=self.user
     )
     updater.call()
     assert sentry_app.webhook_url == "http://example.com/hooks"
     service_hook = ServiceHook.objects.get(application=sentry_app.application)
     assert service_hook.url == "http://example.com/hooks"
     assert set(service_hook.events) == expand_events(["event.alert"])
Example #14
0
    def _create_sentry_app(self):
        from sentry.mediators.service_hooks.creator import expand_events

        kwargs = {
            "name": self.name,
            "slug": self.slug,
            "author": self.author,
            "application_id": self.api_app.id,
            "owner_id": self.organization.id,
            "proxy_user_id": self.proxy.id,
            "scope_list": self.scopes,
            "events": expand_events(self.events),
            "schema": self.schema or {},
            "webhook_url": self.webhook_url,
            "redirect_url": self.redirect_url,
            "is_alertable": self.is_alertable,
            "verify_install": self.verify_install,
            "overview": self.overview,
        }

        if self.is_internal:
            kwargs["status"] = SentryAppStatus.INTERNAL

        return SentryApp.objects.create(**kwargs)
Example #15
0
 def _update_events(self):
     self.service_hook.events = expand_events(self.events)
Example #16
0
 def _update_events(self):
     from sentry.mediators.service_hooks.creator import expand_events
     self.sentry_app.events = expand_events(self.events)
Example #17
0
 def _update_events(self):
     self.service_hook.events = expand_events(self.events)
Example #18
0
 def test_expand_events(self):
     assert expand_events(['issue']) == set(['issue.created'])
Example #19
0
 def test_expand_events(self):
     assert expand_events(['issue']) == set(['issue.created'])