From b530116533abc5cadd79093e80334b48bd6367f2 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 21:22:02 +0000 Subject: [PATCH] ref(releases): Remove experimental release threshold endpoints Remove the experimental release threshold create, list, update, and delete endpoints, which have no callers and no UI, and the unused /release-thresholds/ page route. Mark the public status endpoint deprecated. It is exported by @sentry/api, so removing it waits for that package's next major release. Refs ISWF-3793 Co-Authored-By: Athena Moghaddam <132939361+sentaur-athena@users.noreply.github.com> --- .../release_thresholds/release_threshold.py | 87 ----- .../release_threshold_details.py | 103 ------ .../release_threshold_index.py | 72 ---- .../release_threshold_status_index.py | 1 + src/sentry/api/urls.py | 22 -- .../api_pagination_allowlist_do_not_modify.py | 1 - .../models/release_threshold/constants.py | 34 -- src/sentry/web/urls.py | 5 - .../utils/api/knownSentryApiUrls.generated.ts | 3 - .../test_release_threshold.py | 237 ------------- .../test_release_threshold_details.py | 329 ------------------ .../test_release_thresholds_index.py | 175 ---------- 12 files changed, 1 insertion(+), 1068 deletions(-) delete mode 100644 src/sentry/api/endpoints/release_thresholds/release_threshold.py delete mode 100644 src/sentry/api/endpoints/release_thresholds/release_threshold_details.py delete mode 100644 src/sentry/api/endpoints/release_thresholds/release_threshold_index.py delete mode 100644 tests/sentry/api/endpoints/release_thresholds/test_release_threshold.py delete mode 100644 tests/sentry/api/endpoints/release_thresholds/test_release_threshold_details.py delete mode 100644 tests/sentry/api/endpoints/release_thresholds/test_release_thresholds_index.py diff --git a/src/sentry/api/endpoints/release_thresholds/release_threshold.py b/src/sentry/api/endpoints/release_thresholds/release_threshold.py deleted file mode 100644 index 6812711fbb36..000000000000 --- a/src/sentry/api/endpoints/release_thresholds/release_threshold.py +++ /dev/null @@ -1,87 +0,0 @@ -from typing import TypedDict - -from django.http import HttpResponse -from rest_framework import serializers -from rest_framework.request import Request -from rest_framework.response import Response - -from sentry.api.api_owners import ApiOwner -from sentry.api.api_publish_status import ApiPublishStatus -from sentry.api.base import cell_silo_endpoint -from sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission -from sentry.api.serializers import serialize -from sentry.api.serializers.rest_framework.environment import EnvironmentField -from sentry.models.project import Project -from sentry.models.release_threshold.constants import ( - THRESHOLD_TYPE_STR_TO_INT, - TRIGGER_TYPE_STRING_TO_INT, - ReleaseThresholdType, -) -from sentry.models.release_threshold.constants import TriggerType as ReleaseThresholdTriggerType -from sentry.models.release_threshold.release_threshold import ReleaseThreshold - - -class ReleaseThresholdPOSTData(TypedDict, total=False): - threshold_type: int - trigger_type: int - value: int - window_in_seconds: int - environment: object - - -class ReleaseThresholdPOSTSerializer(serializers.Serializer[ReleaseThresholdPOSTData]): - threshold_type = serializers.ChoiceField(choices=ReleaseThresholdType.as_str_choices()) - trigger_type = serializers.ChoiceField(choices=ReleaseThresholdTriggerType.as_str_choices()) - value = serializers.IntegerField(required=True, min_value=0) - window_in_seconds = serializers.IntegerField(required=True, min_value=0) - environment = EnvironmentField(required=False, allow_null=True) - - def validate_threshold_type(self, threshold_type: str) -> int: - if threshold_type not in THRESHOLD_TYPE_STR_TO_INT: - raise serializers.ValidationError("Invalid threshold type") - return THRESHOLD_TYPE_STR_TO_INT[threshold_type] - - def validate_trigger_type(self, trigger_type: str) -> int: - if trigger_type not in TRIGGER_TYPE_STRING_TO_INT: - raise serializers.ValidationError("Invalid trigger type") - return TRIGGER_TYPE_STRING_TO_INT[trigger_type] - - -@cell_silo_endpoint -class ReleaseThresholdEndpoint(ProjectEndpoint): - permission_classes = (ProjectReleasePermission,) - owner: ApiOwner = ApiOwner.REPLAY - publish_status = { - "GET": ApiPublishStatus.EXPERIMENTAL, - "POST": ApiPublishStatus.EXPERIMENTAL, - } - - def post(self, request: Request, project: Project) -> HttpResponse: - serializer = ReleaseThresholdPOSTSerializer( - data=request.data, - context={ - "organization": project.organization, - "access": request.access, - }, - ) - if not serializer.is_valid(): - return Response(serializer.errors, status=400) - result = serializer.validated_data - - release_threshold = ReleaseThreshold.objects.create( - threshold_type=result.get("threshold_type"), - trigger_type=result.get("trigger_type"), - value=result.get("value"), - window_in_seconds=result.get("window_in_seconds"), - project=project, - environment=result.get("environment"), - ) - return Response(serialize(release_threshold, request.user), status=201) - - def get(self, request: Request, project: Project) -> HttpResponse: - release_thresholds = ReleaseThreshold.objects.filter(project=project) - environment_name: str | None = request.GET.get("environment") - - if environment_name: - release_thresholds = release_thresholds.filter(environment__name=environment_name) - return Response(serialize(list(release_thresholds), request.user), status=200) diff --git a/src/sentry/api/endpoints/release_thresholds/release_threshold_details.py b/src/sentry/api/endpoints/release_thresholds/release_threshold_details.py deleted file mode 100644 index c2b1a595a8bf..000000000000 --- a/src/sentry/api/endpoints/release_thresholds/release_threshold_details.py +++ /dev/null @@ -1,103 +0,0 @@ -import logging -from typing import Any, TypedDict - -from django.http import HttpResponse -from rest_framework import serializers -from rest_framework.request import Request -from rest_framework.response import Response - -from sentry.api.api_owners import ApiOwner -from sentry.api.api_publish_status import ApiPublishStatus -from sentry.api.base import cell_silo_endpoint -from sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission -from sentry.api.exceptions import ResourceDoesNotExist -from sentry.api.serializers import serialize -from sentry.api.utils import to_valid_int_id -from sentry.models.project import Project -from sentry.models.release_threshold.constants import ( - THRESHOLD_TYPE_STR_TO_INT, - TRIGGER_TYPE_STRING_TO_INT, - ReleaseThresholdType, -) -from sentry.models.release_threshold.constants import TriggerType as ReleaseThresholdTriggerType -from sentry.models.release_threshold.release_threshold import ReleaseThreshold - - -class ReleaseThresholdPUTData(TypedDict): - threshold_type: int - trigger_type: int - value: int - window_in_seconds: int - - -logger = logging.getLogger("sentry.release_thresholds") - - -class ReleaseThresholdPUTSerializer(serializers.Serializer[ReleaseThresholdPUTData]): - threshold_type = serializers.ChoiceField(choices=ReleaseThresholdType.as_str_choices()) - trigger_type = serializers.ChoiceField(choices=ReleaseThresholdTriggerType.as_str_choices()) - value = serializers.IntegerField(required=True, min_value=0) - window_in_seconds = serializers.IntegerField(required=True, min_value=0) - - def validate_threshold_type(self, threshold_type: str) -> int: - if threshold_type not in THRESHOLD_TYPE_STR_TO_INT: - raise serializers.ValidationError("Invalid threshold type") - return THRESHOLD_TYPE_STR_TO_INT[threshold_type] - - def validate_trigger_type(self, trigger_type: str) -> int: - if trigger_type not in TRIGGER_TYPE_STRING_TO_INT: - raise serializers.ValidationError("Invalid trigger type") - return TRIGGER_TYPE_STRING_TO_INT[trigger_type] - - -@cell_silo_endpoint -class ReleaseThresholdDetailsEndpoint(ProjectEndpoint): - permission_classes = (ProjectReleasePermission,) - owner: ApiOwner = ApiOwner.REPLAY - publish_status = { - "DELETE": ApiPublishStatus.EXPERIMENTAL, - "GET": ApiPublishStatus.EXPERIMENTAL, - "PUT": ApiPublishStatus.EXPERIMENTAL, - } - - def convert_args( - self, - request: Request, - *args: Any, - **kwargs: Any, - ) -> tuple[tuple[Any, ...], dict[str, Any]]: - parsed_args, parsed_kwargs = super().convert_args(request, *args, **kwargs) - validated_id = to_valid_int_id( - "release_threshold", kwargs["release_threshold"], raise_404=True - ) - try: - parsed_kwargs["release_threshold"] = ReleaseThreshold.objects.get( - id=validated_id, - project=parsed_kwargs["project"], - ) - except ReleaseThreshold.DoesNotExist: - raise ResourceDoesNotExist - return parsed_args, parsed_kwargs - - def get( - self, request: Request, project: Project, release_threshold: ReleaseThreshold - ) -> HttpResponse: - return Response(serialize(release_threshold, request.user), status=200) - - def put( - self, request: Request, project: Project, release_threshold: ReleaseThreshold - ) -> HttpResponse: - serializer = ReleaseThresholdPUTSerializer(data=request.data) - - if not serializer.is_valid(): - return Response(serializer.errors, status=400) - - validated_data = serializer.validated_data - release_threshold.update(**validated_data) - return Response(serialize(release_threshold, request.user), status=200) - - def delete( - self, request: Request, project: Project, release_threshold: ReleaseThreshold - ) -> HttpResponse: - release_threshold.delete() - return Response(status=204) diff --git a/src/sentry/api/endpoints/release_thresholds/release_threshold_index.py b/src/sentry/api/endpoints/release_thresholds/release_threshold_index.py deleted file mode 100644 index b6d1827dd233..000000000000 --- a/src/sentry/api/endpoints/release_thresholds/release_threshold_index.py +++ /dev/null @@ -1,72 +0,0 @@ -from typing import TypedDict - -from django.db.models import Q -from django.http import HttpResponse -from rest_framework import serializers -from rest_framework.request import Request -from rest_framework.response import Response - -from sentry.api.api_owners import ApiOwner -from sentry.api.api_publish_status import ApiPublishStatus -from sentry.api.base import cell_silo_endpoint -from sentry.api.bases.organization import OrganizationEndpoint -from sentry.api.helpers.projects import ProjectIdOrSlug, ProjectIdOrSlugField -from sentry.api.paginator import OffsetPaginator -from sentry.api.serializers import serialize -from sentry.constants import ALL_ACCESS_PROJECTS_SLUG -from sentry.models.organization import Organization -from sentry.models.release_threshold.release_threshold import ReleaseThreshold - - -class ReleaseThresholdIndexGETData(TypedDict, total=False): - environment: list[str] - project: list[ProjectIdOrSlug] - - -class ReleaseThresholdIndexGETValidator(serializers.Serializer[ReleaseThresholdIndexGETData]): - environment = serializers.ListField( - required=False, allow_empty=True, child=serializers.CharField() - ) - project = serializers.ListField(required=True, allow_empty=False, child=ProjectIdOrSlugField()) - - def validate_project(self, value: list[ProjectIdOrSlug]) -> list[ProjectIdOrSlug]: - if ALL_ACCESS_PROJECTS_SLUG in value: - raise serializers.ValidationError("Invalid project") - return value - - -@cell_silo_endpoint -class ReleaseThresholdIndexEndpoint(OrganizationEndpoint): - owner: ApiOwner = ApiOwner.REPLAY - publish_status = { - "GET": ApiPublishStatus.EXPERIMENTAL, - } - - def get(self, request: Request, organization: Organization) -> HttpResponse: - validator = ReleaseThresholdIndexGETValidator( - data=self.get_query_params_without_empty_project_params(request), - ) - if not validator.is_valid(): - return Response(validator.errors, status=400) - - environments_list = self.get_environments(request, organization) - projects_list = self.get_projects(request, organization) - - # `projects_list` is already organization-scoped by `get_projects`, so - # `project__in=projects_list` both narrows to the caller's projects and - # prevents cross-tenant reads. An empty list yields zero rows. - release_query = Q(project__in=projects_list) - if environments_list: - release_query &= Q( - environment__in=environments_list, - ) - - queryset = ReleaseThreshold.objects.filter(release_query) - - return self.paginate( - request=request, - queryset=queryset, - order_by="date_added", - paginator_cls=OffsetPaginator, - on_results=lambda x: serialize(x, request.user), - ) diff --git a/src/sentry/api/endpoints/release_thresholds/release_threshold_status_index.py b/src/sentry/api/endpoints/release_thresholds/release_threshold_status_index.py index 32e2a6230da6..68ef56c34845 100644 --- a/src/sentry/api/endpoints/release_thresholds/release_threshold_status_index.py +++ b/src/sentry/api/endpoints/release_thresholds/release_threshold_status_index.py @@ -121,6 +121,7 @@ class ReleaseThresholdStatusIndexEndpoint(OrganizationReleasesBaseEndpoint): @extend_schema( operation_id="listOrganizationReleaseThresholdStatuses", summary="Retrieve Statuses of Release Thresholds (Alpha)", + deprecated=True, parameters=[GlobalParams.ORG_ID_OR_SLUG, ReleaseThresholdStatusIndexSerializer], request=None, responses={ diff --git a/src/sentry/api/urls.py b/src/sentry/api/urls.py index 90ebbfb16a19..a95797cb1e07 100644 --- a/src/sentry/api/urls.py +++ b/src/sentry/api/urls.py @@ -80,13 +80,6 @@ ) from sentry.api.endpoints.project_overview import ProjectOverviewEndpoint from sentry.api.endpoints.project_statistical_detectors import ProjectStatisticalDetectors -from sentry.api.endpoints.release_thresholds.release_threshold import ReleaseThresholdEndpoint -from sentry.api.endpoints.release_thresholds.release_threshold_details import ( - ReleaseThresholdDetailsEndpoint, -) -from sentry.api.endpoints.release_thresholds.release_threshold_index import ( - ReleaseThresholdIndexEndpoint, -) from sentry.api.endpoints.release_thresholds.release_threshold_status_index import ( ReleaseThresholdStatusIndexEndpoint, ) @@ -2345,11 +2338,6 @@ def create_group_urls( OrganizationReleasesEndpoint.as_view(), name="sentry-api-0-organization-releases", ), - re_path( - r"^(?P[^/]+)/release-thresholds/$", - ReleaseThresholdIndexEndpoint.as_view(), - name="sentry-api-0-organization-release-thresholds", - ), # TODO: also integrate release threshold status into the releases response? re_path( r"^(?P[^/]+)/release-threshold-statuses/$", @@ -3219,16 +3207,6 @@ def create_group_urls( ProjectReleasesEndpoint.as_view(), name="sentry-api-0-project-releases", ), - re_path( - r"^(?P[^/]+)/(?P[^/]+)/release-thresholds/$", - ReleaseThresholdEndpoint.as_view(), - name="sentry-api-0-project-release-thresholds", - ), - re_path( - r"^(?P[^/]+)/(?P[^/]+)/release-thresholds/(?P[^/]+)/$", - ReleaseThresholdDetailsEndpoint.as_view(), - name="sentry-api-0-project-release-thresholds-details", - ), re_path( r"^(?P[^/]+)/(?P[^/]+)/commits/$", ProjectCommitsEndpoint.as_view(), diff --git a/src/sentry/conf/api_pagination_allowlist_do_not_modify.py b/src/sentry/conf/api_pagination_allowlist_do_not_modify.py index 16b86b845ad7..066adff85065 100644 --- a/src/sentry/conf/api_pagination_allowlist_do_not_modify.py +++ b/src/sentry/conf/api_pagination_allowlist_do_not_modify.py @@ -77,7 +77,6 @@ "ProjectSymbolSourcesEndpoint", "ProjectTagsEndpoint", "ProjectUsersEndpoint", - "ReleaseThresholdEndpoint", "SentryAppInstallationServiceHookProjectsEndpoint", "SentryAppRequestsEndpoint", "SentryAppWebhookRequestsEndpoint", diff --git a/src/sentry/models/release_threshold/constants.py b/src/sentry/models/release_threshold/constants.py index f9cb8402b7f9..42caa23497f6 100644 --- a/src/sentry/models/release_threshold/constants.py +++ b/src/sentry/models/release_threshold/constants.py @@ -42,18 +42,6 @@ def as_choices(cls) -> tuple[tuple[str, int], ...]: (cls.CRASH_FREE_USER_RATE_STR, cls.CRASH_FREE_USER_RATE), ) - @classmethod - def as_str_choices(cls) -> tuple[tuple[str, str], ...]: - return ( - (cls.TOTAL_ERROR_COUNT_STR, cls.TOTAL_ERROR_COUNT_STR), - (cls.NEW_ISSUE_COUNT_STR, cls.NEW_ISSUE_COUNT_STR), - (cls.UNHANDLED_ISSUE_COUNT_STR, cls.UNHANDLED_ISSUE_COUNT_STR), - (cls.REGRESSED_ISSUE_COUNT_STR, cls.REGRESSED_ISSUE_COUNT_STR), - (cls.FAILURE_RATE_STR, cls.FAILURE_RATE_STR), - (cls.CRASH_FREE_SESSION_RATE_STR, cls.CRASH_FREE_SESSION_RATE_STR), - (cls.CRASH_FREE_USER_RATE_STR, cls.CRASH_FREE_USER_RATE_STR), - ) - class TriggerType: OVER = 0 @@ -69,13 +57,6 @@ def as_choices(cls) -> tuple[tuple[str, int], ...]: # choices for model column (cls.UNDER_STR, cls.UNDER), ) - @classmethod - def as_str_choices(cls) -> tuple[tuple[str, str], ...]: # choices for serializer - return ( - (cls.OVER_STR, cls.OVER_STR), - (cls.UNDER_STR, cls.UNDER_STR), - ) - THRESHOLD_TYPE_INT_TO_STR: dict[int, ThresholdTypeName] = { ReleaseThresholdType.TOTAL_ERROR_COUNT: ReleaseThresholdType.TOTAL_ERROR_COUNT_STR, @@ -87,22 +68,7 @@ def as_str_choices(cls) -> tuple[tuple[str, str], ...]: # choices for serialize ReleaseThresholdType.CRASH_FREE_USER_RATE: ReleaseThresholdType.CRASH_FREE_USER_RATE_STR, } -THRESHOLD_TYPE_STR_TO_INT = { - ReleaseThresholdType.TOTAL_ERROR_COUNT_STR: ReleaseThresholdType.TOTAL_ERROR_COUNT, - ReleaseThresholdType.NEW_ISSUE_COUNT_STR: ReleaseThresholdType.NEW_ISSUE_COUNT, - ReleaseThresholdType.UNHANDLED_ISSUE_COUNT_STR: ReleaseThresholdType.UNHANDLED_ISSUE_COUNT, - ReleaseThresholdType.REGRESSED_ISSUE_COUNT_STR: ReleaseThresholdType.REGRESSED_ISSUE_COUNT, - ReleaseThresholdType.FAILURE_RATE_STR: ReleaseThresholdType.FAILURE_RATE, - ReleaseThresholdType.CRASH_FREE_SESSION_RATE_STR: ReleaseThresholdType.CRASH_FREE_SESSION_RATE, - ReleaseThresholdType.CRASH_FREE_USER_RATE_STR: ReleaseThresholdType.CRASH_FREE_USER_RATE, -} - TRIGGER_TYPE_INT_TO_STR: dict[int, TriggerTypeName] = { TriggerType.OVER: TriggerType.OVER_STR, TriggerType.UNDER: TriggerType.UNDER_STR, } - -TRIGGER_TYPE_STRING_TO_INT = { - TriggerType.OVER_STR: TriggerType.OVER, - TriggerType.UNDER_STR: TriggerType.UNDER, -} diff --git a/src/sentry/web/urls.py b/src/sentry/web/urls.py index 58b0ae207292..f2bff02c1074 100644 --- a/src/sentry/web/urls.py +++ b/src/sentry/web/urls.py @@ -991,11 +991,6 @@ react_page_view, name="releases", ), - re_path( - r"^release-thresholds/", - react_page_view, - name="release-thresholds", - ), # User Feedback re_path( r"^user-feedback/", diff --git a/static/app/utils/api/knownSentryApiUrls.generated.ts b/static/app/utils/api/knownSentryApiUrls.generated.ts index 2899404aaeb9..366c9718770b 100644 --- a/static/app/utils/api/knownSentryApiUrls.generated.ts +++ b/static/app/utils/api/knownSentryApiUrls.generated.ts @@ -337,7 +337,6 @@ export type KnownSentryApiUrls = | '/organizations/$organizationIdOrSlug/recent-searches/' | '/organizations/$organizationIdOrSlug/relay_usage/' | '/organizations/$organizationIdOrSlug/release-threshold-statuses/' - | '/organizations/$organizationIdOrSlug/release-thresholds/' | '/organizations/$organizationIdOrSlug/releases/' | '/organizations/$organizationIdOrSlug/releases/$version/' | '/organizations/$organizationIdOrSlug/releases/$version/assemble/' @@ -530,8 +529,6 @@ export type KnownSentryApiUrls = | '/projects/$organizationIdOrSlug/$projectIdOrSlug/profiling/profiles/$profileId/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/profiling/raw_chunks/$profilerId/$chunkId/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/profiling/raw_profiles/$profileId/' - | '/projects/$organizationIdOrSlug/$projectIdOrSlug/release-thresholds/' - | '/projects/$organizationIdOrSlug/$projectIdOrSlug/release-thresholds/$releaseThreshold/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/releases/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/releases/$version/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/releases/$version/commits/' diff --git a/tests/sentry/api/endpoints/release_thresholds/test_release_threshold.py b/tests/sentry/api/endpoints/release_thresholds/test_release_threshold.py deleted file mode 100644 index 08798bd4f00d..000000000000 --- a/tests/sentry/api/endpoints/release_thresholds/test_release_threshold.py +++ /dev/null @@ -1,237 +0,0 @@ -from django.urls import reverse - -from sentry.models.environment import Environment -from sentry.models.release_threshold.release_threshold import ReleaseThreshold -from sentry.testutils.cases import APITestCase - - -class ReleaseThresholdTest(APITestCase): - def setUp(self) -> None: - super().setUp() - self.user = self.create_user(is_staff=True, is_superuser=True) - - self.canary_environment = Environment.objects.create( - organization_id=self.organization.id, name="canary" - ) - self.production_environment = Environment.objects.create( - organization_id=self.organization.id, name="production" - ) - self.login_as(user=self.user) - - self.url = reverse( - "sentry-api-0-project-release-thresholds", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - }, - ) - - def test_post_missing_params(self) -> None: - response = self.client.post( - self.url, - data={ - "threshold_type": "total_error_count", - "trigger_type": "over", - # value is missing - "window_in_seconds": 1800, - "environment": "canary", - }, - ) - - assert response.status_code == 400 - assert response.data == {"value": ["This field is required."]} - - def test_post_invalid_threshold_type(self) -> None: - response = self.client.post( - self.url, - data={ - "threshold_type": "indiana_jones_and_the_temple_of_doom", - "trigger_type": "over", - "value": 100, - "window_in_seconds": 1800, - "environment": "canary", - }, - ) - - assert response.status_code == 400 - assert response.data["threshold_type"][0].code == "invalid_choice" - - def test_post_invalid_trigger_type(self) -> None: - response = self.client.post( - self.url, - data={ - "threshold_type": "total_error_count", - "trigger_type": "short_round", - "value": 100, - "window_in_seconds": 1800, - "environment": "production", - }, - ) - - assert response.status_code == 400 - assert response.data["trigger_type"][0].code == "invalid_choice" - - def test_post_invalid_project(self) -> None: - url_with_invalid_project = reverse( - "sentry-api-0-project-release-thresholds", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": "Why did it have to be snakes?", - }, - ) - response = self.client.post( - url_with_invalid_project, - data={ - "threshold_type": "total_error_count", - "trigger_type": "over", - "value": 100, - "window_in_seconds": 1800, - "environment": "production", - }, - ) - assert response.status_code == 404 - - def test_post_invalid_environment(self) -> None: - response = self.client.post( - self.url, - data={ - "threshold_type": "total_error_count", - "trigger_type": "over", - "value": 100, - "window_in_seconds": 1800, - "environment": "Sentry belongs in a museum.", - }, - ) - assert response.status_code == 400 - assert response.data["environment"][0].code == "invalid" - - def test_post_valid_no_environment(self) -> None: - response = self.client.post( - self.url, - data={ - "threshold_type": "total_error_count", - "trigger_type": "over", - "value": 100, - "window_in_seconds": 1800, - }, - ) - assert response.status_code == 201 - data = response.data - assert data["threshold_type"] == "total_error_count" - assert data["trigger_type"] == "over" - assert data["value"] == 100 - assert data["window_in_seconds"] == 1800 - assert data["project"]["id"] == str(self.project.id) - assert data["project"]["slug"] == self.project.slug - assert data["project"]["name"] == self.project.name - assert data["environment"] is None - assert data["date_added"] is not None - - def test_post_valid(self) -> None: - response = self.client.post( - self.url, - data={ - "threshold_type": "total_error_count", - "trigger_type": "over", - "value": 100, - "window_in_seconds": 1800, - "environment": "canary", - }, - ) - - assert response.status_code == 201 - data = response.data - assert data["threshold_type"] == "total_error_count" - assert data["trigger_type"] == "over" - assert data["value"] == 100 - assert data["window_in_seconds"] == 1800 - assert data["project"]["id"] == str(self.project.id) - assert data["project"]["slug"] == self.project.slug - assert data["project"]["name"] == self.project.name - assert data["environment"]["id"] == str(self.canary_environment.id) - assert data["environment"]["name"] == self.canary_environment.name - assert data["date_added"] is not None - - def test_get_invalid_project(self) -> None: - url_with_invalid_project = reverse( - "sentry-api-0-project-release-thresholds", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": "Why did it have to be snakes?", - }, - ) - response = self.client.get(url_with_invalid_project, data={"environment": "canary"}) - assert response.status_code == 404 - - def test_get_invalid_environment(self) -> None: - response = self.client.get(self.url, data={"environment": "The Hovitos are near"}) - assert response.status_code == 200 - assert len(response.data) == 0 - - def test_get_valid_no_environment(self) -> None: - response = self.client.get(self.url) - assert response.status_code == 200 - assert len(response.data) == 0 - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - - response = self.client.get(self.url) - assert response.status_code == 200 - assert len(response.data) == 1 - - created_threshold = response.data[0] - - assert created_threshold["threshold_type"] == "total_error_count" - assert created_threshold["trigger_type"] == "over" - assert created_threshold["value"] == 100 - assert created_threshold["window_in_seconds"] == 1800 - assert created_threshold["project"]["id"] == str(self.project.id) - assert created_threshold["project"]["slug"] == self.project.slug - assert created_threshold["project"]["name"] == self.project.name - assert created_threshold["environment"]["id"] == str(self.canary_environment.id) - assert created_threshold["environment"]["name"] == self.canary_environment.name - - def test_get_valid_with_environment(self) -> None: - response = self.client.get(self.url, data={"environment": "canary"}) - assert response.status_code == 200 - assert len(response.data) == 0 - - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=1, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.production_environment, - ) - - response = self.client.get(self.url, data={"environment": "canary"}) - assert response.status_code == 200 - assert len(response.data) == 1 - - created_threshold = response.data[0] - - assert created_threshold["threshold_type"] == "total_error_count" - assert created_threshold["trigger_type"] == "over" - assert created_threshold["value"] == 100 - assert created_threshold["window_in_seconds"] == 1800 - assert created_threshold["project"]["id"] == str(self.project.id) - assert created_threshold["project"]["slug"] == self.project.slug - assert created_threshold["project"]["name"] == self.project.name - assert created_threshold["environment"]["id"] == str(self.canary_environment.id) - assert created_threshold["environment"]["name"] == self.canary_environment.name diff --git a/tests/sentry/api/endpoints/release_thresholds/test_release_threshold_details.py b/tests/sentry/api/endpoints/release_thresholds/test_release_threshold_details.py deleted file mode 100644 index 2147cfb6cf5f..000000000000 --- a/tests/sentry/api/endpoints/release_thresholds/test_release_threshold_details.py +++ /dev/null @@ -1,329 +0,0 @@ -from django.urls import reverse - -from sentry.models.environment import Environment -from sentry.models.release_threshold.constants import THRESHOLD_TYPE_INT_TO_STR -from sentry.models.release_threshold.release_threshold import ReleaseThreshold -from sentry.testutils.cases import APITestCase - - -class ReleaseThresholdDetailsGETTest(APITestCase): - def setUp(self) -> None: - super().setUp() - self.user = self.create_user(is_staff=True, is_superuser=True) - - self.canary_environment = Environment.objects.create( - organization_id=self.organization.id, name="canary" - ) - self.production_environment = Environment.objects.create( - organization_id=self.organization.id, name="production" - ) - self.login_as(user=self.user) - - self.basic_threshold = ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - - def test_invalid_threshold_id(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": 123, - }, - ) - response = self.client.get(url) - - assert response.status_code == 404 - - def test_invalid_project(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": "kingdom_of_the_crystal_skull", - "release_threshold": self.basic_threshold.id, - }, - ) - response = self.client.get(url) - - assert response.status_code == 404 - - def test_valid(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": self.basic_threshold.id, - }, - ) - response = self.client.get(url) - - assert response.status_code == 200 - assert response.data["id"] == str(self.basic_threshold.id) - assert response.data["threshold_type"] == "total_error_count" - assert response.data["trigger_type"] == "over" - assert response.data["value"] == 100 - assert response.data["window_in_seconds"] == 1800 - - -class ReleaseThresholdDetailsDELETETest(APITestCase): - def setUp(self) -> None: - super().setUp() - self.user = self.create_user(is_staff=True, is_superuser=True) - - self.canary_environment = Environment.objects.create( - organization_id=self.organization.id, name="canary" - ) - self.production_environment = Environment.objects.create( - organization_id=self.organization.id, name="production" - ) - self.login_as(user=self.user) - - self.basic_threshold = ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - - def test_invalid_threshold_id(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": 123, - }, - ) - response = self.client.delete(url) - - assert response.status_code == 404 - - def test_invalid_project(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": "kingdom_of_the_crystal_skull", - "release_threshold": self.basic_threshold.id, - }, - ) - response = self.client.delete(url) - - assert response.status_code == 404 - - def test_valid(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": self.basic_threshold.id, - }, - ) - response = self.client.delete(url) - - assert response.status_code == 204 - - -class ReleaseThresholdDetailsPUTTest(APITestCase): - def setUp(self) -> None: - super().setUp() - self.user = self.create_user(is_staff=True, is_superuser=True) - - self.canary_environment = Environment.objects.create( - organization_id=self.organization.id, name="canary" - ) - self.production_environment = Environment.objects.create( - organization_id=self.organization.id, name="production" - ) - self.login_as(user=self.user) - - self.basic_threshold = ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - - def test_invalid_threshold_id(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": 123, - }, - ) - response = self.client.put(url) - - assert response.status_code == 404 - - def test_invalid_missing_data(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": self.basic_threshold.id, - }, - ) - assert self.basic_threshold.environment is not None - data = { - "project": self.basic_threshold.project.id, - "environment": self.basic_threshold.environment.name, - "id": self.basic_threshold.id, - } - response = self.client.put(url, data) - assert response.status_code == 400 - - def test_invalid_trigger_type(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": self.basic_threshold.id, - }, - ) - assert self.basic_threshold.environment is not None - data = { - "project": self.basic_threshold.project.id, - "environment": self.basic_threshold.environment.name, - "id": self.basic_threshold.id, - "trigger_type": "foobar", - "threshold_type": THRESHOLD_TYPE_INT_TO_STR[self.basic_threshold.threshold_type], - "value": 50, - "window_in_seconds": 120, - } - response = self.client.put(url, data) - assert response.status_code == 400 - - def test_invalid_threshold_type(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": self.basic_threshold.id, - }, - ) - assert self.basic_threshold.environment is not None - data = { - "project": self.basic_threshold.project.id, - "environment": self.basic_threshold.environment.name, - "id": self.basic_threshold.id, - "trigger_type": "over", - "threshold_type": "foobar", - "value": 50, - "window_in_seconds": 120, - } - response = self.client.put(url, data) - assert response.status_code == 400 - - def test_invalid_window(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": self.basic_threshold.id, - }, - ) - assert self.basic_threshold.environment is not None - data = { - "project": self.basic_threshold.project.id, - "environment": self.basic_threshold.environment.name, - "id": self.basic_threshold.id, - "trigger_type": "over", - "threshold_type": THRESHOLD_TYPE_INT_TO_STR[self.basic_threshold.threshold_type], - "value": 50, - "window_in_seconds": -120, - } - response = self.client.put(url, data) - assert response.status_code == 400 - - def test_invalid_project(self) -> None: - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": "kingdom_of_the_crystal_skull", - "release_threshold": self.basic_threshold.id, - }, - ) - response = self.client.put(url) - - assert response.status_code == 404 - - def test_valid(self) -> None: - assert self.basic_threshold.environment is not None - updated_data = { - "project": self.basic_threshold.project.id, - "environment": self.basic_threshold.environment.name, - "date_added": self.basic_threshold.date_added, - "id": self.basic_threshold.id, - "trigger_type": "under", - "threshold_type": THRESHOLD_TYPE_INT_TO_STR[self.basic_threshold.threshold_type], - "value": 50, - "window_in_seconds": 120, - } - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": self.basic_threshold.id, - }, - ) - response = self.client.put(url, data=updated_data) - - assert response.status_code == 200 - assert response.data["id"] == str(self.basic_threshold.id) - assert response.data["threshold_type"] == "total_error_count" - assert response.data["trigger_type"] == updated_data["trigger_type"] - assert response.data["value"] == updated_data["value"] - assert response.data["window_in_seconds"] == updated_data["window_in_seconds"] - assert response.data["environment"]["name"] == "canary" - - def test_valid_with_extra_data(self) -> None: - updated_data = { - "project": self.basic_threshold.project.id, - "environment": "foobar", - "date_added": self.basic_threshold.date_added, - "id": self.basic_threshold.id, - "trigger_type": "under", - "threshold_type": THRESHOLD_TYPE_INT_TO_STR[self.basic_threshold.threshold_type], - "value": 50, - "window_in_seconds": 120, - "foo": "bar", - "biz": "baz", - } - url = reverse( - "sentry-api-0-project-release-thresholds-details", - kwargs={ - "organization_id_or_slug": self.organization.slug, - "project_id_or_slug": self.project.slug, - "release_threshold": self.basic_threshold.id, - }, - ) - response = self.client.put(url, data=updated_data) - - assert response.status_code == 200 - assert response.data["id"] == str(self.basic_threshold.id) - assert response.data["threshold_type"] == "total_error_count" - assert response.data["trigger_type"] == updated_data["trigger_type"] - assert response.data["value"] == updated_data["value"] - assert response.data["window_in_seconds"] == updated_data["window_in_seconds"] - assert response.data["environment"]["name"] == "canary" diff --git a/tests/sentry/api/endpoints/release_thresholds/test_release_thresholds_index.py b/tests/sentry/api/endpoints/release_thresholds/test_release_thresholds_index.py deleted file mode 100644 index fa7bcc7e0917..000000000000 --- a/tests/sentry/api/endpoints/release_thresholds/test_release_thresholds_index.py +++ /dev/null @@ -1,175 +0,0 @@ -from sentry.models.environment import Environment -from sentry.models.release_threshold.release_threshold import ReleaseThreshold -from sentry.testutils.cases import APITestCase - - -class ReleaseThresholdTest(APITestCase): - endpoint = "sentry-api-0-organization-release-thresholds" - method = "get" - - def setUp(self) -> None: - super().setUp() - self.user = self.create_user(is_staff=True, is_superuser=True) - self.login_as(user=self.user) - - self.canary_environment = Environment.objects.create( - organization_id=self.organization.id, name="canary" - ) - self.production_environment = Environment.objects.create( - organization_id=self.organization.id, name="production" - ) - - def test_get_invalid_project(self) -> None: - self.get_error_response(self.organization.slug, project="foo bar") - - def test_get_all_projects_slug_is_invalid(self) -> None: - response = self.get_error_response(self.organization.slug, project="$all") - - assert response.status_code == 400 - - def test_get_no_project(self) -> None: - self.get_error_response(self.organization.slug) - - def test_get_valid_project(self) -> None: - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - response = self.get_success_response(self.organization.slug, project=self.project.id) - assert len(response.data) == 1 - - created_threshold = response.data[0] - - assert created_threshold["threshold_type"] == "total_error_count" - assert created_threshold["trigger_type"] == "over" - assert created_threshold["value"] == 100 - assert created_threshold["window_in_seconds"] == 1800 - assert created_threshold["project"]["id"] == str(self.project.id) - assert created_threshold["project"]["slug"] == self.project.slug - assert created_threshold["project"]["name"] == self.project.name - assert created_threshold["environment"]["id"] == str(self.canary_environment.id) - assert created_threshold["environment"]["name"] == self.canary_environment.name - - def test_get_valid_project_slug(self) -> None: - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - - response = self.get_success_response(self.organization.slug, project=self.project.slug) - - assert len(response.data) == 1 - assert response.data[0]["project"]["id"] == str(self.project.id) - - def test_get_invalid_environment(self) -> None: - self.get_error_response(self.organization.slug, environment="foo bar", project="-1") - - def test_get_valid_no_environment(self) -> None: - response = self.get_success_response(self.organization.slug, project="-1") - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - - response = self.get_success_response(self.organization.slug, project=self.project.id) - assert len(response.data) == 1 - - created_threshold = response.data[0] - - assert created_threshold["threshold_type"] == "total_error_count" - assert created_threshold["trigger_type"] == "over" - assert created_threshold["value"] == 100 - assert created_threshold["window_in_seconds"] == 1800 - assert created_threshold["project"]["id"] == str(self.project.id) - assert created_threshold["project"]["slug"] == self.project.slug - assert created_threshold["project"]["name"] == self.project.name - assert created_threshold["environment"]["id"] == str(self.canary_environment.id) - assert created_threshold["environment"]["name"] == self.canary_environment.name - - def test_scoped_to_caller_accessible_projects(self) -> None: - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - - other_org = self.create_organization() - other_project = self.create_project(organization=other_org) - other_environment = Environment.objects.create(organization_id=other_org.id, name="canary") - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=200, - window_in_seconds=1800, - project=other_project, - environment=other_environment, - ) - - # Closed membership so a teamless member has access to zero projects; - # otherwise `allow_joinleave` grants global project access and the - # `projects_list == []` path that triggered the bug is unreachable. - self.organization.flags.allow_joinleave = False - self.organization.save() - - member = self.create_user() - self.create_member(user=member, organization=self.organization, role="member", teams=[]) - self.login_as(user=member) - - response = self.get_success_response(self.organization.slug, project="-1") - assert response.data == [] - - def test_get_valid_with_environment(self) -> None: - response = self.get_success_response( - self.organization.slug, project="-1", environment="canary" - ) - - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=0, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.canary_environment, - ) - - ReleaseThreshold.objects.create( - threshold_type=0, - trigger_type=1, - value=100, - window_in_seconds=1800, - project=self.project, - environment=self.production_environment, - ) - - response = self.get_success_response( - self.organization.slug, project="-1", environment="canary" - ) - assert response.status_code == 200 - assert len(response.data) == 1 - - created_threshold = response.data[0] - - assert created_threshold["threshold_type"] == "total_error_count" - assert created_threshold["trigger_type"] == "over" - assert created_threshold["value"] == 100 - assert created_threshold["window_in_seconds"] == 1800 - assert created_threshold["project"]["id"] == str(self.project.id) - assert created_threshold["project"]["slug"] == self.project.slug - assert created_threshold["project"]["name"] == self.project.name - assert created_threshold["environment"]["id"] == str(self.canary_environment.id) - assert created_threshold["environment"]["name"] == self.canary_environment.name