How to use the sentry.testutils.TestCase function in sentry

To help you get started, we’ve selected a few sentry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github getsentry / sentry / tests / sentry / lang / javascript / test_sourcemaps.py View on Github external
src_id=1,
                name='captureException'
            ),
            SourceMapTokenMatch(
                dst_line=0,
                dst_col=191,
                src='foo/file2.js',
                src_line=9,
                src_col=25,
                src_id=1,
                name='e'
            ),
        ]


class ParseIndexedSourcemapTest(TestCase):
    # Tests lookups that fall exactly on source map token boundaries
    # https://github.com/mozilla/source-map/blob/master/test/test-source-map-consumer.js#138
    def test_exact_mappings(self):
        smap_view = SourceMapView.from_json_bytes(indexed_sourcemap_example)

        # one.js
        assert smap_view.lookup(0, 1) == SourceMapTokenMatch(
            dst_line=0,
            dst_col=1,
            src='/the/root/one.js',
            src_line=0,
            src_col=1,
            src_id=0,
            name=None
        )
        assert smap_view.lookup(0, 18) == SourceMapTokenMatch(
github getsentry / sentry / tests / sentry / models / test_pullrequest.py View on Github external
from __future__ import absolute_import

from hashlib import sha1
from uuid import uuid4

from sentry.models import Commit, Repository, PullRequest
from sentry.testutils import TestCase


class FindReferencedGroupsTest(TestCase):
    def test_multiple_matches_basic(self):
        group = self.create_group()
        group2 = self.create_group()

        repo = Repository.objects.create(name="example", organization_id=self.group.organization.id)

        commit = Commit.objects.create(
            key=sha1(uuid4().hex).hexdigest(),
            repository_id=repo.id,
            organization_id=group.organization.id,
            message=u"Foo Biz\n\nFixes {}".format(group.qualified_short_id),
        )

        groups = commit.find_referenced_groups()
        assert len(groups) == 1
        assert group in groups
github getsentry / sentry / tests / sentry / integrations / slack / test_link_identity.py View on Github external
import responses

from mock import patch

from sentry.models import (
    Identity,
    IdentityProvider,
    IdentityStatus,
    Integration,
    OrganizationIntegration,
)
from sentry.testutils import TestCase
from sentry.integrations.slack.link_identity import build_linking_url


class SlackIntegrationLinkIdentityTest(TestCase):
    def setUp(self):
        super(TestCase, self).setUp()
        self.user1 = self.create_user(is_superuser=False)
        self.user2 = self.create_user(is_superuser=False)
        self.org = self.create_organization(owner=None)
        self.team = self.create_team(organization=self.org, members=[self.user1, self.user2])

        self.login_as(self.user1)

        self.integration = Integration.objects.create(
            provider="slack",
            external_id="TXXXXXXX1",
            metadata={"access_token": "xoxa-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"},
        )
        OrganizationIntegration.objects.create(organization=self.org, integration=self.integration)
github NetEaseGame / Sentry / tests / sentry / utils / queue / tests.py View on Github external
from __future__ import absolute_import

from sentry.utils.queue import can_queue
from sentry.testutils import TestCase


def test_func():
    pass


class CanQueueTest(TestCase):
    def test_disabled(self):
        with self.Settings(SENTRY_USE_QUEUE=False):
            self.assertFalse(can_queue(test_func))

    def test_empty_whitelist(self):
        with self.Settings(SENTRY_USE_QUEUE=()):
            self.assertFalse(can_queue(test_func))

    def test_enabled(self):
        with self.Settings(SENTRY_USE_QUEUE=True):
            self.assertTrue(can_queue(test_func))

    def test_in_whitelist(self):
        with self.Settings(SENTRY_USE_QUEUE=('%s.test_func' % (__name__,))):
            self.assertTrue(can_queue(test_func))
github NetEaseGame / Sentry / tests / sentry / utils / email / tests.py View on Github external
from __future__ import absolute_import

from mock import patch

from django.core import mail

from sentry.models import User, UserOption, GroupEmailThread
from sentry.testutils import TestCase
from sentry.utils.email import MessageBuilder


class MessageBuilderTest(TestCase):
    def test_raw_content(self):
        msg = MessageBuilder(
            subject='Test',
            body='hello world',
            html_body='<b>hello world</b>',
            headers={'X-Test': 'foo'},
        )
        msg.send(['foo@example.com'])

        assert len(mail.outbox) == 1

        out = mail.outbox[0]
        assert out.to == ['foo@example.com']
        assert out.subject == 'Test'
        assert out.extra_headers['X-Test'] == 'foo'
        assert out.body == 'hello world'
github NetEaseGame / Sentry / tests / sentry / web / frontend / projects / tests.py View on Github external
def test_requires_authentication(self):
        self.assertRequiresAuthentication(self.path, 'POST')

    def test_does_not_respond_to_get(self):
        resp = self.client.get(self.path)
        assert resp.status_code == 405

    def test_removes_key_and_redirects(self):
        self.login_as(self.user)

        resp = self.client.post(self.path)
        assert resp.status_code == 302
        assert not ProjectKey.objects.filter(id=self.key.id).exists()


class EnableProjectKeyTest(TestCase):
    def setUp(self):
        super(EnableProjectKeyTest, self).setUp()
        self.key = ProjectKey.objects.create(
            project=self.project,
            status=ProjectKeyStatus.INACTIVE,
        )

    @fixture
    def path(self):
        return reverse('sentry-enable-project-key', args=[self.organization.slug, self.project.id, self.key.id])

    def test_requires_authentication(self):
        self.assertRequiresAuthentication(self.path, 'POST')

    def test_does_not_respond_to_get(self):
        resp = self.client.get(self.path)
github getsentry / sentry / tests / integration / tests.py View on Github external
hub.capture_message('foo')
        hub.client.close()

        for _request in requests:
            self.send_event(*_request)

        assert request.call_count is 1
        assert Group.objects.count() == 1
        group = Group.objects.get()
        assert group.event_set.count() == 1
        instance = group.event_set.get()
        assert instance.data['logentry']['formatted'] == 'foo'


class SentryRemoteTest(TestCase):
    @fixture
    def path(self):
        return reverse('sentry-api-store')

    def test_minimal(self):
        kwargs = {'message': 'hello', 'tags': {'foo': 'bar'}}

        resp = self._postWithHeader(kwargs)

        assert resp.status_code == 200, resp.content

        event_id = json.loads(resp.content)['id']
        instance = Event.objects.get(event_id=event_id)
        Event.objects.bind_nodes([instance], 'data')

        assert instance.message == 'hello'
github NetEaseGame / Sentry / tests / sentry / web / frontend / projects / tests.py View on Github external
self.assertRequiresAuthentication(self.path, 'POST')

    def test_does_not_respond_to_get(self):
        resp = self.client.get(self.path)
        assert resp.status_code == 405

    def test_does_enable(self):
        self.login_as(self.user)

        resp = self.client.post(self.path)
        assert resp.status_code == 302
        key = ProjectKey.objects.get(id=self.key.id)
        assert key.status == ProjectKeyStatus.ACTIVE


class DisableProjectKeyTest(TestCase):
    def setUp(self):
        super(DisableProjectKeyTest, self).setUp()
        self.key = ProjectKey.objects.create(
            project=self.project,
            status=ProjectKeyStatus.ACTIVE,
        )

    @fixture
    def path(self):
        return reverse('sentry-disable-project-key', args=[self.organization.slug, self.project.id, self.key.id])

    def test_requires_authentication(self):
        self.assertRequiresAuthentication(self.path, 'POST')

    def test_does_not_respond_to_get(self):
        resp = self.client.get(self.path)
github getsentry / sentry / tests / sentry / models / test_identity.py View on Github external
from sentry.identity import register
from sentry.identity.base import Provider
from sentry.models import Identity, IdentityProvider
from sentry.testutils import TestCase


class ProviderDummy(Provider):
    name = "Tester"
    key = "tester"

    def build_identity(self, state):
        pass


class IdentityTestCase(TestCase):
    def test_get_provider(self):
        provider_model = IdentityProvider.objects.create(type="tester", external_id="tester_id")

        register(ProviderDummy)
        identity_model = Identity.objects.create(
            idp=provider_model, user=self.user, external_id="identity_id"
        )

        provider = identity_model.get_provider()
        assert provider.name == "Tester"
        assert provider.key == "tester"
github getsentry / sentry / tests / sentry / api / validators / sentry_apps / test_issue_link.py View on Github external
from __future__ import absolute_import

from sentry.testutils import TestCase

from .util import invalid_schema
from sentry.api.validators.sentry_apps.schema import validate_component


class TestIssueLinkSchemaValidation(TestCase):
    def setUp(self):
        self.schema = {
            "type": "issue-link",
            "link": {
                "uri": "/sentry/tasks/link",
                "required_fields": [
                    {
                        "type": "select",
                        "name": "task_id",
                        "label": "Task ID",
                        "uri": "/sentry/tasks",
                    }
                ],
                "optional_fields": [{"type": "text", "name": "owner", "label": "Owner"}],
            },
            "create": {