mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-19 03:14:52 +03:00
Merge branch 'cookiecutter:master' into master
This commit is contained in:
commit
5c384a5581
5
.github/contributors.json
vendored
5
.github/contributors.json
vendored
|
@ -1217,5 +1217,10 @@
|
||||||
"name": "Pedro Campos",
|
"name": "Pedro Campos",
|
||||||
"github_login": "pcampos119104",
|
"github_login": "pcampos119104",
|
||||||
"twitter_username": ""
|
"twitter_username": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Vikas Yadav",
|
||||||
|
"github_login": "vik-y",
|
||||||
|
"twitter_username": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -1636,6 +1636,13 @@ Listed in alphabetical order.
|
||||||
</td>
|
</td>
|
||||||
<td>highcenburg</td>
|
<td>highcenburg</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Vikas Yadav</td>
|
||||||
|
<td>
|
||||||
|
<a href="https://github.com/vik-y">vik-y</a>
|
||||||
|
</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Vitaly Babiy</td>
|
<td>Vitaly Babiy</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -391,6 +391,11 @@ def remove_drf_starter_files():
|
||||||
"{{cookiecutter.project_slug}}", "users", "tests", "test_drf_views.py"
|
"{{cookiecutter.project_slug}}", "users", "tests", "test_drf_views.py"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
os.remove(
|
||||||
|
os.path.join(
|
||||||
|
"{{cookiecutter.project_slug}}", "users", "tests", "test_swagger_ui.py"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def remove_storages_module():
|
def remove_storages_module():
|
||||||
|
|
|
@ -8,7 +8,7 @@ black==21.12b0
|
||||||
isort==5.10.1
|
isort==5.10.1
|
||||||
flake8==4.0.1
|
flake8==4.0.1
|
||||||
flake8-isort==4.1.1
|
flake8-isort==4.1.1
|
||||||
pre-commit==2.16.0
|
pre-commit==2.17.0
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -90,6 +90,7 @@ THIRD_PARTY_APPS = [
|
||||||
"rest_framework",
|
"rest_framework",
|
||||||
"rest_framework.authtoken",
|
"rest_framework.authtoken",
|
||||||
"corsheaders",
|
"corsheaders",
|
||||||
|
"drf_spectacular",
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -340,6 +341,18 @@ REST_FRAMEWORK = {
|
||||||
# django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup
|
# django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup
|
||||||
CORS_URLS_REGEX = r"^/api/.*$"
|
CORS_URLS_REGEX = r"^/api/.*$"
|
||||||
|
|
||||||
|
# By Default swagger ui is available only to admin user. You can change permission classs to change that
|
||||||
|
# See more configuration options at https://drf-spectacular.readthedocs.io/en/latest/settings.html#settings
|
||||||
|
SPECTACULAR_SETTINGS = {
|
||||||
|
"TITLE": "{{ cookiecutter.project_name }} API",
|
||||||
|
"DESCRIPTION": "Documentation of API endpoiints of {{ cookiecutter.project_name }}",
|
||||||
|
"VERSION": "1.0.0",
|
||||||
|
"SERVE_PERMISSIONS": ["rest_framework.permissions.IsAdminUser"],
|
||||||
|
"SERVERS": [
|
||||||
|
{"url": "https://127.0.0.1:8000", "description": "Local Development server"},
|
||||||
|
{"url": "https://{{ cookiecutter.domain_name }}", "description": "Production server"},
|
||||||
|
],
|
||||||
|
}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
# Your stuff...
|
# Your stuff...
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -8,6 +8,7 @@ from django.urls import include, path
|
||||||
from django.views import defaults as default_views
|
from django.views import defaults as default_views
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
{%- if cookiecutter.use_drf == 'y' %}
|
{%- if cookiecutter.use_drf == 'y' %}
|
||||||
|
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
|
||||||
from rest_framework.authtoken.views import obtain_auth_token
|
from rest_framework.authtoken.views import obtain_auth_token
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
@ -35,6 +36,12 @@ urlpatterns += [
|
||||||
path("api/", include("config.api_router")),
|
path("api/", include("config.api_router")),
|
||||||
# DRF auth token
|
# DRF auth token
|
||||||
path("auth-token/", obtain_auth_token),
|
path("auth-token/", obtain_auth_token),
|
||||||
|
path("api/schema/", SpectacularAPIView.as_view(), name="api-schema"),
|
||||||
|
path(
|
||||||
|
"api/docs/",
|
||||||
|
SpectacularSwaggerView.as_view(url_name="api-schema"),
|
||||||
|
name="api-docs",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
|
|
@ -43,4 +43,6 @@ django-redis==5.2.0 # https://github.com/jazzband/django-redis
|
||||||
# Django REST Framework
|
# Django REST Framework
|
||||||
djangorestframework==3.13.1 # https://github.com/encode/django-rest-framework
|
djangorestframework==3.13.1 # https://github.com/encode/django-rest-framework
|
||||||
django-cors-headers==3.11.0 # https://github.com/adamchainz/django-cors-headers
|
django-cors-headers==3.11.0 # https://github.com/adamchainz/django-cors-headers
|
||||||
|
# DRF-spectacular for api documentation
|
||||||
|
drf-spectacular==0.21.1
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
|
@ -41,7 +41,7 @@ pylint-django==2.5.0 # https://github.com/PyCQA/pylint-django
|
||||||
{%- if cookiecutter.use_celery == 'y' %}
|
{%- if cookiecutter.use_celery == 'y' %}
|
||||||
pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery
|
pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
pre-commit==2.16.0 # https://github.com/pre-commit/pre-commit
|
pre-commit==2.17.0 # https://github.com/pre-commit/pre-commit
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import pytest
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
|
|
||||||
|
def test_swagger_accessible_by_admin(admin_client):
|
||||||
|
url = reverse("api-docs")
|
||||||
|
response = admin_client.get(url)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_swagger_ui_not_accessible_by_normal_user(client):
|
||||||
|
url = reverse("api-docs")
|
||||||
|
response = client.get(url)
|
||||||
|
assert response.status_code == 403
|
Loading…
Reference in New Issue
Block a user