def setUp(self):
     self.superuser = self.create_user(email='*****@*****.**', is_superuser=True)
     self.user = self.create_user(email='*****@*****.**')
     self.org = self.create_organization(owner=self.user)
     self.super_org = self.create_organization(owner=self.superuser)
     self.published_app = SentryAppCreator.run(
         name='Test',
         organization=self.super_org,
         scopes=(),
         webhook_url='https://example.com',
     )
     self.published_app.update(status=SentryAppStatus.PUBLISHED)
     self.installation, _ = Creator.run(
         slug=self.published_app.slug,
         organization=self.super_org,
     )
     self.unpublished_app = SentryAppCreator.run(
         name='Testin',
         organization=self.org,
         scopes=(),
         webhook_url='https://example.com',
     )
     self.installation2, _ = Creator.run(
         slug=self.unpublished_app.slug,
         organization=self.org,
     )
     self.url = reverse(
         'sentry-api-0-organization-sentry-app-installations-details',
         args=[
             self.org.slug,
             self.installation2.uuid,
         ])
コード例 #2
0
ファイル: test_creator.py プロジェクト: yaoqi/sentry
 def test_creates_audit_log_entry(self):
     request = self.make_request(user=self.user, method='GET')
     Creator.run(
         name='nulldb',
         user=self.user,
         author='Sentry',
         organization=self.org,
         scopes=('project:read',),
         webhook_url='http://example.com',
         schema={'elements': [self.create_issue_link_schema()]},
         request=request,
     )
     assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_ADD).exists()
コード例 #3
0
ファイル: test_access.py プロジェクト: alexandrul/sentry
    def setUp(self):
        super(FromSentryAppTest, self).setUp()

        # Partner's normal Sentry account.
        self.user = self.create_user('*****@*****.**')

        self.org = self.create_organization()
        self.out_of_scope_org = self.create_organization()

        self.team = self.create_team(organization=self.org)
        self.out_of_scope_team = self.create_team(
            organization=self.out_of_scope_org
        )

        self.sentry_app = SentryAppCreator.run(
            name='SlowDB',
            organization=self.org,
            scopes=(),
            webhook_url='http://example.com',
        )

        self.proxy_user = self.sentry_app.proxy_user

        self.install = SentryAppInstallationCreator.run(
            organization=self.org,
            slug=self.sentry_app.slug,
        )
コード例 #4
0
ファイル: sentry_apps.py プロジェクト: getsentry/sentry
    def post(self, request, organization):
        data = {
            'name': request.json_body.get('name'),
            'user': request.user,
            'author': request.json_body.get('author'),
            'organization': self._get_user_org(request),
            'webhookUrl': request.json_body.get('webhookUrl'),
            'redirectUrl': request.json_body.get('redirectUrl'),
            'isAlertable': request.json_body.get('isAlertable'),
            'scopes': request.json_body.get('scopes', []),
            'events': request.json_body.get('events', []),
            'schema': request.json_body.get('schema', {}),
            'overview': request.json_body.get('overview'),
        }

        serializer = SentryAppSerializer(data=data)

        if serializer.is_valid():
            data['redirect_url'] = data['redirectUrl']
            data['webhook_url'] = data['webhookUrl']
            data['is_alertable'] = data['isAlertable']

            sentry_app = Creator.run(
                request=request,
                **data
            )

            return Response(serialize(sentry_app), status=201)
        return Response(serializer.errors, status=400)
コード例 #5
0
ファイル: test_creator.py プロジェクト: Kayle009/sentry
 def setUp(self):
     self.user = self.create_user()
     self.org = self.create_organization(owner=self.user)
     self.creator = Creator(name='nulldb',
                            organization=self.org,
                            scopes=('project:read',),
                            webhook_url='http://example.com')
コード例 #6
0
ファイル: test_updater.py プロジェクト: mjumbewu/sentry
    def setUp(self):
        self.user = self.create_user()
        self.sentry_app = Creator.run(
            name='nulldb',
            user=self.user,
            scopes=('project:read',),
            webhook_url='http://example.com',
        )

        self.updater = Updater(sentry_app=self.sentry_app)
