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:
sonny 2020-03-02 20:14:38 +01:00
parent acd9bd30cb
commit a87d4f387f
8 changed files with 18 additions and 52 deletions

View file

@ -7,7 +7,7 @@ django-axes==5.2.2
Django==2.2
django-celery-beat==1.5.0
djangorestframework==3.9.4
django-rest-swagger==2.2.0
drf-yasg==1.17.1
django-registration-redux==2.6
lxml==4.4.2
feedparser==5.2.1

View file

@ -27,7 +27,7 @@ INSTALLED_APPS = [
"django.contrib.staticfiles",
# third party apps
"rest_framework",
"rest_framework_swagger",
"drf_yasg",
"celery",
"django_celery_beat",
"registration",

View file

@ -2,7 +2,6 @@ from rest_framework import status
from rest_framework.generics import (
GenericAPIView,
ListAPIView,
ListCreateAPIView,
RetrieveUpdateDestroyAPIView,
get_object_or_404,
)
@ -17,7 +16,7 @@ from newsreader.news.core.models import Post
from newsreader.news.core.serializers import PostSerializer
class ListRuleView(ListCreateAPIView):
class ListRuleView(ListAPIView):
queryset = CollectionRule.objects.all()
serializer_class = RuleSerializer
pagination_class = ResultSetPagination

View file

@ -94,13 +94,9 @@ class RuleListViewTestCase(TestCase):
content_type="application/json",
)
data = response.json()
data["category"]
self.assertEquals(response.status_code, 201)
self.assertEquals(data["name"], "BBC")
self.assertEquals(data["url"], "https://www.bbc.co.uk")
self.assertEquals(data["category"], category.pk)
self.assertEquals(response.status_code, 405)
self.assertEquals(data["detail"], 'Method "POST" not allowed.')
def test_patch(self):
response = self.client.patch(reverse("api:rules-list"))

View file

@ -44,7 +44,7 @@ class DetailPostView(RetrieveUpdateAPIView):
permission_classes = (IsAuthenticated, IsPostOwner)
class ListCategoryView(ListCreateAPIView):
class ListCategoryView(ListAPIView):
queryset = Category.objects.all()
serializer_class = CategorySerializer

View file

@ -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",
)

View file

@ -74,8 +74,8 @@ class CategoryListViewTestCase(TestCase):
)
response_data = response.json()
self.assertEquals(response.status_code, 201)
self.assertEquals(response_data["name"], "Tech")
self.assertEquals(response.status_code, 405)
self.assertEquals(response_data["detail"], 'Method "POST" not allowed.')
def test_patch(self):
response = self.client.patch(reverse("api:categories-list"))

View file

@ -2,7 +2,8 @@ from django.conf import settings
from django.contrib import admin
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.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
schema_view = get_swagger_view(title="Newsreader API")
endpoints = [
path("", schema_view, name="schema-view"),
*collection_endpoints,
*core_endpoints,
apipatterns = [
path("api/", include(core_endpoints)),
path("api/", include(collection_endpoints)),
]
schema_info = openapi.Info(title="Newsreader API", default_version="v1")
schema_view = get_schema_view(schema_info, patterns=apipatterns)
urlpatterns = [
path("", include(core_patterns)),
path("", include(collection_patterns)),
path("", include((apipatterns, "api")), name="api"),
path("accounts/", include((login_urls, "accounts")), name="accounts"),
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"),
]