How to use the sentry.testutils.APITestCase 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 / models / test_debugfile.py View on Github external
# XXX: If no file has features, in a group, the newest one is chosen,
        # regardless of the required feature set.
        difs = ProjectDebugFile.objects.find_by_debug_ids(
            project=self.project, debug_ids=[debug_id1], features=['debug'])
        assert difs[debug_id1].id == dif1.id

    def test_find_dif_miss_by_features(self):
        debug_id = 'dfb8e43a-f242-3d73-a453-aeb6a777ef75'
        self.create_dif_file(debug_id=debug_id, features=[])

        difs = ProjectDebugFile.objects.find_by_debug_ids(
            project=self.project, debug_ids=[debug_id], features=['debug'])
        assert debug_id not in difs


class CreateDebugFileTest(APITestCase):
    @property
    def file_path(self):
        return os.path.join(os.path.dirname(__file__), 'fixtures', 'crash.dsym')

    def create_dif(self, fileobj=None, file=None, **kwargs):
        args = {
            'file_format': 'macho',
            'arch': 'x86_64',
            'debug_id': '67e9247c-814e-392b-a027-dbde6748fcbf',
            'data': {'features': ['debug']},
            'path': 'crash.dsym',
        }

        args.update(kwargs)
        return debugfile.create_dif_from_id(
            self.project, DifMeta(**args), fileobj=fileobj, file=file)
github getsentry / sentry / tests / snuba / api / endpoints / test_organization_events_v2.py View on Github external
from __future__ import absolute_import


from django.core.urlresolvers import reverse

from sentry.testutils import APITestCase, SnubaTestCase
from sentry.testutils.helpers.datetime import before_now, iso_format
from sentry.utils.samples import load_data
import pytest


class OrganizationEventsV2EndpointTest(APITestCase, SnubaTestCase):
    def setUp(self):
        super(OrganizationEventsV2EndpointTest, self).setUp()
        self.min_ago = iso_format(before_now(minutes=1))
        self.two_min_ago = iso_format(before_now(minutes=2))
        self.url = reverse(
            "sentry-api-0-organization-eventsv2",
            kwargs={"organization_slug": self.organization.slug},
        )

    def test_no_projects(self):
        self.login_as(user=self.user)
        with self.feature("organizations:events-v2"):
            response = self.client.get(self.url, format="json")

        assert response.status_code == 200, response.content
        assert len(response.data) == 0
github getsentry / sentry / tests / snuba / api / endpoints / test_organization_events.py View on Github external
from __future__ import absolute_import

import six
from six.moves.urllib.parse import urlencode

from django.utils import timezone
from django.core.urlresolvers import reverse

from sentry.testutils import APITestCase, SnubaTestCase
from sentry.testutils.helpers.datetime import before_now, iso_format