コード例 #7
0
ファイル: test_updater.py プロジェクト: yangzaiCN/sentry
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization(owner=self.user)
        self.sentry_app = Creator.run(
            name='nulldb',
            organization=self.org,
            scopes=('project:read', ),
            webhook_url='http://example.com',
        )

        self.updater = Updater(sentry_app=self.sentry_app)
コード例 #8
0
ファイル: test_creator.py プロジェクト: yaoqi/sentry
 def setUp(self):
     self.user = self.create_user()
     self.org = self.create_organization(owner=self.user)
     self.creator = Creator(
         name='nulldb',
         user=self.user,
         author='Sentry',
         organization=self.org,
         scopes=('project:read',),
         webhook_url='http://example.com',
         schema={'elements': [self.create_issue_link_schema()]},
     )
コード例 #9
0
ファイル: test_creator.py プロジェクト: zuolei828/sentry
    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')
コード例 #10
0
ファイル: test_creator.py プロジェクト: mjumbewu/sentry
    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')
コード例 #11
0
 def setUp(self):
     self.superuser = self.create_user(email='*****@*****.**',
                                       is_superuser=True)
     self.user = self.create_user(email='*****@*****.**')
     self.org = self.create_organization(owner=self.user)
     self.super_org = self.create_organization(owner=self.superuser)
     self.published_app = Creator.run(
         name='Test',
         organization=self.org,
         scopes=(),
         webhook_url='https://example.com',
     )
     self.published_app.update(status=SentryAppStatus.PUBLISHED)
     self.unpublished_app = Creator.run(
         name='Testin',
         organization=self.org,
         scopes=(),
         webhook_url='https://example.com',
     )
     self.url = reverse('sentry-api-0-sentry-app-details',
                        args=[self.published_app.slug])
コード例 #12
0
    def setUp(self):
        self.permission = SentryAppDetailsPermission()
        self.user = self.create_user()
        self.sentry_app = SentryAppCreator.run(
            name='foo',
            user=self.user,
            scopes=(),
            webhook_url='https://example.com',
        )

        self.request = HttpRequest()
        self.request.user = self.user
コード例 #13
0
ファイル: test_destroyer.py プロジェクト: yangzaiCN/sentry
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization()

        self.sentry_app = Creator.run(
            name='blah',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='https://example.com',
        )

        self.destroyer = Destroyer(sentry_app=self.sentry_app)
コード例 #14
0
    def test_doesnt_update_published_app_scopes(self):
        sentry_app = Creator.run(
            name='sentry',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='http://example.com',
        )
        sentry_app.update(status=SentryAppStatus.PUBLISHED)
        updater = Updater(sentry_app=sentry_app)
        updater.scopes = ('project:read', 'project:write', )

        with self.assertRaises(APIError):
            updater.call()
コード例 #15
0
    def setUp(self):
        super(TestClientIdSecretAuthentication, self).setUp()

        self.auth = ClientIdSecretAuthentication()

        self.sentry_app = Creator.run(
            name="foo",
            user=self.user,
            scopes=(),
            webhook_url='https://example.com',
        )

        self.api_app = self.sentry_app.application
コード例 #16
0
    def post(self, request):
        serializer = SentryAppSerializer(data=request.json_body)

        if not serializer.is_valid():
            return Response({'errors': serializer.errors}, status=422)

        sentry_app = Creator.run(
            name=request.json_body.get('name'),
            organization=self._get_user_org(request),
            scopes=request.json_body.get('scopes'),
            webhook_url=request.json_body.get('webhook_url'),
        )

        return Response(serialize(sentry_app), status=201)
コード例 #17
0
ファイル: sentry_apps.py プロジェクト: alexandrul/sentry
    def post(self, request):
        serializer = SentryAppSerializer(data=request.json_body)

        if not serializer.is_valid():
            return Response({'errors': serializer.errors}, status=422)

        sentry_app = Creator.run(
            name=request.json_body.get('name'),
            organization=self._get_user_org(request),
            scopes=request.json_body.get('scopes'),
            webhook_url=request.json_body.get('webhook_url'),
        )

        return Response(serialize(sentry_app), status=201)
