Replace rest_framework_swagger with drf_yasg
rest_framework is deprecated see https://github.com/marcgibbons/django-rest-swagger#django-rest-swagger-deprecated-2019-06-04
This commit is contained in:
parent
acd9bd30cb
commit
a87d4f387f
8 changed files with 18 additions and 52 deletions
|
|
@ -7,7 +7,7 @@ django-axes==5.2.2
|
||||||
Django==2.2
|
Django==2.2
|
||||||
django-celery-beat==1.5.0
|
django-celery-beat==1.5.0
|
||||||
djangorestframework==3.9.4
|
djangorestframework==3.9.4
|
||||||
django-rest-swagger==2.2.0
|
drf-yasg==1.17.1
|
||||||
django-registration-redux==2.6
|
django-registration-redux==2.6
|
||||||
lxml==4.4.2
|
lxml==4.4.2
|
||||||
feedparser==5.2.1
|
feedparser==5.2.1
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ INSTALLED_APPS = [
|
||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
# third party apps
|
# third party apps
|
||||||
"rest_framework",
|
"rest_framework",
|
||||||
"rest_framework_swagger",
|
"drf_yasg",
|
||||||
"celery",
|
"celery",
|
||||||
"django_celery_beat",
|
"django_celery_beat",
|
||||||
"registration",
|
"registration",
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ from rest_framework import status
|
||||||
from rest_framework.generics import (
|
from rest_framework.generics import (
|
||||||
GenericAPIView,
|
GenericAPIView,
|
||||||
ListAPIView,
|
ListAPIView,
|
||||||
ListCreateAPIView,
|
|
||||||
RetrieveUpdateDestroyAPIView,
|
RetrieveUpdateDestroyAPIView,
|
||||||
get_object_or_404,
|
get_object_or_404,
|
||||||
)
|
)
|
||||||
|
|
@ -17,7 +16,7 @@ from newsreader.news.core.models import Post
|
||||||
from newsreader.news.core.serializers import PostSerializer
|
from newsreader.news.core.serializers import PostSerializer
|
||||||
|
|
||||||
|
|
||||||
class ListRuleView(ListCreateAPIView):
|
class ListRuleView(ListAPIView):
|
||||||
queryset = CollectionRule.objects.all()
|
queryset = CollectionRule.objects.all()
|
||||||
serializer_class = RuleSerializer
|
serializer_class = RuleSerializer
|
||||||
pagination_class = ResultSetPagination
|
pagination_class = ResultSetPagination
|
||||||
|
|
|
||||||
|
|
@ -94,13 +94,9 @@ class RuleListViewTestCase(TestCase):
|
||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
)
|
)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
data["category"]
|
|
||||||
|
|
||||||
self.assertEquals(response.status_code, 201)
|
self.assertEquals(response.status_code, 405)
|
||||||
|
self.assertEquals(data["detail"], 'Method "POST" not allowed.')
|
||||||
self.assertEquals(data["name"], "BBC")
|
|
||||||
self.assertEquals(data["url"], "https://www.bbc.co.uk")
|
|
||||||
self.assertEquals(data["category"], category.pk)
|
|
||||||
|
|
||||||
def test_patch(self):
|
def test_patch(self):
|
||||||
response = self.client.patch(reverse("api:rules-list"))
|
response = self.client.patch(reverse("api:rules-list"))
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class DetailPostView(RetrieveUpdateAPIView):
|
||||||
permission_classes = (IsAuthenticated, IsPostOwner)
|
permission_classes = (IsAuthenticated, IsPostOwner)
|
||||||
|
|
||||||
|
|
||||||
class ListCategoryView(ListCreateAPIView):
|
class ListCategoryView(ListAPIView):
|
||||||
queryset = Category.objects.all()
|
queryset = Category.objects.all()
|
||||||
serializer_class = CategorySerializer
|
serializer_class = CategorySerializer
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
from newsreadern.news.collection.serializers import RuleSerializer
|
|
||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
from newsreader.news.posts.models import Category, Post
|
|
||||||
|
|
||||||
|
|
||||||
class CategorySerializer(serializers.ModelSerializer):
|
|
||||||
rules = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
def get_rules(self, instance):
|
|
||||||
rules = instance.rules.order_by("-modified", "-created")
|
|
||||||
serializer = RuleSerializer(rules, many=True)
|
|
||||||
return serializer.data
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Category
|
|
||||||
fields = ("id", "name", "rules")
|
|
||||||
|
|
||||||
|
|
||||||
class PostSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Post
|
|
||||||
fields = (
|
|
||||||
"id",
|
|
||||||
"title",
|
|
||||||
"body",
|
|
||||||
"author",
|
|
||||||
"publication_date",
|
|
||||||
"url",
|
|
||||||
"rule",
|
|
||||||
"remote_identifier",
|
|
||||||
)
|
|
||||||
|
|
@ -74,8 +74,8 @@ class CategoryListViewTestCase(TestCase):
|
||||||
)
|
)
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
|
|
||||||
self.assertEquals(response.status_code, 201)
|
self.assertEquals(response.status_code, 405)
|
||||||
self.assertEquals(response_data["name"], "Tech")
|
self.assertEquals(response_data["detail"], 'Method "POST" not allowed.')
|
||||||
|
|
||||||
def test_patch(self):
|
def test_patch(self):
|
||||||
response = self.client.patch(reverse("api:categories-list"))
|
response = self.client.patch(reverse("api:categories-list"))
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ from django.conf import settings
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
|
|
||||||
from rest_framework_swagger.views import get_swagger_view
|
from drf_yasg import openapi
|
||||||
|
from drf_yasg.views import get_schema_view
|
||||||
|
|
||||||
from newsreader.accounts.urls import urlpatterns as login_urls
|
from newsreader.accounts.urls import urlpatterns as login_urls
|
||||||
from newsreader.news.collection.urls import endpoints as collection_endpoints
|
from newsreader.news.collection.urls import endpoints as collection_endpoints
|
||||||
|
|
@ -11,19 +12,21 @@ from newsreader.news.core.urls import endpoints as core_endpoints
|
||||||
from newsreader.news.core.urls import urlpatterns as core_patterns
|
from newsreader.news.core.urls import urlpatterns as core_patterns
|
||||||
|
|
||||||
|
|
||||||
schema_view = get_swagger_view(title="Newsreader API")
|
apipatterns = [
|
||||||
endpoints = [
|
path("api/", include(core_endpoints)),
|
||||||
path("", schema_view, name="schema-view"),
|
path("api/", include(collection_endpoints)),
|
||||||
*collection_endpoints,
|
|
||||||
*core_endpoints,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
schema_info = openapi.Info(title="Newsreader API", default_version="v1")
|
||||||
|
schema_view = get_schema_view(schema_info, patterns=apipatterns)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", include(core_patterns)),
|
path("", include(core_patterns)),
|
||||||
path("", include(collection_patterns)),
|
path("", include(collection_patterns)),
|
||||||
|
path("", include((apipatterns, "api")), name="api"),
|
||||||
path("accounts/", include((login_urls, "accounts")), name="accounts"),
|
path("accounts/", include((login_urls, "accounts")), name="accounts"),
|
||||||
path("admin/", admin.site.urls, name="admin"),
|
path("admin/", admin.site.urls, name="admin"),
|
||||||
path("api/", include((endpoints, "api")), name="api"),
|
path("api/", schema_view.with_ui("swagger"), name="api"),
|
||||||
path("api/auth/", include("rest_framework.urls"), name="rest_framework"),
|
path("api/auth/", include("rest_framework.urls"), name="rest_framework"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue