mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from sentry.models.apiapplication import ApiApplication
|
|
from sentry.models.apiauthorization import ApiAuthorization
|
|
from sentry.models.apitoken import ApiToken
|
|
from sentry.testutils.cases import APITestCase
|
|
from sentry.testutils.silo import control_silo_test
|
|
|
|
|
|
class ApiAuthorizationsTest(APITestCase):
|
|
endpoint = "sentry-api-0-api-authorizations"
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.login_as(self.user)
|
|
|
|
|
|
@control_silo_test
|
|
class ApiAuthorizationsListTest(ApiAuthorizationsTest):
|
|
def test_simple(self):
|
|
app = ApiApplication.objects.create(name="test", owner=self.user)
|
|
auth = ApiAuthorization.objects.create(application=app, user=self.user)
|
|
ApiAuthorization.objects.create(
|
|
application=app, user=self.create_user("[email protected]")
|
|
)
|
|
|
|
response = self.get_success_response()
|
|
assert len(response.data) == 1
|
|
assert response.data[0]["id"] == str(auth.id)
|
|
|
|
|
|
@control_silo_test
|
|
class ApiAuthorizationsDeleteTest(ApiAuthorizationsTest):
|
|
method = "delete"
|
|
|
|
def test_simple(self):
|
|
app = ApiApplication.objects.create(name="test", owner=self.user)
|
|
auth = ApiAuthorization.objects.create(application=app, user=self.user)
|
|
token = ApiToken.objects.create(application=app, user=self.user)
|
|
|
|
self.get_success_response(authorization=auth.id, status_code=204)
|
|
assert not ApiAuthorization.objects.filter(id=auth.id).exists()
|
|
assert not ApiToken.objects.filter(id=token.id).exists()
|