コード例 #18
0
ファイル: test_sentry_apps.py プロジェクト: alexandrul/sentry
    def setUp(self):
        self.superuser = self.create_user(email='*****@*****.**', is_superuser=True)
        self.super_org = self.create_organization(owner=self.superuser)

        self.user = self.create_user(email='*****@*****.**')
        self.org = self.create_organization(owner=self.user)

        self.published_app = Creator.run(
            name='Test',
            organization=self.org,
            scopes=(),
            webhook_url='https://example.com',
        )
        self.published_app.update(status=SentryAppStatus.PUBLISHED)

        self.unpublished_app = Creator.run(
            name='Testin',
            organization=self.org,
            scopes=(),
            webhook_url='https://example.com',
        )

        self.url = reverse('sentry-api-0-sentry-apps')
コード例 #19
0
    def setUp(self):
        self.endpoint = SentryAppDetailsEndpoint()

        self.user = self.create_user()
        self.request = HttpRequest()
        self.request.user = self.user
        self.request.successful_authenticator = True

        self.sentry_app = SentryAppCreator.run(
            name='foo',
            user=self.user,
            scopes=(),
            webhook_url='https://example.com',
        )
コード例 #20
0
ファイル: test_destroyer.py プロジェクト: mjumbewu/sentry
    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='https://example.com',
        )

        self.install, self.grant = Creator.run(
            organization=self.org,
            slug='nulldb',
        )

        self.destroyer = Destroyer(install=self.install)
コード例 #21
0
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization()

        self.sentry_app = SentryAppCreator.run(
            name='nulldb',
            organization=self.org,
            scopes=('project:read', ),
            webhook_url='https://example.com',
        )

        self.install, self.grant = Creator.run(
            organization=self.org,
            slug='nulldb',
        )

        self.destroyer = Destroyer(install=self.install)
コード例 #22
0
    def test_records_analytics(self, record):
        sentry_app = Creator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read', ),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=self.make_request(user=self.user, method='GET'))

        record.assert_called_with(
            'sentry_app.created',
            user_id=self.user.id,
            organization_id=self.org.id,
            sentry_app=sentry_app.slug,
        )
コード例 #23
0
 def test_cannot_update_non_owned_apps(self):
     self.login_as(user=self.user)
     app = Creator.run(
         name='SampleApp',
         organization=self.super_org,
         scopes=(),
         webhook_url='https://sample.com',
     )
     url = reverse('sentry-api-0-sentry-app-details', args=[app.slug])
     response = self.client.put(
         url,
         data={
             'name': 'NewName',
             'webhook_url': 'https://newurl.com',
         },
         format='json',
     )
     assert response.status_code == 403
コード例 #24
0
ファイル: test_creator.py プロジェクト: yaoqi/sentry
    def test_records_analytics(self, record):
        sentry_app = Creator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=self.make_request(user=self.user, method='GET')
        )

        record.assert_called_with(
            'sentry_app.created',
            user_id=self.user.id,
            organization_id=self.org.id,
            sentry_app=sentry_app.slug,
        )
コード例 #25
0
    def test_records_analytics(self, record):
        sentry_app = Creator.run(
            name="nulldb",
            user=self.user,
            author="Sentry",
            organization=self.org,
            scopes=("project:read",),
            webhook_url="http://example.com",
            schema={"elements": [self.create_issue_link_schema()]},
            request=self.make_request(user=self.user, method="GET"),
        )

        record.assert_called_with(
            "sentry_app.created",
            user_id=self.user.id,
            organization_id=self.org.id,
            sentry_app=sentry_app.slug,
        )
コード例 #26
0
ファイル: test_creator.py プロジェクト: commonlims/commonlims
class TestCreator(TestCase):
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization(owner=self.user)
        self.creator = Creator(name='nulldb',
                               organization=self.org,
                               scopes=('project:read', ),
                               webhook_url='http://example.com')

    def test_creates_proxy_user(self):
        self.creator.call()

        assert User.objects.get(
            username='******',
            is_sentry_app=True,
        )

    def test_creates_api_application(self):
        self.creator.call()
        proxy = User.objects.get(username='******')

        assert ApiApplication.objects.get(owner=proxy)

    def test_creates_sentry_app(self):
        self.creator.call()

        proxy = User.objects.get(username='******')
        app = ApiApplication.objects.get(owner=proxy)

        sentry_app = SentryApp.objects.get(
            name='nulldb',
            application=app,
            owner=self.org,
            proxy_user=proxy,
        )

        assert sentry_app
        assert sentry_app.scope_list == ['project:read']

    def test_expands_rolled_up_events(self):
        self.creator.events = ['issue']
        app = self.creator.call()

        sentry_app = SentryApp.objects.get(id=app.id)

        assert 'issue.created' in sentry_app.events
