示例#1
0
    def test_saves_request_if_webhook_request_succeeds(self, safe_urlopen):
        data = {"issue": serialize(self.issue)}
        send_webhooks(installation=self.install, event="issue.assigned", data=data, actor=self.user)

        requests = self.buffer.get_requests()
        requests_count = len(requests)
        first_request = requests[0]

        assert safe_urlopen.called
        assert requests_count == 1
        assert first_request["response_code"] == 200
        assert first_request["event_type"] == "issue.assigned"
        assert first_request["organization_id"] == self.install.organization.id
示例#2
0
    def test_saves_error_if_workflow_webhook_request_fails(self, safe_urlopen):
        data = {"issue": serialize(self.issue)}
        send_webhooks(installation=self.install,
                      event="issue.assigned",
                      data=data,
                      actor=self.user)

        error_count = SentryAppWebhookError.objects.count()
        error = SentryAppWebhookError.objects.first()

        assert safe_urlopen.called
        assert error_count == 1
        assert error.sentry_app.id == self.install.sentry_app.id
        assert error.organization.id == self.install.organization.id
        assert error.response_body == "{}"
示例#3
0
    def test_saves_error_event_id_if_in_header(self, safe_urlopen):
        data = {"issue": serialize(self.issue)}
        send_webhooks(installation=self.install, event="issue.assigned", data=data, actor=self.user)

        requests = self.buffer.get_requests()
        requests_count = len(requests)
        first_request = requests[0]

        assert safe_urlopen.called
        assert requests_count == 1
        assert first_request["response_code"] == 400
        assert first_request["event_type"] == "issue.assigned"
        assert first_request["organization_id"] == self.install.organization.id
        assert first_request["error_id"] == "d5111da2c28645c5889d072017e3445d"
        assert first_request["project_id"] == "1"
示例#4
0
    def test_raises_ignorable_error_for_internal_apps(self, safe_urlopen):
        data = {"issue": serialize(self.issue)}
        self.sentry_app.update(status=SentryAppStatus.INTERNAL)
        with self.assertRaises(IgnorableSentryAppError):
            send_webhooks(
                installation=self.install, event="issue.assigned", data=data, actor=self.user
            )

        requests = self.buffer.get_requests()
        requests_count = len(requests)
        first_request = requests[0]

        assert safe_urlopen.called
        assert requests_count == 1
        assert first_request["response_code"] == 404
        assert first_request["event_type"] == "issue.assigned"
示例#5
0
    def test_saves_error_for_request_timeout(self, safe_urlopen):
        data = {"issue": serialize(self.issue)}

        with self.assertRaises(RequestException):
            send_webhooks(installation=self.install,
                          event="issue.assigned",
                          data=data,
                          actor=self.user)

        error_count = SentryAppWebhookError.objects.count()
        error = SentryAppWebhookError.objects.first()

        assert safe_urlopen.called
        assert error_count == 1
        assert error.sentry_app.id == self.install.sentry_app.id
        assert error.organization.id == self.install.organization.id
        assert error.response_body == "RequestException('Timeout',)"
示例#6
0
    def test_saves_error_for_request_timeout(self, safe_urlopen):
        data = {"issue": serialize(self.issue)}
        # we don't log errors for unpublished and internal apps
        with self.assertRaises(Timeout):
            send_webhooks(
                installation=self.install, event="issue.assigned", data=data, actor=self.user
            )

        requests = self.buffer.get_requests()
        requests_count = len(requests)
        first_request = requests[0]

        assert safe_urlopen.called
        assert requests_count == 1
        assert first_request["response_code"] == 0
        assert first_request["event_type"] == "issue.assigned"
        assert first_request["organization_id"] == self.install.organization.id
示例#7
0
    def test_saves_error_if_workflow_webhook_request_fails(self, safe_urlopen):
        sentry_app = self.create_sentry_app(
            name="Test App",
            organization=self.project.organization,
            events=["issue.resolved", "issue.ignored", "issue.assigned"],
        )
        install = self.create_sentry_app_installation(
            organization=self.project.organization, slug=sentry_app.slug)
        data = {"issue": serialize(self.issue)}
        send_webhooks(installation=install,
                      event="issue.assigned",
                      data=data,
                      actor=self.user)

        error_count = SentryAppWebhookError.objects.count()
        error = SentryAppWebhookError.objects.first()

        assert safe_urlopen.called
        assert error_count == 1
        assert error.sentry_app.id == install.sentry_app.id
        assert error.organization.id == install.organization.id
示例#8
0
    def test_does_not_save_error_if_nonworkflow_request_fails(
            self, safe_urlopen):
        sentry_app = self.create_sentry_app(
            name="Test App 2",
            organization=self.project.organization,
            events=[
                "issue.resolved",
                "issue.ignored",
                "issue.assigned",
                "issue.created",
                "error.created",
            ],
        )
        install = self.create_sentry_app_installation(
            organization=self.project.organization, slug=sentry_app.slug)
        data = {"issue": serialize(self.issue)}
        send_webhooks(installation=install, event="issue.created", data=data)
        send_webhooks(installation=install, event="error.created", data=data)

        error_count = SentryAppWebhookError.objects.count()

        assert safe_urlopen.called
        assert error_count == 0