Skip to content

Commit 21304d9

Browse files
committed
add a test for the expected response of a schema protected with admin permissions
1 parent 4da66b5 commit 21304d9

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

tests/test_openapi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ def test_schema_generated(api_client):
630630
assert response.status_code == 200
631631

632632

633+
def test_protected_schema_response(api_client):
634+
response = api_client.get("/protected-schema/")
635+
assert response.status_code == 403
636+
637+
633638
@extend_schema_serializer(
634639
examples=[
635640
OpenApiExample(

tests/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.urls import path
22
from drf_spectacular.views import SpectacularAPIView
3+
from rest_framework.permissions import IsAdminUser
34

45
from .views import (
56
AuthErrorView,
@@ -18,4 +19,8 @@
1819
path("rate-limit-error/", RateLimitErrorView.as_view()),
1920
path("recursion-error/", RecursionView.as_view()),
2021
path("schema/", SpectacularAPIView.as_view(), name="api-schema"),
22+
path(
23+
"protected-schema/",
24+
SpectacularAPIView.as_view(permission_classes=[IsAdminUser]),
25+
),
2126
]

0 commit comments

Comments
 (0)