コード例 #27
0
ファイル: test_creator.py プロジェクト: Kayle009/sentry
class TestCreator(TestCase):
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization(owner=self.user)
        self.creator = Creator(name='nulldb',
                               organization=self.org,
                               scopes=('project:read',),
                               webhook_url='http://example.com')

    def test_creates_proxy_user(self):
        self.creator.call()

        assert User.objects.get(
            username='******',
            is_sentry_app=True,
        )

    def test_creates_api_application(self):
        self.creator.call()
        proxy = User.objects.get(username='******')

        assert ApiApplication.objects.get(owner=proxy)

    def test_creates_sentry_app(self):
        self.creator.call()

        proxy = User.objects.get(username='******')
        app = ApiApplication.objects.get(owner=proxy)

        sentry_app = SentryApp.objects.get(
            name='nulldb',
            application=app,
            owner=self.org,
            proxy_user=proxy,
        )

        assert sentry_app
        assert sentry_app.scope_list == ['project:read']

    def test_expands_rolled_up_events(self):
        self.creator.events = ['issue']
        app = self.creator.call()

        sentry_app = SentryApp.objects.get(id=app.id)

        assert 'issue.created' in sentry_app.events
コード例 #28
0
    def test_install_unpublished_app(self):
        self.login_as(user=self.user)
        app = SentryAppCreator.run(
            name='Sample',
            organization=self.org,
            scopes=(),
            webhook_url='https://example.com',
        )
        response = self.client.post(
            self.url,
            data={'slug': app.slug},
            format='json',
        )
        expected = {
            'app': app.slug,
            'organization': self.org.slug,
        }

        assert response.status_code == 200, response.content
        assert six.viewitems(expected) <= six.viewitems(response.data)
コード例 #29
0
ファイル: sentry_apps.py プロジェクト: Kayle009/sentry
    def post(self, request, organization):
        serializer = SentryAppSerializer(data=request.json_body)

        if serializer.is_valid():
            result = serializer.object

            sentry_app = Creator.run(
                name=result.get('name'),
                organization=self._get_user_org(request),
                scopes=result.get('scopes'),
                events=result.get('events'),
                webhook_url=result.get('webhookUrl'),
                redirect_url=result.get('redirectUrl'),
                is_alertable=result.get('isAlertable'),
                overview=result.get('overview'),
            )

            return Response(serialize(sentry_app), status=201)

        return Response({'errors': serializer.errors}, status=422)
コード例 #30
0
    def create_sentry_app(self, name=None, organization=None, published=False, scopes=(),
                          webhook_url=None, **kwargs):
        if not name:
            name = 'Test App'
        if not organization:
            organization = self.create_organization()
        if not webhook_url:
            webhook_url = 'https://example.com/webhook'

        app = SentryAppCreator.run(
            name=name,
            organization=organization,
            scopes=scopes,
            webhook_url=webhook_url,
            **kwargs
        )
        if published:
            app.update(status=SentryAppStatus.PUBLISHED)

        return app
コード例 #31
0
    def post(self, request, organization):
        serializer = SentryAppSerializer(data=request.json_body)

        if serializer.is_valid():
            result = serializer.object

            sentry_app = Creator.run(
                name=result.get('name'),
                organization=self._get_user_org(request),
                scopes=result.get('scopes'),
                events=result.get('events'),
                webhook_url=result.get('webhookUrl'),
                redirect_url=result.get('redirectUrl'),
                is_alertable=result.get('isAlertable'),
                overview=result.get('overview'),
            )

            return Response(serialize(sentry_app), status=201)

        return Response(serializer.errors, status=422)
コード例 #32
0
    def test_install_unpublished_app(self):
        self.login_as(user=self.user)
        app = SentryAppCreator.run(
            name='Sample',
            organization=self.org,
            scopes=(),
            webhook_url='https://example.com',
        )
        response = self.client.post(
            self.url,
            data={'slug': app.slug},
            format='json',
        )
        expected = {
            'app': app.slug,
            'organization': self.org.slug,
        }

        assert response.status_code == 200, response.content
        assert six.viewitems(expected) <= six.viewitems(response.data)