class OrganizationEventsEndpointTest(APITestCase, SnubaTestCase):
    def setUp(self):
        super(OrganizationEventsEndpointTest, self).setUp()
        self.min_ago = before_now(minutes=1)
        self.day_ago = before_now(days=1)

    def assert_events_in_response(self, response, event_ids):
        assert sorted(map(lambda x: x["eventID"], response.data)) == sorted(event_ids)

    def test_simple(self):
        self.login_as(user=self.user)

        project = self.create_project()
        project2 = self.create_project()

        event_1 = self.store_event(
            data={"event_id": "a" * 32, "timestamp": iso_format(self.min_ago)},
github getsentry / sentry / tests / sentry / api / endpoints / test_project_events.py View on Github external
from __future__ import absolute_import

import six

from datetime import timedelta
from django.utils import timezone
from django.core.urlresolvers import reverse

from sentry.testutils import APITestCase, SnubaTestCase


class ProjectEventsTest(APITestCase, SnubaTestCase):
    def setUp(self):
        super(ProjectEventsTest, self).setUp()

    def test_simple(self):
        self.login_as(user=self.user)

        project = self.create_project()
        min_ago = (timezone.now() - timedelta(minutes=1)).isoformat()[:19]

        event_1 = self.store_event(
            data={
                'fingerprint': ['group_1'],
                'timestamp': min_ago
            },
            project_id=project.id,
        )
github getsentry / sentry / tests / sentry / api / endpoints / test_project_details.py View on Github external
self.assert_settings_not_copied(project, teams=[team])

    @mock.patch("sentry.models.project.Project.copy_settings_from")
    def test_copy_project_settings_fails(self, mock_copy_settings_from):
        mock_copy_settings_from.return_value = False
        project = self.create_project(fire_project_created=True)
        resp = self.client.put(
            self.path(project), data={"copy_from_project": self.other_project.id}
        )
        assert resp.status_code == 409
        assert resp.data == {"detail": ["Copy project settings failed."]}
        self.assert_settings_not_copied(project)
        self.assert_other_project_settings_not_changed()


class ProjectDeleteTest(APITestCase):
    @mock.patch("sentry.db.mixin.uuid4")
    @mock.patch("sentry.api.endpoints.project_details.uuid4")
    @mock.patch("sentry.api.endpoints.project_details.delete_project")
    def test_simple(self, mock_delete_project, mock_uuid4_project, mock_uuid4_mixin):
        class uuid(object):
            hex = "abc123"

        mock_uuid4_mixin.return_value = uuid
        mock_uuid4_project.return_value = uuid
        project = self.create_project()

        self.login_as(user=self.user)

        url = reverse(
            "sentry-api-0-project-details",
            kwargs={"organization_slug": project.organization.slug, "project_slug": project.slug},
github getsentry / sentry / tests / sentry / api / endpoints / test_organization_member_issues_assigned.py View on Github external
from __future__ import absolute_import

import six

from datetime import timedelta
from django.core.urlresolvers import reverse
from django.utils import timezone

from sentry.models import GroupAssignee, ProjectStatus
from sentry.testutils import APITestCase


class OrganizationMemberIssuesAssignedTest(APITestCase):
    def test_simple(self):
        now = timezone.now()
        user = self.create_user("foo@example.com")
        org = self.create_organization(name="foo")
        team = self.create_team(name="foo", organization=org)
        self.create_member(organization=org, user=user, role="admin", teams=[team])
        project1 = self.create_project(name="foo", organization=org, teams=[team])
        group1 = self.create_group(project=project1)
        group2 = self.create_group(project=project1)
        project2 = self.create_project(
            name="bar", organization=org, teams=[team], status=ProjectStatus.PENDING_DELETION
        )
        group3 = self.create_group(project=project2)
        GroupAssignee.objects.create(group=group1, project=project1, user=user, date_added=now)
        GroupAssignee.objects.create(
            group=group2, project=project1, user=user, date_added=now + timedelta(seconds=1)
github getsentry / sentry / tests / sentry / api / endpoints / test_organization_searches.py View on Github external
from __future__ import absolute_import

import django
from django.utils import timezone
from exam import fixture

from sentry.api.serializers import serialize
from sentry.models import SavedSearch
from sentry.models.search_common import SearchType
from sentry.models.savedsearch import DEFAULT_SAVED_SEARCHES
from sentry.testutils import APITestCase


class OrganizationSearchesListTest(APITestCase):
    endpoint = "sentry-api-0-organization-searches"

    @fixture
    def user(self):
        return self.create_user("test@test.com")

    def test_simple(self):
        self.login_as(user=self.user)
        team = self.create_team(members=[self.user])
        project1 = self.create_project(teams=[team], name="foo")
        project2 = self.create_project(teams=[team], name="bar")

        if django.VERSION[:2] >= (1, 8):
            # Depending on test we run migrations in Django 1.8. This causes
            # extra rows to be created, so remove them to keep this test working
            SavedSearch.objects.filter(is_global=True).delete()
github getsentry / sentry / tests / sentry / api / endpoints / test_organization_dashboards.py View on Github external
from __future__ import absolute_import

import six

from django.core.urlresolvers import reverse

from sentry.models import Dashboard
from sentry.testutils import APITestCase


class OrganizationDashboardsTest(APITestCase):
    def setUp(self):
        super(OrganizationDashboardsTest, self).setUp()
        self.login_as(self.user)
        self.url = reverse(
            "sentry-api-0-organization-dashboards",
            kwargs={"organization_slug": self.organization.slug},
        )
        self.dashboard_1 = Dashboard.objects.create(
            title="Dashboard 1", created_by=self.user, organization=self.organization
        )
        self.dashboard_2 = Dashboard.objects.create(
            title="Dashboard 2", created_by=self.user, organization=self.organization
        )

    def assert_equal_dashboards(self, dashboard, data):
        assert data["id"] == six.text_type(dashboard.id)
github getsentry / sentry / tests / sentry / api / endpoints / test_team_details.py View on Github external
from __future__ import absolute_import

import six

from django.core.urlresolvers import reverse
from mock import patch

from sentry.models import AuditLogEntry, AuditLogEntryEvent, Team, TeamStatus, DeletedTeam
from sentry.testutils import APITestCase


class TeamDetailsTest(APITestCase):
    def test_simple(self):
        team = self.team  # force creation
        self.login_as(user=self.user)
        url = reverse(
            "sentry-api-0-team-details",
            kwargs={"organization_slug": team.organization.slug, "team_slug": team.slug},
        )
        response = self.client.get(url)
        assert response.status_code == 200
        assert response.data["id"] == six.text_type(team.id)


class TeamUpdateTest(APITestCase):
    def test_simple(self):
        team = self.team  # force creation
        self.login_as(user=self.user)
github getsentry / sentry / tests / sentry / api / endpoints / test_dif_assemble.py View on Github external
from django.core.files.base import ContentFile

from sentry.models import ApiToken, FileBlob, File, FileBlobIndex, FileBlobOwner
from sentry.models.debugfile import ProjectDebugFile
from sentry.testutils import APITestCase
from sentry.tasks.assemble import (
    assemble_dif,
    assemble_file,
    get_assemble_status,
    set_assemble_status,
    AssembleTask,
    ChunkFileState,
)


class DifAssembleEndpoint(APITestCase):
    def setUp(self):
        self.organization = self.create_organization(owner=self.user)
        self.token = ApiToken.objects.create(user=self.user, scope_list=["project:write"])
        self.team = self.create_team(organization=self.organization)
        self.project = self.create_project(
            teams=[self.team], organization=self.organization, name="foo"
        )
        self.url = reverse(
            "sentry-api-0-assemble-dif-files", args=[self.organization.slug, self.project.slug]
        )

    def test_assemble_json_schema(self):
        response = self.client.post(
            self.url, data={"lol": "test"}, HTTP_AUTHORIZATION=u"Bearer {}".format(self.token.token)
        )
        assert response.status_code == 400, response.content