-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(releases): Implement threshold details GET
- Loading branch information
1 parent
41e8adc
commit 18e4043
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 region_silo_endpoint | ||
from sentry.api.bases.project import ProjectEndpoint | ||
from sentry.api.serializers import serialize | ||
from sentry.api.serializers.rest_framework.project import ProjectField | ||
from sentry.models import Project | ||
from sentry.models.release_threshold.releasethreshold import ReleaseThreshold | ||
|
||
|
||
class ReleaseThresholdDetailsGETSerializer(serializers.Serializer): | ||
threshold_id = serializers.CharField() | ||
project = ProjectField() | ||
|
||
|
||
@region_silo_endpoint | ||
class ReleaseThresholdDetailsEndpoint(ProjectEndpoint): | ||
owner: ApiOwner = ApiOwner.ENTERPRISE | ||
publish_status = { | ||
"GET": ApiPublishStatus.PRIVATE, | ||
} | ||
|
||
def get(self, request: Request, project: Project, threshold_id: str) -> HttpResponse: | ||
request.data["project"] = project.slug | ||
request.data["threshold_id"] = threshold_id | ||
serializer = ReleaseThresholdDetailsGETSerializer( | ||
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 | ||
try: | ||
release_threshold = ReleaseThreshold.objects.get( | ||
id=result.get("threshold_id"), | ||
project=project, | ||
) | ||
return Response(serialize(release_threshold, request.user), status=200) | ||
except ReleaseThreshold.DoesNotExist: | ||
return Response(status=404) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/sentry/api/endpoints/test_release_threshold_details.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from django.urls import reverse | ||
|
||
from sentry.models.environment import Environment | ||
from sentry.models.release_threshold.releasethreshold import ReleaseThreshold | ||
from sentry.testutils.cases import APITestCase | ||
|
||
|
||
class ReleaseThresholdDetailsTest(APITestCase): | ||
def setUp(self): | ||
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): | ||
url = reverse( | ||
"sentry-api-0-project-release-thresholds-details", | ||
kwargs={ | ||
"organization_slug": self.organization.slug, | ||
"project_slug": self.project.slug, | ||
"threshold_id": 123, | ||
}, | ||
) | ||
response = self.client.get(url) | ||
|
||
assert response.status_code == 404 | ||
|
||
def test_invalid_project(self): | ||
url = reverse( | ||
"sentry-api-0-project-release-thresholds-details", | ||
kwargs={ | ||
"organization_slug": self.organization.slug, | ||
"project_slug": "kingdom_of_the_crystal_skull", | ||
"threshold_id": self.basic_threshold.id, | ||
}, | ||
) | ||
response = self.client.get(url) | ||
|
||
assert response.status_code == 404 | ||
|
||
def test_valid(self): | ||
url = reverse( | ||
"sentry-api-0-project-release-thresholds-details", | ||
kwargs={ | ||
"organization_slug": self.organization.slug, | ||
"project_slug": self.project.slug, | ||
"threshold_id": 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"] == "percent_over" | ||
assert response.data["value"] == 100 | ||
assert response.data["window_in_seconds"] == 1800 | ||
assert response.data["environment"]["name"] == "canary" |