コード例 #33
0
 def test_members_cannot_install_apps(self):
     user = self.create_user('*****@*****.**')
     self.create_member(
         organization=self.org,
         user=user,
         role='member',
     )
     self.login_as(user)
     app = SentryAppCreator.run(
         name='Sample',
         organization=self.org,
         scopes=(),
         webhook_url='https://example.com',
     )
     app.update(status=SentryAppStatus.PUBLISHED)
     response = self.client.post(
         self.url,
         data={'slug': app.slug},
         format='json',
     )
     assert response.status_code == 403
コード例 #34
0
    def setUp(self):
        self.endpoint = SentryAppInstallationDetailsEndpoint()

        self.user = self.create_user()
        self.org = self.create_organization(owner=self.user)

        self.request = HttpRequest()
        self.request.user = self.user
        self.request.successful_authenticator = True

        self.sentry_app = SentryAppCreator.run(
            name='foo',
            user=self.user,
            scopes=(),
            webhook_url='https://example.com',
        )

        self.installation, _ = SentryAppInstallationCreator.run(
            slug=self.sentry_app.slug,
            organization=self.org,
        )
コード例 #35
0
 def test_members_cannot_install_apps(self):
     user = self.create_user('*****@*****.**')
     self.create_member(
         organization=self.org,
         user=user,
         role='member',
     )
     self.login_as(user)
     app = SentryAppCreator.run(
         name='Sample',
         organization=self.org,
         scopes=(),
         webhook_url='https://example.com',
     )
     app.update(status=SentryAppStatus.PUBLISHED)
     response = self.client.post(
         self.url,
         data={'slug': app.slug},
         format='json',
     )
     assert response.status_code == 403
コード例 #36
0
    def setUp(self):
        self.permission = SentryAppInstallationDetailsPermission()

        self.user = self.create_user()
        self.member = self.create_user()
        self.org = self.create_organization(owner=self.member)

        self.sentry_app = SentryAppCreator.run(
            name='foo',
            user=self.user,
            scopes=(),
            webhook_url='https://example.com',
        )

        self.installation, _ = SentryAppInstallationCreator.run(
            slug=self.sentry_app.slug,
            organization=self.org,
        )

        self.request = HttpRequest()
        self.request.user = self.user
コード例 #37
0
ファイル: test_authorizer.py プロジェクト: alexandrul/sentry
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization()

        self.sentry_app = SentryAppCreator.run(
            name='nulldb',
            organization=self.org,
            scopes=(),
            webhook_url='http://example.com',
        )

        self.install, self.grant = Creator.run(
            organization=self.org,
            slug='nulldb',
        )

        self.authorizer = Authorizer(
            install=self.install,
            grant_type='authorization_code',
            code=self.grant.code,
            client_id=self.sentry_app.application.client_id,
            user=self.sentry_app.proxy_user,
        )
コード例 #38
0
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization()

        self.sentry_app = SentryAppCreator.run(
            name='nulldb',
            organization=self.org,
            scopes=(),
            webhook_url='http://example.com',
        )

        self.install, self.grant = Creator.run(
            organization=self.org,
            slug='nulldb',
        )

        self.authorizer = Authorizer(
            install=self.install,
            grant_type='authorization_code',
            code=self.grant.code,
            client_id=self.sentry_app.application.client_id,
            user=self.sentry_app.proxy_user,
        )
コード例 #39
0
ファイル: test_creator.py プロジェクト: mjumbewu/sentry
class TestCreator(TestCase):
    def setUp(self):
        self.user = self.create_user()
        self.creator = Creator(name='nulldb',
                               user=self.user,
                               scopes=('project:read',),
                               webhook_url='http://example.com')

    def test_creates_proxy_user(self):
        self.creator.call()

        assert User.objects.get(
            username='******',
            is_sentry_app=True,
        )

    def test_creates_api_application(self):
        self.creator.call()
        proxy = User.objects.get(username='******')

        assert ApiApplication.objects.get(owner=proxy)

    def test_creates_sentry_app(self):
        self.creator.call()

        proxy = User.objects.get(username='******')
        app = ApiApplication.objects.get(owner=proxy)

        sentry_app = SentryApp.objects.get(
            name='nulldb',
            application=app,
            owner=self.user,
            proxy_user=proxy,
        )

        assert sentry_app
        assert sentry_app.scope_list == ['project:read']
