Skip to content

Commit

Permalink
Revert "ref(uptime): Drop usage of uptime-api-create-update in be (#7…
Browse files Browse the repository at this point in the history
…8149)"

This reverts commit b09c541.

Co-authored-by: wedamija <6288560+wedamija@users.noreply.github.com>
  • Loading branch information
getsentry-bot and wedamija committed Sep 26, 2024
1 parent 422ee35 commit 33d1d77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/sentry/uptime/endpoints/project_uptime_alert_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework.request import Request
from rest_framework.response import Response

from sentry import features
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
Expand Down Expand Up @@ -45,6 +46,10 @@ def post(self, request: Request, project: Project) -> Response:
"""
Create a new monitor.
"""
if not features.has(
"organizations:uptime-api-create-update", project.organization, actor=request.user
):
return Response(status=404)
validator = UptimeMonitorValidator(
data=request.data,
context={
Expand Down
21 changes: 21 additions & 0 deletions tests/sentry/uptime/endpoints/test_project_uptime_alert_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from rest_framework.exceptions import ErrorDetail

from sentry.testutils.helpers import with_feature
from sentry.uptime.endpoints.validators import MAX_REQUEST_SIZE_BYTES
from sentry.uptime.models import ProjectUptimeSubscription, ProjectUptimeSubscriptionMode
from sentry.uptime.subscriptions.subscriptions import DEFAULT_SUBSCRIPTION_TIMEOUT_MS
Expand All @@ -15,6 +16,18 @@ class ProjectUptimeAlertIndexBaseEndpointTest(UptimeAlertBaseEndpointTest):
class ProjectUptimeAlertIndexPostEndpointTest(ProjectUptimeAlertIndexBaseEndpointTest):
method = "post"

def test_no_feature(self):
self.get_error_response(
self.organization.slug,
self.project.slug,
name="test",
owner=f"user:{self.user.id}",
url="http://sentry.io",
interval_seconds=60,
status_code=404,
)

@with_feature("organizations:uptime-api-create-update")
def test(self):
resp = self.get_success_response(
self.organization.slug,
Expand All @@ -36,6 +49,7 @@ def test(self):
assert uptime_subscription.timeout_ms == DEFAULT_SUBSCRIPTION_TIMEOUT_MS
assert uptime_subscription.body is None

@with_feature("organizations:uptime-api-create-update")
def test_no_owner(self):
resp = self.get_success_response(
self.organization.slug,
Expand All @@ -55,6 +69,7 @@ def test_no_owner(self):
assert uptime_subscription.interval_seconds == 60
assert uptime_subscription.timeout_ms == DEFAULT_SUBSCRIPTION_TIMEOUT_MS

@with_feature("organizations:uptime-api-create-update")
def test_mode_no_superadmin(self):
resp = self.get_error_response(
self.organization.slug,
Expand All @@ -70,6 +85,7 @@ def test_mode_no_superadmin(self):
"mode": [ErrorDetail(string="Only superusers can modify `mode`", code="invalid")]
}

@with_feature("organizations:uptime-api-create-update")
def test_mode_superadmin(self):
self.login_as(self.user, superuser=True)
resp = self.get_success_response(
Expand All @@ -91,6 +107,7 @@ def test_mode_superadmin(self):
assert uptime_subscription.interval_seconds == 60
assert uptime_subscription.timeout_ms == DEFAULT_SUBSCRIPTION_TIMEOUT_MS

@with_feature("organizations:uptime-api-create-update")
def test_headers_body_method(self):
resp = self.get_success_response(
self.organization.slug,
Expand All @@ -115,6 +132,7 @@ def test_headers_body_method(self):
assert uptime_subscription.body == '{"key": "value"}'
assert uptime_subscription.headers == [["header", "value"]]

@with_feature("organizations:uptime-api-create-update")
def test_headers_body_method_already_exists(self):
resp = self.get_success_response(
self.organization.slug,
Expand Down Expand Up @@ -159,6 +177,7 @@ def test_headers_body_method_already_exists(self):
newer_uptime_monitor.uptime_subscription_id != new_uptime_monitor.uptime_subscription_id
)

@with_feature("organizations:uptime-api-create-update")
def test_headers_invalid_format(self):
resp = self.get_error_response(
self.organization.slug,
Expand All @@ -176,6 +195,7 @@ def test_headers_invalid_format(self):
"headers": [ErrorDetail(string="Expected array of header tuples.", code="invalid")]
}

@with_feature("organizations:uptime-api-create-update")
def test_size_too_big(self):
resp = self.get_error_response(
self.organization.slug,
Expand All @@ -197,6 +217,7 @@ def test_size_too_big(self):
]
}

@with_feature("organizations:uptime-api-create-update")
def test_over_limit(self):
with mock.patch(
"sentry.uptime.subscriptions.subscriptions.MAX_MANUAL_SUBSCRIPTIONS_PER_ORG", new=1
Expand Down

0 comments on commit 33d1d77

Please sign in to comment.