From fe5e2aa73080ee6ad781a00803f025b03ddeb4e1 Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Wed, 22 May 2024 16:09:28 -0300 Subject: [PATCH] Drop checks of Django versions that reached end of life --- example_app/urls.py | 51 +++++++++++++++++++----------------------- tests/test_generics.py | 15 +++++-------- tests/test_mixins.py | 15 +++++-------- tests/test_viewsets.py | 15 +++++-------- 4 files changed, 38 insertions(+), 58 deletions(-) diff --git a/example_app/urls.py b/example_app/urls.py index d16d38e..1874d80 100644 --- a/example_app/urls.py +++ b/example_app/urls.py @@ -1,57 +1,52 @@ # -*- coding: utf-8 -*- -from django.utils import version as django_version +from django.urls import path, re_path + from rest_framework.urlpatterns import format_suffix_patterns -from .views import ( - OrderListCreateEndpoint, OrderRetrieveUpdateDestroyEndpoint, - OrderRetrieveUpdateEndpoint, OrderCreateWithGenericEndpoint, - OrderListWithGenericEndpoint, OrderRetrieveWithGenericEndpoint, - OrderUpdateWithGenericEndpoint, OrderCreateWithMixinEndpoint, - OrderUpdateWithMixinEndpoint, OrderListWithoutReadSerializerEndpoint, - OrderListWithMixinEndpoint, OrderRetrieveWithMixinEndpoint, - OrderViewset) -if django_version.get_complete_version() < (2, 0, 0): - from django.conf.urls import url -else: - from django.urls import re_path as url +from .views import ( + OrderCreateWithGenericEndpoint, OrderCreateWithMixinEndpoint, OrderListCreateEndpoint, OrderListWithGenericEndpoint, + OrderListWithMixinEndpoint, OrderListWithoutReadSerializerEndpoint, OrderRetrieveUpdateDestroyEndpoint, + OrderRetrieveUpdateEndpoint, OrderRetrieveWithGenericEndpoint, OrderRetrieveWithMixinEndpoint, + OrderUpdateWithGenericEndpoint, OrderUpdateWithMixinEndpoint, OrderViewset +) urlpatterns = [ - url(r'^orders-list-without-read-serializer/$', + path('orders-list-without-read-serializer/', OrderListWithoutReadSerializerEndpoint.as_view(), name='list_without_read_serializer'), - url(r'^orders/$', OrderListCreateEndpoint.as_view(), name='list_create'), - url(r'^orders/(?P[0-9]+)$', OrderRetrieveUpdateDestroyEndpoint.as_view(), + path('orders/', OrderListCreateEndpoint.as_view(), name='list_create'), + re_path(r'^orders/(?P[0-9]+)$', OrderRetrieveUpdateDestroyEndpoint.as_view(), name='retrieve_update_destroy'), - url(r'^orders-retrieve-update/(?P[0-9]+)$', OrderRetrieveUpdateEndpoint.as_view(), + re_path(r'^orders-retrieve-update/(?P[0-9]+)$', OrderRetrieveUpdateEndpoint.as_view(), name='retrieve_update'), - url(r'^orders-list-generic-view/$', OrderListWithGenericEndpoint.as_view(), + path('orders-list-generic-view/', OrderListWithGenericEndpoint.as_view(), name='list'), - url(r'^orders-retrieve-generic-view/(?P[0-9]+)$', + re_path(r'^orders-retrieve-generic-view/(?P[0-9]+)$', OrderRetrieveWithGenericEndpoint.as_view(), name='retrieve'), - url(r'^orders-create-generic-view/$', OrderCreateWithGenericEndpoint.as_view(), + path('orders-create-generic-view/', OrderCreateWithGenericEndpoint.as_view(), name='create'), - url(r'^orders-update-generic-view/(?P[0-9]+)$', OrderUpdateWithGenericEndpoint.as_view(), + re_path(r'^orders-update-generic-view/(?P[0-9]+)$', OrderUpdateWithGenericEndpoint.as_view(), name='update'), - url(r'^orders-list-mixin/$', OrderListWithMixinEndpoint.as_view(), + path('orders-list-mixin/', OrderListWithMixinEndpoint.as_view(), name='list_mixin'), - url(r'^orders-retrieve-mixin/(?P[0-9]+)$', OrderRetrieveWithMixinEndpoint.as_view(), + re_path(r'^orders-retrieve-mixin/(?P[0-9]+)$', OrderRetrieveWithMixinEndpoint.as_view(), name='retrieve_mixin'), - url(r'^orders-create-mixin/$', OrderCreateWithMixinEndpoint.as_view(), + path('orders-create-mixin/', OrderCreateWithMixinEndpoint.as_view(), name='create_mixin'), - url(r'^orders-update-mixin/(?P[0-9]+)$', OrderUpdateWithMixinEndpoint.as_view(), + re_path(r'^orders-update-mixin/(?P[0-9]+)$', OrderUpdateWithMixinEndpoint.as_view(), name='update_mixin'), - url(r'^orders-viewset/$', + path('orders-viewset/', OrderViewset.as_view({ 'get': 'list', 'post': 'create', }), name='viewset_list_create'), - url(r'^orders-viewset/(?P[0-9]+)$', + re_path(r'^orders-viewset/(?P[0-9]+)$', OrderViewset.as_view({ 'get': 'retrieve', 'put': 'update', @@ -61,4 +56,4 @@ name='viewset_retrieve_update_destroy'), ] -urlpatterns = format_suffix_patterns(urlpatterns) +urlpatterns = format_suffix_patterns(urlpatterns) \ No newline at end of file diff --git a/tests/test_generics.py b/tests/test_generics.py index 3347821..984a7cf 100644 --- a/tests/test_generics.py +++ b/tests/test_generics.py @@ -6,19 +6,14 @@ from __future__ import absolute_import, unicode_literals -from django.utils import version as django_version +from django.urls import reverse + from model_bakery import baker -from test_utils.base_tests import ( - BaseTestCase, TestListRequestSuccess, TestRetrieveRequestSuccess, - TestCreateRequestSuccess, TestUpdateRequestSuccess) from example_app.serializers import OrderCreateSerializer, OrderListSerializer - - -if django_version.get_complete_version() < (2, 0, 0): - from django.core.urlresolvers import reverse # pylint: disable=no-name-in-module,import-error -else: - from django.urls import reverse # pylint: disable=no-name-in-module,import-error +from test_utils.base_tests import ( + BaseTestCase, TestCreateRequestSuccess, TestListRequestSuccess, TestRetrieveRequestSuccess, TestUpdateRequestSuccess +) class OrderListCreateEndpointTests( diff --git a/tests/test_mixins.py b/tests/test_mixins.py index eebb0f5..321d0a2 100644 --- a/tests/test_mixins.py +++ b/tests/test_mixins.py @@ -6,19 +6,14 @@ from __future__ import absolute_import, unicode_literals -from django.utils import version as django_version +from django.urls import reverse + from model_bakery import baker -from test_utils.base_tests import ( - BaseTestCase, TestListRequestSuccess, TestRetrieveRequestSuccess, - TestCreateRequestSuccess, TestUpdateRequestSuccess) from example_app.serializers import OrderCreateSerializer, OrderListSerializer - - -if django_version.get_complete_version() < (2, 0, 0): - from django.core.urlresolvers import reverse # pylint: disable=no-name-in-module,import-error -else: - from django.urls import reverse # pylint: disable=no-name-in-module,import-error +from test_utils.base_tests import ( + BaseTestCase, TestCreateRequestSuccess, TestListRequestSuccess, TestRetrieveRequestSuccess, TestUpdateRequestSuccess +) class OrderCreateWithMixinEndpointTests(BaseTestCase, TestCreateRequestSuccess): diff --git a/tests/test_viewsets.py b/tests/test_viewsets.py index 5a1d661..dfcc922 100644 --- a/tests/test_viewsets.py +++ b/tests/test_viewsets.py @@ -6,19 +6,14 @@ from __future__ import absolute_import, unicode_literals -from django.utils import version as django_version +from django.urls import reverse + from model_bakery import baker -from test_utils.base_tests import ( - BaseTestCase, TestListRequestSuccess, TestRetrieveRequestSuccess, - TestCreateRequestSuccess, TestUpdateRequestSuccess) from example_app.serializers import OrderCreateSerializer, OrderListSerializer - - -if django_version.get_complete_version() < (2, 0, 0): - from django.core.urlresolvers import reverse # pylint: disable=no-name-in-module,import-error -else: - from django.urls import reverse # pylint: disable=no-name-in-module,import-error +from test_utils.base_tests import ( + BaseTestCase, TestCreateRequestSuccess, TestListRequestSuccess, TestRetrieveRequestSuccess, TestUpdateRequestSuccess +) class OrderViewsetListCreateTests(