コード例 #40
0
ファイル: test_creator.py プロジェクト: zuolei828/sentry
class TestCreator(TestCase):
    def setUp(self):
        self.user = self.create_user()
        self.creator = Creator(name='nulldb',
                               user=self.user,
                               scopes=('project:read', ),
                               webhook_url='http://example.com')

    def test_creates_proxy_user(self):
        self.creator.call()

        assert User.objects.get(
            username='******',
            is_sentry_app=True,
        )

    def test_creates_api_application(self):
        self.creator.call()
        proxy = User.objects.get(username='******')

        assert ApiApplication.objects.get(owner=proxy)

    def test_creates_sentry_app(self):
        self.creator.call()

        proxy = User.objects.get(username='******')
        app = ApiApplication.objects.get(owner=proxy)

        sentry_app = SentryApp.objects.get(
            name='nulldb',
            application=app,
            owner=self.user,
            proxy_user=proxy,
        )

        assert sentry_app
        assert sentry_app.scope_list == ['project:read']
コード例 #41
0
ファイル: test_creator.py プロジェクト: liang0/sentry-1
class TestCreator(TestCase):
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization(owner=self.user)
        self.creator = Creator(
            name="nulldb",
            user=self.user,
            author="Sentry",
            organization=self.org,
            scopes=("project:read", ),
            webhook_url="http://example.com",
            schema={"elements": [self.create_issue_link_schema()]},
            is_internal=False,
        )

    def test_slug(self):
        app = self.creator.call()
        assert app.slug == "nulldb"

    def test_creates_proxy_user(self):
        self.creator.call()

        assert User.objects.get(username__contains="nulldb",
                                is_sentry_app=True)

    def test_creates_api_application(self):
        self.creator.call()
        proxy = User.objects.get(username__contains="nulldb")

        assert ApiApplication.objects.get(owner=proxy)

    def test_creates_sentry_app(self):
        self.creator.call()

        proxy = User.objects.get(username__contains="nulldb")
        app = ApiApplication.objects.get(owner=proxy)

        sentry_app = SentryApp.objects.get(name="nulldb",
                                           application=app,
                                           owner=self.org,
                                           proxy_user=proxy)

        assert sentry_app
        assert sentry_app.scope_list == ["project:read"]

    def test_expands_rolled_up_events(self):
        self.creator.events = ["issue"]
        app = self.creator.call()

        sentry_app = SentryApp.objects.get(id=app.id)

        assert "issue.created" in sentry_app.events

    def test_creates_ui_components(self):
        self.creator.schema = {
            "elements": [
                self.create_issue_link_schema(),
                self.create_alert_rule_action_schema()
            ]
        }

        app = self.creator.call()

        assert SentryAppComponent.objects.filter(sentry_app_id=app.id,
                                                 type="issue-link").exists()

        assert SentryAppComponent.objects.filter(
            sentry_app_id=app.id, type="alert-rule-action").exists()

    def test_creates_integration_feature(self):
        app = self.creator.call()
        assert IntegrationFeature.objects.filter(sentry_app=app).exists()

    @patch("sentry.mediators.sentry_apps.creator.Creator.log")
    @patch("sentry.models.integrationfeature.IntegrationFeature.objects.create"
           )
    def test_raises_error_creating_integration_feature(self, mock_create,
                                                       mock_log):
        mock_create.side_effect = IntegrityError()
        self.creator.call()
        mock_log.assert_called_with(sentry_app="nulldb", error_message="")

    def test_creates_audit_log_entry(self):
        request = self.make_request(user=self.user, method="GET")
        Creator.run(
            name="nulldb",
            user=self.user,
            author="Sentry",
            organization=self.org,
            scopes=("project:read", ),
            webhook_url="http://example.com",
            schema={"elements": [self.create_issue_link_schema()]},
            request=request,
            is_internal=False,
        )
        assert AuditLogEntry.objects.filter(
            event=AuditLogEntryEvent.SENTRY_APP_ADD).exists()

    def test_blank_schema(self):
        self.creator.schema = ""
        assert self.creator.call()

    def test_none_schema(self):
        self.creator.schema = None
        assert self.creator.call()

    def test_schema_with_no_elements(self):
        self.creator.schema = {"elements": []}
        assert self.creator.call()

    @patch("sentry.analytics.record")
    def test_records_analytics(self, record):
        sentry_app = Creator.run(
            name="nulldb",
            user=self.user,
            author="Sentry",
            organization=self.org,
            scopes=("project:read", ),
            webhook_url="http://example.com",
            schema={"elements": [self.create_issue_link_schema()]},
            request=self.make_request(user=self.user, method="GET"),
            is_internal=False,
        )

        record.assert_called_with(
            "sentry_app.created",
            user_id=self.user.id,
            organization_id=self.org.id,
            sentry_app=sentry_app.slug,
        )

    def test_allows_name_that_exists_as_username_already(self):
        self.create_user(username="******")
        assert self.creator.call()
