Fix Swagger schema API endpoint & add a test for it (#3592)

Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>
This commit is contained in:
ghazi-git 2022-02-16 13:25:32 +01:00 committed by GitHub
parent 30c2d91020
commit c22f2c7e9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View File

@ -329,7 +329,7 @@ def remove_drf_starter_files():
)
os.remove(
os.path.join(
"{{cookiecutter.project_slug}}", "users", "tests", "test_swagger_ui.py"
"{{cookiecutter.project_slug}}", "users", "tests", "test_swagger.py"
)
)

View File

@ -333,6 +333,7 @@ REST_FRAMEWORK = {
"rest_framework.authentication.TokenAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}
# django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup

View File

@ -14,3 +14,9 @@ def test_swagger_ui_not_accessible_by_normal_user(client):
url = reverse("api-docs")
response = client.get(url)
assert response.status_code == 403
def test_api_schema_generated_successfully(admin_client):
url = reverse("api-schema")
response = admin_client.get(url)
assert response.status_code == 200