コード例 #42
0
ファイル: test_creator.py プロジェクト: mjumbewu/sentry
 def setUp(self):
     self.user = self.create_user()
     self.creator = Creator(name='nulldb',
                            user=self.user,
                            scopes=('project:read',),
                            webhook_url='http://example.com')
コード例 #43
0
ファイル: test_creator.py プロジェクト: zuolei828/sentry
 def setUp(self):
     self.user = self.create_user()
     self.creator = Creator(name='nulldb',
                            user=self.user,
                            scopes=('project:read', ),
                            webhook_url='http://example.com')
コード例 #44
0
class TestCreator(TestCase):
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization(owner=self.user)
        self.creator = Creator(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read', ),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
        )

    def test_creates_proxy_user(self):
        self.creator.call()

        assert User.objects.get(
            username='******',
            is_sentry_app=True,
        )

    def test_creates_api_application(self):
        self.creator.call()
        proxy = User.objects.get(username='******')

        assert ApiApplication.objects.get(owner=proxy)

    def test_creates_sentry_app(self):
        self.creator.call()

        proxy = User.objects.get(username='******')
        app = ApiApplication.objects.get(owner=proxy)

        sentry_app = SentryApp.objects.get(
            name='nulldb',
            application=app,
            owner=self.org,
            proxy_user=proxy,
        )

        assert sentry_app
        assert sentry_app.scope_list == ['project:read']

    def test_expands_rolled_up_events(self):
        self.creator.events = ['issue']
        app = self.creator.call()

        sentry_app = SentryApp.objects.get(id=app.id)

        assert 'issue.created' in sentry_app.events

    def test_creates_ui_components(self):
        self.creator.schema = {
            'elements': [
                self.create_issue_link_schema(),
                self.create_alert_rule_action_schema(),
            ],
        }

        app = self.creator.call()

        assert SentryAppComponent.objects.filter(
            sentry_app_id=app.id,
            type='issue-link',
        ).exists()

        assert SentryAppComponent.objects.filter(
            sentry_app_id=app.id,
            type='alert-rule-action',
        ).exists()

    def test_creates_integration_feature(self):
        app = self.creator.call()
        assert IntegrationFeature.objects.filter(sentry_app=app).exists()

    @patch('sentry.mediators.sentry_apps.creator.Creator.log')
    @patch('sentry.models.integrationfeature.IntegrationFeature.objects.create'
           )
    def test_raises_error_creating_integration_feature(self, mock_create,
                                                       mock_log):
        mock_create.side_effect = IntegrityError()
        self.creator.call()
        mock_log.assert_called_with(
            sentry_app='nulldb',
            error_message='',
        )

    def test_creates_audit_log_entry(self):
        request = self.make_request(user=self.user, method='GET')
        Creator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read', ),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=request,
        )
        assert AuditLogEntry.objects.filter(
            event=AuditLogEntryEvent.SENTRY_APP_ADD).exists()

    def test_blank_schema(self):
        self.creator.schema = ''
        assert self.creator.call()

    def test_none_schema(self):
        self.creator.schema = None
        assert self.creator.call()

    def test_schema_with_no_elements(self):
        self.creator.schema = {'elements': []}
        assert self.creator.call()

    @patch('sentry.analytics.record')
    def test_records_analytics(self, record):
        sentry_app = Creator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read', ),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=self.make_request(user=self.user, method='GET'))

        record.assert_called_with(
            'sentry_app.created',
            user_id=self.user.id,
            organization_id=self.org.id,
            sentry_app=sentry_app.slug,
        )
コード例 #45
0
ファイル: test_creator.py プロジェクト: yaoqi/sentry
class TestCreator(TestCase):
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization(owner=self.user)
        self.creator = Creator(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
        )

    def test_creates_proxy_user(self):
        self.creator.call()

        assert User.objects.get(
            username='******',
            is_sentry_app=True,
        )

    def test_creates_api_application(self):
        self.creator.call()
        proxy = User.objects.get(username='******')

        assert ApiApplication.objects.get(owner=proxy)

    def test_creates_sentry_app(self):
        self.creator.call()

        proxy = User.objects.get(username='******')
        app = ApiApplication.objects.get(owner=proxy)

        sentry_app = SentryApp.objects.get(
            name='nulldb',
            application=app,
            owner=self.org,
            proxy_user=proxy,
        )

        assert sentry_app
        assert sentry_app.scope_list == ['project:read']

    def test_expands_rolled_up_events(self):
        self.creator.events = ['issue']
        app = self.creator.call()

        sentry_app = SentryApp.objects.get(id=app.id)

        assert 'issue.created' in sentry_app.events

    def test_creates_ui_components(self):
        self.creator.schema = {
            'elements': [
                self.create_issue_link_schema(),
                self.create_alert_rule_action_schema(),
            ],
        }

        app = self.creator.call()

        assert SentryAppComponent.objects.filter(
            sentry_app_id=app.id,
            type='issue-link',
        ).exists()

        assert SentryAppComponent.objects.filter(
            sentry_app_id=app.id,
            type='alert-rule-action',
        ).exists()

    def test_creates_audit_log_entry(self):
        request = self.make_request(user=self.user, method='GET')
        Creator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=request,
        )
        assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_ADD).exists()

    def test_blank_schema(self):
        self.creator.schema = ''
        assert self.creator.call()

    def test_none_schema(self):
        self.creator.schema = None
        assert self.creator.call()

    def test_schema_with_no_elements(self):
        self.creator.schema = {'elements': []}
        assert self.creator.call()

    @patch('sentry.analytics.record')
    def test_records_analytics(self, record):
        sentry_app = Creator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=self.make_request(user=self.user, method='GET')
        )

        record.assert_called_with(
            'sentry_app.created',
            user_id=self.user.id,
            organization_id=self.org.id,
            sentry_app=sentry_app.slug,
        )
コード例 #46
0
class TestCreator(TestCase):
    def setUp(self):
        self.user = self.create_user()
        self.org = self.create_organization(owner=self.user)
        self.creator = Creator(
            name='nulldb',
            organization=self.org,
            scopes=('project:read', ),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
        )

    def test_creates_proxy_user(self):
        self.creator.call()

        assert User.objects.get(
            username='******',
            is_sentry_app=True,
        )

    def test_creates_api_application(self):
        self.creator.call()
        proxy = User.objects.get(username='******')

        assert ApiApplication.objects.get(owner=proxy)

    def test_creates_sentry_app(self):
        self.creator.call()

        proxy = User.objects.get(username='******')
        app = ApiApplication.objects.get(owner=proxy)

        sentry_app = SentryApp.objects.get(
            name='nulldb',
            application=app,
            owner=self.org,
            proxy_user=proxy,
        )

        assert sentry_app
        assert sentry_app.scope_list == ['project:read']

    def test_expands_rolled_up_events(self):
        self.creator.events = ['issue']
        app = self.creator.call()

        sentry_app = SentryApp.objects.get(id=app.id)

        assert 'issue.created' in sentry_app.events

    def test_creates_ui_components(self):
        self.creator.schema = {
            'elements': [
                self.create_issue_link_schema(),
                self.create_alert_rule_action_schema(),
            ],
        }

        app = self.creator.call()

        assert SentryAppComponent.objects.filter(
            sentry_app_id=app.id,
            type='issue-link',
        ).exists()

        assert SentryAppComponent.objects.filter(
            sentry_app_id=app.id,
            type='alert-rule-action',
        ).exists()

    def test_blank_schema(self):
        self.creator.schema = ''
        assert self.creator.call()

    def test_none_schema(self):
        self.creator.schema = None
        assert self.creator.call()

    def test_schema_with_no_elements(self):
        self.creator.schema = {'elements': []}
        assert self.creator.call()