mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-21 17:16:47 +03:00
Replace all url() calls with path() or re_path() (#7512)
* url() is deprecated in Django 3.1 * update given feedbacks on url() is deprecated in Django 3.1 * Fix test_urlpatterns.py to continue testing mixed re_path() and path() * Fix one missed reference Co-authored-by: sanjusci <sanju.sci9@gmail.com>
This commit is contained in:
parent
9990b59281
commit
410575dace
|
@ -199,7 +199,7 @@ When using `TokenAuthentication`, you may want to provide a mechanism for client
|
||||||
|
|
||||||
from rest_framework.authtoken import views
|
from rest_framework.authtoken import views
|
||||||
urlpatterns += [
|
urlpatterns += [
|
||||||
url(r'^api-token-auth/', views.obtain_auth_token)
|
path('api-token-auth/', views.obtain_auth_token)
|
||||||
]
|
]
|
||||||
|
|
||||||
Note that the URL part of the pattern can be whatever you want to use.
|
Note that the URL part of the pattern can be whatever you want to use.
|
||||||
|
@ -238,7 +238,7 @@ For example, you may return additional user information beyond the `token` value
|
||||||
And in your `urls.py`:
|
And in your `urls.py`:
|
||||||
|
|
||||||
urlpatterns += [
|
urlpatterns += [
|
||||||
url(r'^api-token-auth/', CustomAuthToken.as_view())
|
path('api-token-auth/', CustomAuthToken.as_view())
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ Another style of filtering might involve restricting the queryset based on some
|
||||||
|
|
||||||
For example if your URL config contained an entry like this:
|
For example if your URL config contained an entry like this:
|
||||||
|
|
||||||
url('^purchases/(?P<username>.+)/$', PurchaseList.as_view()),
|
re_path('^purchases/(?P<username>.+)/$', PurchaseList.as_view()),
|
||||||
|
|
||||||
You could then write a view that returned a purchase queryset filtered by the username portion of the URL:
|
You could then write a view that returned a purchase queryset filtered by the username portion of the URL:
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,9 @@ Example:
|
||||||
from blog import views
|
from blog import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^/$', views.apt_root),
|
path('', views.apt_root),
|
||||||
url(r'^comments/$', views.comment_list),
|
path('comments/', views.comment_list),
|
||||||
url(r'^comments/(?P<pk>[0-9]+)/$', views.comment_detail)
|
path('comments/<int:pk>/', views.comment_detail)
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html'])
|
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html'])
|
||||||
|
|
|
@ -45,7 +45,7 @@ For more complex cases you might also want to override various methods on the vi
|
||||||
|
|
||||||
For very simple cases you might want to pass through any class attributes using the `.as_view()` method. For example, your URLconf might include something like the following entry:
|
For very simple cases you might want to pass through any class attributes using the `.as_view()` method. For example, your URLconf might include something like the following entry:
|
||||||
|
|
||||||
url(r'^/users/', ListCreateAPIView.as_view(queryset=User.objects.all(), serializer_class=UserSerializer), name='user-list')
|
path('users/', ListCreateAPIView.as_view(queryset=User.objects.all(), serializer_class=UserSerializer), name='user-list')
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ If it is called without a `filename` URL keyword argument, then the client must
|
||||||
# urls.py
|
# urls.py
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# ...
|
# ...
|
||||||
url(r'^upload/(?P<filename>[^/]+)$', FileUploadView.as_view())
|
re_path(r'^upload/(?P<filename>[^/]+)$', FileUploadView.as_view())
|
||||||
]
|
]
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
@ -63,7 +63,7 @@ For example, you can append `router.urls` to a list of existing views...
|
||||||
router.register(r'accounts', AccountViewSet)
|
router.register(r'accounts', AccountViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
|
path('forgot-password/', ForgotPasswordFormView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns += router.urls
|
urlpatterns += router.urls
|
||||||
|
@ -71,22 +71,22 @@ For example, you can append `router.urls` to a list of existing views...
|
||||||
Alternatively you can use Django's `include` function, like so...
|
Alternatively you can use Django's `include` function, like so...
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
|
path('forgot-password', ForgotPasswordFormView.as_view()),
|
||||||
url(r'^', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
You may use `include` with an application namespace:
|
You may use `include` with an application namespace:
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
|
path('forgot-password/', ForgotPasswordFormView.as_view()),
|
||||||
url(r'^api/', include((router.urls, 'app_name'))),
|
path('api/', include((router.urls, 'app_name'))),
|
||||||
]
|
]
|
||||||
|
|
||||||
Or both an application and instance namespace:
|
Or both an application and instance namespace:
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
|
path('forgot-password/', ForgotPasswordFormView.as_view()),
|
||||||
url(r'^api/', include((router.urls, 'app_name'), namespace='instance_name')),
|
path('api/', include((router.urls, 'app_name'), namespace='instance_name')),
|
||||||
]
|
]
|
||||||
|
|
||||||
See Django's [URL namespaces docs][url-namespace-docs] and the [`include` API reference][include-api-reference] for more details.
|
See Django's [URL namespaces docs][url-namespace-docs] and the [`include` API reference][include-api-reference] for more details.
|
||||||
|
|
|
@ -114,7 +114,7 @@ The `get_schema_view()` helper takes the following keyword arguments:
|
||||||
only want the `myproject.api` urls to be exposed in the schema:
|
only want the `myproject.api` urls to be exposed in the schema:
|
||||||
|
|
||||||
schema_url_patterns = [
|
schema_url_patterns = [
|
||||||
url(r'^api/', include('myproject.api.urls')),
|
path('api/', include('myproject.api.urls')),
|
||||||
]
|
]
|
||||||
|
|
||||||
schema_view = get_schema_view(
|
schema_view = get_schema_view(
|
||||||
|
|
|
@ -69,7 +69,7 @@ schema_view = get_schema_view(
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^swagger/$', schema_view),
|
path('swagger/', schema_view),
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
@ -198,8 +198,8 @@ Make sure to include the view before your router urls. For example:
|
||||||
schema_view = get_schema_view(title='Example API')
|
schema_view = get_schema_view(title='Example API')
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url('^$', schema_view),
|
path('', schema_view),
|
||||||
url(r'^', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
### Schema path representations
|
### Schema path representations
|
||||||
|
|
|
@ -73,7 +73,7 @@ To install the API documentation, you'll need to include it in your projects URL
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
...
|
...
|
||||||
url(r'^docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
|
path('docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
|
||||||
]
|
]
|
||||||
|
|
||||||
Once installed you should see something a little like this:
|
Once installed you should see something a little like this:
|
||||||
|
|
|
@ -62,6 +62,7 @@ Here's an example of adding an OpenAPI schema to the URL conf:
|
||||||
```python
|
```python
|
||||||
from rest_framework.schemas import get_schema_view
|
from rest_framework.schemas import get_schema_view
|
||||||
from rest_framework.renderers import JSONOpenAPIRenderer
|
from rest_framework.renderers import JSONOpenAPIRenderer
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
schema_view = get_schema_view(
|
schema_view = get_schema_view(
|
||||||
title='Server Monitoring API',
|
title='Server Monitoring API',
|
||||||
|
@ -70,7 +71,7 @@ schema_view = get_schema_view(
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url('^schema.json$', schema_view),
|
path('schema.json', schema_view),
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
|
@ -19,7 +19,7 @@ To install the API documentation, you'll need to include it in your project's UR
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
...
|
...
|
||||||
url(r'^docs/', include_docs_urls(title='My API title'))
|
path('docs/', include_docs_urls(title='My API title'))
|
||||||
]
|
]
|
||||||
|
|
||||||
This will include two different views:
|
This will include two different views:
|
||||||
|
@ -41,7 +41,7 @@ You may ensure views are given a `request` instance by calling `include_docs_url
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
...
|
...
|
||||||
# Generate schema with valid `request` instance:
|
# Generate schema with valid `request` instance:
|
||||||
url(r'^docs/', include_docs_urls(title='My API title', public=False))
|
path('docs/', include_docs_urls(title='My API title', public=False))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,12 @@ To add a dynamically generated schema view to your API, use `get_schema_view`.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from rest_framework.schemas import get_schema_view
|
from rest_framework.schemas import get_schema_view
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
schema_view = get_schema_view(title="Example API")
|
schema_view = get_schema_view(title="Example API")
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url('^schema$', schema_view),
|
path('schema', schema_view),
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
@ -292,7 +293,7 @@ The simplest way to include a schema in your project is to use the
|
||||||
schema_view = get_schema_view(title="Server Monitoring API")
|
schema_view = get_schema_view(title="Server Monitoring API")
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url('^$', schema_view),
|
path('', schema_view),
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -358,7 +359,7 @@ List of url patterns to limit the schema introspection to. If you only want the
|
||||||
to be exposed in the schema:
|
to be exposed in the schema:
|
||||||
|
|
||||||
schema_url_patterns = [
|
schema_url_patterns = [
|
||||||
url(r'^api/', include('myproject.api.urls')),
|
path('api/', include('myproject.api.urls')),
|
||||||
]
|
]
|
||||||
|
|
||||||
schema_view = get_schema_view(
|
schema_view = get_schema_view(
|
||||||
|
@ -411,7 +412,7 @@ return the schema.
|
||||||
**urls.py:**
|
**urls.py:**
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url('/', schema_view),
|
path('', schema_view),
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ If you're intending to use the browsable API you'll probably also want to add RE
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
...
|
...
|
||||||
url(r'^api-auth/', include('rest_framework.urls'))
|
path('api-auth/', include('rest_framework.urls'))
|
||||||
]
|
]
|
||||||
|
|
||||||
Note that the URL path can be whatever you want.
|
Note that the URL path can be whatever you want.
|
||||||
|
|
|
@ -384,7 +384,7 @@ First, install the API documentation views. These will include the schema resour
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
...
|
...
|
||||||
url(r'^docs/', include_docs_urls(title='My API service'), name='api-docs'),
|
path('docs/', include_docs_urls(title='My API service'), name='api-docs'),
|
||||||
]
|
]
|
||||||
|
|
||||||
Once the API documentation URLs are installed, you'll be able to include both the required JavaScript resources. Note that the ordering of these two lines is important, as the schema loading requires CoreAPI to already be installed.
|
Once the API documentation URLs are installed, you'll be able to include both the required JavaScript resources. Note that the ordering of these two lines is important, as the schema loading requires CoreAPI to already be installed.
|
||||||
|
|
|
@ -137,7 +137,7 @@ We can add a login view for use with the browsable API, by editing the URLconf i
|
||||||
|
|
||||||
Add the following import at the top of the file:
|
Add the following import at the top of the file:
|
||||||
|
|
||||||
from django.conf.urls import include
|
from django.urls import path, include
|
||||||
|
|
||||||
And, at the end of the file, add a pattern to include the login and logout views for the browsable API.
|
And, at the end of the file, add a pattern to include the login and logout views for the browsable API.
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ being applied unexpectedly?</p>
|
||||||
when including the docs urls:</p>
|
when including the docs urls:</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
url(r'^docs/', include_docs_urls(title='Your API',
|
path('docs/', include_docs_urls(title='Your API',
|
||||||
authentication_classes=[],
|
authentication_classes=[],
|
||||||
permission_classes=[])),
|
permission_classes=[])),
|
||||||
</pre>
|
</pre>
|
||||||
|
|
|
@ -6,7 +6,7 @@ your API requires authentication:
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
...
|
...
|
||||||
url(r'^auth/', include('rest_framework.urls'))
|
path('auth/', include('rest_framework.urls'))
|
||||||
]
|
]
|
||||||
|
|
||||||
You should make sure your authentication settings include `SessionAuthentication`.
|
You should make sure your authentication settings include `SessionAuthentication`.
|
||||||
|
|
|
@ -60,8 +60,8 @@ class URLPathVersioning(BaseVersioning):
|
||||||
An example URL conf for two views that accept two different versions.
|
An example URL conf for two views that accept two different versions.
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^(?P<version>[v1|v2]+)/users/$', users_list, name='users-list'),
|
re_path(r'^(?P<version>[v1|v2]+)/users/$', users_list, name='users-list'),
|
||||||
url(r'^(?P<version>[v1|v2]+)/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
|
re_path(r'^(?P<version>[v1|v2]+)/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
|
||||||
]
|
]
|
||||||
|
|
||||||
GET /1.0/something/ HTTP/1.1
|
GET /1.0/something/ HTTP/1.1
|
||||||
|
@ -99,14 +99,14 @@ class NamespaceVersioning(BaseVersioning):
|
||||||
|
|
||||||
# users/urls.py
|
# users/urls.py
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^/users/$', users_list, name='users-list'),
|
path('/users/', users_list, name='users-list'),
|
||||||
url(r'^/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
|
path('/users/<int:pk>/', users_detail, name='users-detail')
|
||||||
]
|
]
|
||||||
|
|
||||||
# urls.py
|
# urls.py
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^v1/', include('users.urls', namespace='v1')),
|
path('v1/', include('users.urls', namespace='v1')),
|
||||||
url(r'^v2/', include('users.urls', namespace='v2'))
|
path('v2/', include('users.urls', namespace='v2'))
|
||||||
]
|
]
|
||||||
|
|
||||||
GET /1.0/something/ HTTP/1.1
|
GET /1.0/something/ HTTP/1.1
|
||||||
|
|
|
@ -2,10 +2,10 @@ import base64
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls import include, url
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import include, path
|
||||||
|
|
||||||
from rest_framework import (
|
from rest_framework import (
|
||||||
HTTP_HEADER_ENCODING, exceptions, permissions, renderers, status
|
HTTP_HEADER_ENCODING, exceptions, permissions, renderers, status
|
||||||
|
@ -47,34 +47,34 @@ class MockView(APIView):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(
|
path(
|
||||||
r'^session/$',
|
'session/',
|
||||||
MockView.as_view(authentication_classes=[SessionAuthentication])
|
MockView.as_view(authentication_classes=[SessionAuthentication])
|
||||||
),
|
),
|
||||||
url(
|
path(
|
||||||
r'^basic/$',
|
'basic/',
|
||||||
MockView.as_view(authentication_classes=[BasicAuthentication])
|
MockView.as_view(authentication_classes=[BasicAuthentication])
|
||||||
),
|
),
|
||||||
url(
|
path(
|
||||||
r'^remote-user/$',
|
'remote-user/',
|
||||||
MockView.as_view(authentication_classes=[RemoteUserAuthentication])
|
MockView.as_view(authentication_classes=[RemoteUserAuthentication])
|
||||||
),
|
),
|
||||||
url(
|
path(
|
||||||
r'^token/$',
|
'token/',
|
||||||
MockView.as_view(authentication_classes=[TokenAuthentication])
|
MockView.as_view(authentication_classes=[TokenAuthentication])
|
||||||
),
|
),
|
||||||
url(
|
path(
|
||||||
r'^customtoken/$',
|
'customtoken/',
|
||||||
MockView.as_view(authentication_classes=[CustomTokenAuthentication])
|
MockView.as_view(authentication_classes=[CustomTokenAuthentication])
|
||||||
),
|
),
|
||||||
url(
|
path(
|
||||||
r'^customkeywordtoken/$',
|
'customkeywordtoken/',
|
||||||
MockView.as_view(
|
MockView.as_view(
|
||||||
authentication_classes=[CustomKeywordTokenAuthentication]
|
authentication_classes=[CustomKeywordTokenAuthentication]
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
url(r'^auth-token/$', obtain_auth_token),
|
path('auth-token/', obtain_auth_token),
|
||||||
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
|
path('auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from django.conf.urls import include, url
|
from django.urls import include, path
|
||||||
|
|
||||||
from .views import MockView
|
from .views import MockView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', MockView.as_view()),
|
path('', MockView.as_view()),
|
||||||
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
|
path('auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.conf.urls import url
|
from django.urls import path
|
||||||
|
|
||||||
from .views import MockView
|
from .views import MockView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', MockView.as_view()),
|
path('', MockView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.conf.urls import url
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.generics import ListCreateAPIView
|
from rest_framework.generics import ListCreateAPIView
|
||||||
|
@ -23,7 +23,7 @@ class NestedSerializersView(ListCreateAPIView):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^api/$', NestedSerializersView.as_view(), name='api'),
|
path('api/', NestedSerializersView.as_view(), name='api'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import include, url
|
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.urls import path
|
from django.urls import include, path
|
||||||
|
|
||||||
from rest_framework import (
|
from rest_framework import (
|
||||||
filters, generics, pagination, permissions, serializers
|
filters, generics, pagination, permissions, serializers
|
||||||
|
@ -145,8 +144,8 @@ with override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.s
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
router.register('example', ExampleViewSet, basename='example')
|
router.register('example', ExampleViewSet, basename='example')
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', schema_view),
|
path('', schema_view),
|
||||||
url(r'^', include(router.urls))
|
path('', include(router.urls))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -407,9 +406,9 @@ class ExampleDetailView(APIView):
|
||||||
class TestSchemaGenerator(TestCase):
|
class TestSchemaGenerator(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.patterns = [
|
self.patterns = [
|
||||||
url(r'^example/?$', views.ExampleListView.as_view()),
|
path('example/', views.ExampleListView.as_view()),
|
||||||
url(r'^example/(?P<pk>\d+)/?$', views.ExampleDetailView.as_view()),
|
path('example/<int:pk>/', views.ExampleDetailView.as_view()),
|
||||||
url(r'^example/(?P<pk>\d+)/sub/?$', views.ExampleDetailView.as_view()),
|
path('example/<int:pk>/sub/', views.ExampleDetailView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_schema_for_regular_views(self):
|
def test_schema_for_regular_views(self):
|
||||||
|
@ -513,9 +512,9 @@ class TestSchemaGeneratorDjango2(TestCase):
|
||||||
class TestSchemaGeneratorNotAtRoot(TestCase):
|
class TestSchemaGeneratorNotAtRoot(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.patterns = [
|
self.patterns = [
|
||||||
url(r'^api/v1/example/?$', views.ExampleListView.as_view()),
|
path('api/v1/example/', views.ExampleListView.as_view()),
|
||||||
url(r'^api/v1/example/(?P<pk>\d+)/?$', views.ExampleDetailView.as_view()),
|
path('api/v1/example/<int:pk>/', views.ExampleDetailView.as_view()),
|
||||||
url(r'^api/v1/example/(?P<pk>\d+)/sub/?$', views.ExampleDetailView.as_view()),
|
path('api/v1/example/<int:pk>/sub/', views.ExampleDetailView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_schema_for_regular_views(self):
|
def test_schema_for_regular_views(self):
|
||||||
|
@ -569,7 +568,7 @@ class TestSchemaGeneratorWithMethodLimitedViewSets(TestCase):
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
router.register('example1', MethodLimitedViewSet, basename='example1')
|
router.register('example1', MethodLimitedViewSet, basename='example1')
|
||||||
self.patterns = [
|
self.patterns = [
|
||||||
url(r'^', include(router.urls))
|
path('', include(router.urls))
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_schema_for_regular_views(self):
|
def test_schema_for_regular_views(self):
|
||||||
|
@ -635,8 +634,8 @@ class TestSchemaGeneratorWithRestrictedViewSets(TestCase):
|
||||||
router.register('example1', Http404ExampleViewSet, basename='example1')
|
router.register('example1', Http404ExampleViewSet, basename='example1')
|
||||||
router.register('example2', PermissionDeniedExampleViewSet, basename='example2')
|
router.register('example2', PermissionDeniedExampleViewSet, basename='example2')
|
||||||
self.patterns = [
|
self.patterns = [
|
||||||
url('^example/?$', views.ExampleListView.as_view()),
|
path('example/', views.ExampleListView.as_view()),
|
||||||
url(r'^', include(router.urls))
|
path('', include(router.urls))
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_schema_for_regular_views(self):
|
def test_schema_for_regular_views(self):
|
||||||
|
@ -679,7 +678,7 @@ class ForeignKeySourceView(generics.CreateAPIView):
|
||||||
class TestSchemaGeneratorWithForeignKey(TestCase):
|
class TestSchemaGeneratorWithForeignKey(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.patterns = [
|
self.patterns = [
|
||||||
url(r'^example/?$', ForeignKeySourceView.as_view()),
|
path('example/', ForeignKeySourceView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_schema_for_regular_views(self):
|
def test_schema_for_regular_views(self):
|
||||||
|
@ -725,7 +724,7 @@ class ManyToManySourceView(generics.CreateAPIView):
|
||||||
class TestSchemaGeneratorWithManyToMany(TestCase):
|
class TestSchemaGeneratorWithManyToMany(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.patterns = [
|
self.patterns = [
|
||||||
url(r'^example/?$', ManyToManySourceView.as_view()),
|
path('example/', ManyToManySourceView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_schema_for_regular_views(self):
|
def test_schema_for_regular_views(self):
|
||||||
|
@ -1041,9 +1040,9 @@ with override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.s
|
||||||
class SchemaGenerationExclusionTests(TestCase):
|
class SchemaGenerationExclusionTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.patterns = [
|
self.patterns = [
|
||||||
url('^excluded-cbv/$', ExcludedAPIView.as_view()),
|
path('excluded-cbv/', ExcludedAPIView.as_view()),
|
||||||
url('^excluded-fbv/$', excluded_fbv),
|
path('excluded-fbv/', excluded_fbv),
|
||||||
url('^included-fbv/$', included_fbv),
|
path('included-fbv/', included_fbv),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_schema_generator_excludes_correctly(self):
|
def test_schema_generator_excludes_correctly(self):
|
||||||
|
@ -1136,8 +1135,8 @@ class TestURLNamingCollisions(TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^test', simple_fbv),
|
path('test', simple_fbv),
|
||||||
url(r'^test/list/', simple_fbv),
|
path('test/list/', simple_fbv),
|
||||||
]
|
]
|
||||||
|
|
||||||
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
||||||
|
@ -1173,14 +1172,14 @@ class TestURLNamingCollisions(TestCase):
|
||||||
|
|
||||||
def test_manually_routing_generic_view(self):
|
def test_manually_routing_generic_view(self):
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^test', NamingCollisionView.as_view()),
|
path('test', NamingCollisionView.as_view()),
|
||||||
url(r'^test/retrieve/', NamingCollisionView.as_view()),
|
path('test/retrieve/', NamingCollisionView.as_view()),
|
||||||
url(r'^test/update/', NamingCollisionView.as_view()),
|
path('test/update/', NamingCollisionView.as_view()),
|
||||||
|
|
||||||
# Fails with method names:
|
# Fails with method names:
|
||||||
url(r'^test/get/', NamingCollisionView.as_view()),
|
path('test/get/', NamingCollisionView.as_view()),
|
||||||
url(r'^test/put/', NamingCollisionView.as_view()),
|
path('test/put/', NamingCollisionView.as_view()),
|
||||||
url(r'^test/delete/', NamingCollisionView.as_view()),
|
path('test/delete/', NamingCollisionView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
||||||
|
@ -1196,7 +1195,7 @@ class TestURLNamingCollisions(TestCase):
|
||||||
|
|
||||||
def test_from_router(self):
|
def test_from_router(self):
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'from-router', include(naming_collisions_router.urls)),
|
path('from-router', include(naming_collisions_router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
||||||
|
@ -1228,8 +1227,8 @@ class TestURLNamingCollisions(TestCase):
|
||||||
|
|
||||||
def test_url_under_same_key_not_replaced(self):
|
def test_url_under_same_key_not_replaced(self):
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'example/(?P<pk>\d+)/$', BasicNamingCollisionView.as_view()),
|
path('example/<int:pk>/', BasicNamingCollisionView.as_view()),
|
||||||
url(r'example/(?P<slug>\w+)/$', BasicNamingCollisionView.as_view()),
|
path('example/<str:slug>/', BasicNamingCollisionView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
||||||
|
@ -1245,8 +1244,8 @@ class TestURLNamingCollisions(TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^test/list/', simple_fbv),
|
path('test/list/', simple_fbv),
|
||||||
url(r'^test/(?P<pk>\d+)/list/', simple_fbv),
|
path('test/<int:pk>/list/', simple_fbv),
|
||||||
]
|
]
|
||||||
|
|
||||||
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
|
||||||
|
|
|
@ -3,10 +3,10 @@ import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import url
|
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework.compat import uritemplate, yaml
|
from rest_framework.compat import uritemplate, yaml
|
||||||
from rest_framework.management.commands import generateschema
|
from rest_framework.management.commands import generateschema
|
||||||
|
@ -20,7 +20,7 @@ class FooView(APIView):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', FooView.as_view())
|
path('', FooView.as_view())
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ import uuid
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import url
|
|
||||||
from django.test import RequestFactory, TestCase, override_settings
|
from django.test import RequestFactory, TestCase, override_settings
|
||||||
|
from django.urls import path
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from rest_framework import filters, generics, pagination, routers, serializers
|
from rest_framework import filters, generics, pagination, routers, serializers
|
||||||
|
@ -719,8 +719,8 @@ class TestOperationIntrospection(TestCase):
|
||||||
|
|
||||||
def test_duplicate_operation_id(self):
|
def test_duplicate_operation_id(self):
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^duplicate1/?$', views.ExampleOperationIdDuplicate1.as_view()),
|
path('duplicate1/', views.ExampleOperationIdDuplicate1.as_view()),
|
||||||
url(r'^duplicate2/?$', views.ExampleOperationIdDuplicate2.as_view()),
|
path('duplicate2/', views.ExampleOperationIdDuplicate2.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
generator = SchemaGenerator(patterns=patterns)
|
generator = SchemaGenerator(patterns=patterns)
|
||||||
|
@ -874,7 +874,7 @@ class TestOperationIntrospection(TestCase):
|
||||||
schema = AutoSchema(tags=['example1', 'example2'])
|
schema = AutoSchema(tags=['example1', 'example2'])
|
||||||
|
|
||||||
url_patterns = [
|
url_patterns = [
|
||||||
url(r'^test/?$', ExampleStringTagsViewSet.as_view()),
|
path('test/', ExampleStringTagsViewSet.as_view()),
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=url_patterns)
|
generator = SchemaGenerator(patterns=url_patterns)
|
||||||
schema = generator.get_schema(request=create_request('/'))
|
schema = generator.get_schema(request=create_request('/'))
|
||||||
|
@ -911,8 +911,8 @@ class TestOperationIntrospection(TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
url_patterns = [
|
url_patterns = [
|
||||||
url(r'^any-dash_underscore/?$', RestaurantAPIView.as_view()),
|
path('any-dash_underscore/', RestaurantAPIView.as_view()),
|
||||||
url(r'^restaurants/branches/?$', BranchAPIView.as_view())
|
path('restaurants/branches/', BranchAPIView.as_view())
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=url_patterns)
|
generator = SchemaGenerator(patterns=url_patterns)
|
||||||
schema = generator.get_schema(request=create_request('/'))
|
schema = generator.get_schema(request=create_request('/'))
|
||||||
|
@ -930,7 +930,7 @@ class TestGenerator(TestCase):
|
||||||
def test_paths_construction(self):
|
def test_paths_construction(self):
|
||||||
"""Construction of the `paths` key."""
|
"""Construction of the `paths` key."""
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^example/?$', views.ExampleListView.as_view()),
|
path('example/', views.ExampleListView.as_view()),
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=patterns)
|
generator = SchemaGenerator(patterns=patterns)
|
||||||
generator._initialise_endpoints()
|
generator._initialise_endpoints()
|
||||||
|
@ -946,8 +946,8 @@ class TestGenerator(TestCase):
|
||||||
def test_prefixed_paths_construction(self):
|
def test_prefixed_paths_construction(self):
|
||||||
"""Construction of the `paths` key maintains a common prefix."""
|
"""Construction of the `paths` key maintains a common prefix."""
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^v1/example/?$', views.ExampleListView.as_view()),
|
path('v1/example/', views.ExampleListView.as_view()),
|
||||||
url(r'^v1/example/{pk}/?$', views.ExampleDetailView.as_view()),
|
path('v1/example/{pk}/', views.ExampleDetailView.as_view()),
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=patterns)
|
generator = SchemaGenerator(patterns=patterns)
|
||||||
generator._initialise_endpoints()
|
generator._initialise_endpoints()
|
||||||
|
@ -959,8 +959,8 @@ class TestGenerator(TestCase):
|
||||||
|
|
||||||
def test_mount_url_prefixed_to_paths(self):
|
def test_mount_url_prefixed_to_paths(self):
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^example/?$', views.ExampleListView.as_view()),
|
path('example/', views.ExampleListView.as_view()),
|
||||||
url(r'^example/{pk}/?$', views.ExampleDetailView.as_view()),
|
path('example/{pk}/', views.ExampleDetailView.as_view()),
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=patterns, url='/api')
|
generator = SchemaGenerator(patterns=patterns, url='/api')
|
||||||
generator._initialise_endpoints()
|
generator._initialise_endpoints()
|
||||||
|
@ -973,7 +973,7 @@ class TestGenerator(TestCase):
|
||||||
def test_schema_construction(self):
|
def test_schema_construction(self):
|
||||||
"""Construction of the top level dictionary."""
|
"""Construction of the top level dictionary."""
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^example/?$', views.ExampleListView.as_view()),
|
path('example/', views.ExampleListView.as_view()),
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=patterns)
|
generator = SchemaGenerator(patterns=patterns)
|
||||||
|
|
||||||
|
@ -995,7 +995,7 @@ class TestGenerator(TestCase):
|
||||||
def test_schema_information(self):
|
def test_schema_information(self):
|
||||||
"""Construction of the top level dictionary."""
|
"""Construction of the top level dictionary."""
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^example/?$', views.ExampleListView.as_view()),
|
path('example/', views.ExampleListView.as_view()),
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=patterns, title='My title', version='1.2.3', description='My description')
|
generator = SchemaGenerator(patterns=patterns, title='My title', version='1.2.3', description='My description')
|
||||||
|
|
||||||
|
@ -1009,7 +1009,7 @@ class TestGenerator(TestCase):
|
||||||
def test_schema_information_empty(self):
|
def test_schema_information_empty(self):
|
||||||
"""Construction of the top level dictionary."""
|
"""Construction of the top level dictionary."""
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^example/?$', views.ExampleListView.as_view()),
|
path('example/', views.ExampleListView.as_view()),
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=patterns)
|
generator = SchemaGenerator(patterns=patterns)
|
||||||
|
|
||||||
|
@ -1022,7 +1022,7 @@ class TestGenerator(TestCase):
|
||||||
def test_serializer_model(self):
|
def test_serializer_model(self):
|
||||||
"""Construction of the top level dictionary."""
|
"""Construction of the top level dictionary."""
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^example/?$', views.ExampleGenericAPIViewModel.as_view()),
|
path('example/', views.ExampleGenericAPIViewModel.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
generator = SchemaGenerator(patterns=patterns)
|
generator = SchemaGenerator(patterns=patterns)
|
||||||
|
@ -1038,7 +1038,7 @@ class TestGenerator(TestCase):
|
||||||
|
|
||||||
def test_authtoken_serializer(self):
|
def test_authtoken_serializer(self):
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^api-token-auth/', obtain_auth_token)
|
path('api-token-auth/', obtain_auth_token)
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=patterns)
|
generator = SchemaGenerator(patterns=patterns)
|
||||||
|
|
||||||
|
@ -1065,7 +1065,7 @@ class TestGenerator(TestCase):
|
||||||
|
|
||||||
def test_component_name(self):
|
def test_component_name(self):
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^example/?$', views.ExampleAutoSchemaComponentName.as_view()),
|
path('example/', views.ExampleAutoSchemaComponentName.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
generator = SchemaGenerator(patterns=patterns)
|
generator = SchemaGenerator(patterns=patterns)
|
||||||
|
@ -1080,8 +1080,8 @@ class TestGenerator(TestCase):
|
||||||
|
|
||||||
def test_duplicate_component_name(self):
|
def test_duplicate_component_name(self):
|
||||||
patterns = [
|
patterns = [
|
||||||
url(r'^duplicate1/?$', views.ExampleAutoSchemaDuplicate1.as_view()),
|
path('duplicate1/', views.ExampleAutoSchemaDuplicate1.as_view()),
|
||||||
url(r'^duplicate2/?$', views.ExampleAutoSchemaDuplicate2.as_view()),
|
path('duplicate2/', views.ExampleAutoSchemaDuplicate2.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
generator = SchemaGenerator(patterns=patterns)
|
generator = SchemaGenerator(patterns=patterns)
|
||||||
|
@ -1104,7 +1104,7 @@ class TestGenerator(TestCase):
|
||||||
schema = AutoSchema(operation_id_base='example')
|
schema = AutoSchema(operation_id_base='example')
|
||||||
|
|
||||||
url_patterns = [
|
url_patterns = [
|
||||||
url(r'^example/?$', ExampleView.as_view()),
|
path('example/', ExampleView.as_view()),
|
||||||
]
|
]
|
||||||
generator = SchemaGenerator(patterns=url_patterns)
|
generator = SchemaGenerator(patterns=url_patterns)
|
||||||
schema = generator.get_schema(request=create_request('/'))
|
schema = generator.get_schema(request=create_request('/'))
|
||||||
|
|
|
@ -2,9 +2,9 @@ import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.conf.urls import url
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
from django.urls import path, re_path
|
||||||
|
|
||||||
from rest_framework.compat import coreapi, coreschema
|
from rest_framework.compat import coreapi, coreschema
|
||||||
from rest_framework.parsers import FileUploadParser
|
from rest_framework.parsers import FileUploadParser
|
||||||
|
@ -178,13 +178,13 @@ class HeadersView(APIView):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', SchemaView.as_view()),
|
path('', SchemaView.as_view()),
|
||||||
url(r'^example/$', ListView.as_view()),
|
path('example/', ListView.as_view()),
|
||||||
url(r'^example/(?P<id>[0-9]+)/$', DetailView.as_view()),
|
re_path(r'^example/(?P<id>[0-9]+)/$', DetailView.as_view()),
|
||||||
url(r'^upload/$', UploadView.as_view()),
|
path('upload/', UploadView.as_view()),
|
||||||
url(r'^download/$', DownloadView.as_view()),
|
path('download/', DownloadView.as_view()),
|
||||||
url(r'^text/$', TextView.as_view()),
|
path('text/', TextView.as_view()),
|
||||||
url(r'^headers/$', HeadersView.as_view()),
|
path('headers/', HeadersView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.conf.urls import url
|
|
||||||
from django.db import connection, connections, transaction
|
from django.db import connection, connections, transaction
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.test import TestCase, TransactionTestCase, override_settings
|
from django.test import TestCase, TransactionTestCase, override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
|
@ -44,7 +44,7 @@ class NonAtomicAPIExceptionView(APIView):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = (
|
urlpatterns = (
|
||||||
url(r'^$', NonAtomicAPIExceptionView.as_view()),
|
path('', NonAtomicAPIExceptionView.as_view()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -697,7 +697,7 @@ class TestNullBooleanField(TestBooleanField):
|
||||||
None: None,
|
None: None,
|
||||||
'other': True
|
'other': True
|
||||||
}
|
}
|
||||||
field = serializers.NullBooleanField()
|
field = serializers.BooleanField(allow_null=True)
|
||||||
|
|
||||||
|
|
||||||
class TestNullableBooleanField(TestNullBooleanField):
|
class TestNullableBooleanField(TestNullBooleanField):
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import django.template.loader
|
import django.template.loader
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import url
|
|
||||||
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
|
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.template import TemplateDoesNotExist, engines
|
from django.template import TemplateDoesNotExist, engines
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.decorators import api_view, renderer_classes
|
from rest_framework.decorators import api_view, renderer_classes
|
||||||
|
@ -35,9 +35,9 @@ def not_found(request):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', example),
|
path('', example),
|
||||||
url(r'^permission_denied$', permission_denied),
|
path('permission_denied', permission_denied),
|
||||||
url(r'^not_found$', not_found),
|
path('not_found', not_found),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.conf.urls import url
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.renderers import JSONRenderer
|
from rest_framework.renderers import JSONRenderer
|
||||||
|
@ -29,7 +29,7 @@ def dummy_view(request):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^example/(?P<pk>[0-9]+)/$', dummy_view, name='example-detail'),
|
path('example/<int:pk>/', dummy_view, name='example-detail'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -311,7 +311,8 @@ class TestMetadata:
|
||||||
class TestSimpleMetadataFieldInfo(TestCase):
|
class TestSimpleMetadataFieldInfo(TestCase):
|
||||||
def test_null_boolean_field_info_type(self):
|
def test_null_boolean_field_info_type(self):
|
||||||
options = metadata.SimpleMetadata()
|
options = metadata.SimpleMetadata()
|
||||||
field_info = options.get_field_info(serializers.NullBooleanField())
|
field_info = options.get_field_info(serializers.BooleanField(
|
||||||
|
allow_null=True))
|
||||||
assert field_info['type'] == 'boolean'
|
assert field_info['type'] == 'boolean'
|
||||||
|
|
||||||
def test_related_field_choices(self):
|
def test_related_field_choices(self):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.conf.urls import url
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework.authentication import TokenAuthentication
|
from rest_framework.authentication import TokenAuthentication
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
|
@ -17,8 +17,8 @@ class PostView(APIView):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^auth$', APIView.as_view(authentication_classes=(TokenAuthentication,))),
|
path('auth', APIView.as_view(authentication_classes=(TokenAuthentication,))),
|
||||||
url(r'^post$', PostView.as_view()),
|
path('post', PostView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@ import uuid
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.monkeypatch import MonkeyPatch
|
from _pytest.monkeypatch import MonkeyPatch
|
||||||
from django.conf.urls import url
|
|
||||||
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
|
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
from django.urls import re_path
|
||||||
from django.utils.datastructures import MultiValueDict
|
from django.utils.datastructures import MultiValueDict
|
||||||
|
|
||||||
from rest_framework import relations, serializers
|
from rest_framework import relations, serializers
|
||||||
|
@ -146,7 +146,7 @@ class TestProxiedPrimaryKeyRelatedField(APISimpleTestCase):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^example/(?P<name>.+)/$', lambda: None, name='example'),
|
re_path(r'^example/(?P<name>.+)/$', lambda: None, name='example'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.conf.urls import url
|
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.test import APIRequestFactory
|
from rest_framework.test import APIRequestFactory
|
||||||
|
@ -17,14 +17,14 @@ def dummy_view(request, pk):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^dummyurl/(?P<pk>[0-9]+)/$', dummy_view, name='dummy-url'),
|
path('dummyurl/<int:pk>/', dummy_view, name='dummy-url'),
|
||||||
url(r'^manytomanysource/(?P<pk>[0-9]+)/$', dummy_view, name='manytomanysource-detail'),
|
path('manytomanysource/<int:pk>/', dummy_view, name='manytomanysource-detail'),
|
||||||
url(r'^manytomanytarget/(?P<pk>[0-9]+)/$', dummy_view, name='manytomanytarget-detail'),
|
path('manytomanytarget/<int:pk>/', dummy_view, name='manytomanytarget-detail'),
|
||||||
url(r'^foreignkeysource/(?P<pk>[0-9]+)/$', dummy_view, name='foreignkeysource-detail'),
|
path('foreignkeysource/<int:pk>/', dummy_view, name='foreignkeysource-detail'),
|
||||||
url(r'^foreignkeytarget/(?P<pk>[0-9]+)/$', dummy_view, name='foreignkeytarget-detail'),
|
path('foreignkeytarget/<int:pk>/', dummy_view, name='foreignkeytarget-detail'),
|
||||||
url(r'^nullableforeignkeysource/(?P<pk>[0-9]+)/$', dummy_view, name='nullableforeignkeysource-detail'),
|
path('nullableforeignkeysource/<int:pk>/', dummy_view, name='nullableforeignkeysource-detail'),
|
||||||
url(r'^onetoonetarget/(?P<pk>[0-9]+)/$', dummy_view, name='onetoonetarget-detail'),
|
path('onetoonetarget/<int:pk>/', dummy_view, name='onetoonetarget-detail'),
|
||||||
url(r'^nullableonetoonesource/(?P<pk>[0-9]+)/$', dummy_view, name='nullableonetoonesource-detail'),
|
path('nullableonetoonesource/<int:pk>/', dummy_view, name='nullableonetoonesource-detail'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ from collections import OrderedDict
|
||||||
from collections.abc import MutableMapping
|
from collections.abc import MutableMapping
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import include, url
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import include, path, re_path
|
||||||
from django.utils.safestring import SafeText
|
from django.utils.safestring import SafeText
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
@ -111,14 +111,14 @@ class HTMLView1(APIView):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^.*\.(?P<format>.+)$', MockView.as_view(renderer_classes=[RendererA, RendererB])),
|
re_path(r'^.*\.(?P<format>.+)$', MockView.as_view(renderer_classes=[RendererA, RendererB])),
|
||||||
url(r'^$', MockView.as_view(renderer_classes=[RendererA, RendererB])),
|
path('', MockView.as_view(renderer_classes=[RendererA, RendererB])),
|
||||||
url(r'^cache$', MockGETView.as_view()),
|
path('cache', MockGETView.as_view()),
|
||||||
url(r'^parseerror$', MockPOSTView.as_view(renderer_classes=[JSONRenderer, BrowsableAPIRenderer])),
|
path('parseerror', MockPOSTView.as_view(renderer_classes=[JSONRenderer, BrowsableAPIRenderer])),
|
||||||
url(r'^html$', HTMLView.as_view()),
|
path('html', HTMLView.as_view()),
|
||||||
url(r'^html1$', HTMLView1.as_view()),
|
path('html1', HTMLView1.as_view()),
|
||||||
url(r'^empty$', EmptyGETView.as_view()),
|
path('empty', EmptyGETView.as_view()),
|
||||||
url(r'^api', include('rest_framework.urls', namespace='rest_framework'))
|
path('api', include('rest_framework.urls', namespace='rest_framework'))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -637,7 +637,7 @@ class BrowsableAPIRendererTests(URLPatternsTestCase):
|
||||||
router = SimpleRouter()
|
router = SimpleRouter()
|
||||||
router.register('examples', ExampleViewSet, basename='example')
|
router.register('examples', ExampleViewSet, basename='example')
|
||||||
router.register('auth-examples', AuthExampleViewSet, basename='auth-example')
|
router.register('auth-examples', AuthExampleViewSet, basename='auth-example')
|
||||||
urlpatterns = [url(r'^api/', include(router.urls))]
|
urlpatterns = [path('api/', include(router.urls))]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.renderer = BrowsableAPIRenderer()
|
self.renderer = BrowsableAPIRenderer()
|
||||||
|
|
|
@ -5,7 +5,6 @@ import os.path
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import url
|
|
||||||
from django.contrib.auth import authenticate, login, logout
|
from django.contrib.auth import authenticate, login, logout
|
||||||
from django.contrib.auth.middleware import AuthenticationMiddleware
|
from django.contrib.auth.middleware import AuthenticationMiddleware
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -13,6 +12,7 @@ from django.contrib.sessions.middleware import SessionMiddleware
|
||||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.http.request import RawPostDataException
|
from django.http.request import RawPostDataException
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.authentication import SessionAuthentication
|
from rest_framework.authentication import SessionAuthentication
|
||||||
|
@ -153,9 +153,9 @@ class FileUploadView(APIView):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', MockView.as_view()),
|
path('', MockView.as_view()),
|
||||||
url(r'^echo/$', EchoView.as_view()),
|
path('echo/', EchoView.as_view()),
|
||||||
url(r'^upload/$', FileUploadView.as_view())
|
path('upload/', FileUploadView.as_view())
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.conf.urls import url
|
|
||||||
from django.contrib.auth import authenticate, login
|
from django.contrib.auth import authenticate, login
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
from django.urls import path
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.decorators.csrf import csrf_protect, ensure_csrf_cookie
|
from django.views.decorators.csrf import csrf_protect, ensure_csrf_cookie
|
||||||
|
|
||||||
|
@ -90,10 +90,10 @@ class AuthView(APIView):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', Root.as_view(), name='root'),
|
path('', Root.as_view(), name='root'),
|
||||||
url(r'^headers/$', HeadersView.as_view(), name='headers'),
|
path('headers/', HeadersView.as_view(), name='headers'),
|
||||||
url(r'^session/$', SessionView.as_view(), name='session'),
|
path('session/', SessionView.as_view(), name='session'),
|
||||||
url(r'^auth/$', AuthView.as_view(), name='auth'),
|
path('auth/', AuthView.as_view(), name='auth'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.conf.urls import include, url
|
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import include, path, re_path
|
||||||
|
|
||||||
from rest_framework import generics, routers, serializers, status, viewsets
|
from rest_framework import generics, routers, serializers, status, viewsets
|
||||||
from rest_framework.parsers import JSONParser
|
from rest_framework.parsers import JSONParser
|
||||||
|
@ -117,15 +117,15 @@ new_model_viewset_router.register(r'', HTMLNewModelViewSet)
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^setbyview$', MockViewSettingContentType.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
|
path('setbyview', MockViewSettingContentType.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
|
||||||
url(r'^.*\.(?P<format>.+)$', MockView.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
|
re_path(r'^.*\.(?P<format>.+)$', MockView.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
|
||||||
url(r'^$', MockView.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
|
path('', MockView.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
|
||||||
url(r'^html$', HTMLView.as_view()),
|
path('html', HTMLView.as_view()),
|
||||||
url(r'^json$', JSONView.as_view()),
|
path('json', JSONView.as_view()),
|
||||||
url(r'^html1$', HTMLView1.as_view()),
|
path('html1', HTMLView1.as_view()),
|
||||||
url(r'^html_new_model$', HTMLNewModelView.as_view()),
|
path('html_new_model', HTMLNewModelView.as_view()),
|
||||||
url(r'^html_new_model_viewset', include(new_model_viewset_router.urls)),
|
path('html_new_model_viewset', include(new_model_viewset_router.urls)),
|
||||||
url(r'^restframework', include('rest_framework.urls', namespace='rest_framework'))
|
path('restframework', include('rest_framework.urls', namespace='rest_framework'))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from django.conf.urls import url
|
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.urls import NoReverseMatch
|
from django.urls import NoReverseMatch, path
|
||||||
|
|
||||||
from rest_framework.reverse import reverse
|
from rest_framework.reverse import reverse
|
||||||
from rest_framework.test import APIRequestFactory
|
from rest_framework.test import APIRequestFactory
|
||||||
|
@ -13,7 +12,7 @@ def null_view(request):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^view$', null_view, name='view'),
|
path('view', null_view, name='view'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import include, url
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.urls import resolve, reverse
|
from django.urls import include, path, resolve, reverse
|
||||||
|
|
||||||
from rest_framework import permissions, serializers, viewsets
|
from rest_framework import permissions, serializers, viewsets
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
@ -118,7 +117,7 @@ class TestSimpleRouter(URLPatternsTestCase, TestCase):
|
||||||
router.register('basics', BasicViewSet, basename='basic')
|
router.register('basics', BasicViewSet, basename='basic')
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^api/', include(router.urls)),
|
path('api/', include(router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -163,8 +162,8 @@ class TestSimpleRouter(URLPatternsTestCase, TestCase):
|
||||||
|
|
||||||
class TestRootView(URLPatternsTestCase, TestCase):
|
class TestRootView(URLPatternsTestCase, TestCase):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^non-namespaced/', include(namespaced_router.urls)),
|
path('non-namespaced/', include(namespaced_router.urls)),
|
||||||
url(r'^namespaced/', include((namespaced_router.urls, 'namespaced'), namespace='namespaced')),
|
path('namespaced/', include((namespaced_router.urls, 'namespaced'), namespace='namespaced')),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_retrieve_namespaced_root(self):
|
def test_retrieve_namespaced_root(self):
|
||||||
|
@ -181,8 +180,8 @@ class TestCustomLookupFields(URLPatternsTestCase, TestCase):
|
||||||
Ensure that custom lookup fields are correctly routed.
|
Ensure that custom lookup fields are correctly routed.
|
||||||
"""
|
"""
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^example/', include(notes_router.urls)),
|
path('example/', include(notes_router.urls)),
|
||||||
url(r'^example2/', include(kwarged_notes_router.urls)),
|
path('example2/', include(kwarged_notes_router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -238,8 +237,8 @@ class TestLookupUrlKwargs(URLPatternsTestCase, TestCase):
|
||||||
Setup a deep lookup_field, but map it to a simple URL kwarg.
|
Setup a deep lookup_field, but map it to a simple URL kwarg.
|
||||||
"""
|
"""
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^example/', include(notes_router.urls)),
|
path('example/', include(notes_router.urls)),
|
||||||
url(r'^example2/', include(kwarged_notes_router.urls)),
|
path('example2/', include(kwarged_notes_router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -426,7 +425,7 @@ class TestDynamicListAndDetailRouter(TestCase):
|
||||||
|
|
||||||
class TestEmptyPrefix(URLPatternsTestCase, TestCase):
|
class TestEmptyPrefix(URLPatternsTestCase, TestCase):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^empty-prefix/', include(empty_prefix_router.urls)),
|
path('empty-prefix/', include(empty_prefix_router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_empty_prefix_list(self):
|
def test_empty_prefix_list(self):
|
||||||
|
@ -443,7 +442,7 @@ class TestEmptyPrefix(URLPatternsTestCase, TestCase):
|
||||||
|
|
||||||
class TestRegexUrlPath(URLPatternsTestCase, TestCase):
|
class TestRegexUrlPath(URLPatternsTestCase, TestCase):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^regex/', include(regex_url_path_router.urls)),
|
path('regex/', include(regex_url_path_router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_regex_url_path_list(self):
|
def test_regex_url_path_list(self):
|
||||||
|
@ -462,7 +461,7 @@ class TestRegexUrlPath(URLPatternsTestCase, TestCase):
|
||||||
|
|
||||||
class TestViewInitkwargs(URLPatternsTestCase, TestCase):
|
class TestViewInitkwargs(URLPatternsTestCase, TestCase):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^example/', include(notes_router.urls)),
|
path('example/', include(notes_router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_suffix(self):
|
def test_suffix(self):
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from django.conf.urls import url
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework import fields, serializers
|
from rest_framework import fields, serializers
|
||||||
from rest_framework.decorators import api_view
|
from rest_framework.decorators import api_view
|
||||||
|
@ -47,10 +47,10 @@ def post_view(request):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^view/$', view),
|
path('view/', view),
|
||||||
url(r'^session-view/$', session_view),
|
path('session-view/', session_view),
|
||||||
url(r'^redirect-view/$', redirect_view),
|
path('redirect-view/', redirect_view),
|
||||||
url(r'^post-view/$', post_view)
|
path('post-view/', post_view)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ class TestAPIRequestFactory(TestCase):
|
||||||
|
|
||||||
class TestUrlPatternTestCase(URLPatternsTestCase):
|
class TestUrlPatternTestCase(URLPatternsTestCase):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', view),
|
path('', view),
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from django.conf.urls import include, url
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import Resolver404, URLResolver, path, re_path
|
from django.urls import Resolver404, URLResolver, include, path, re_path
|
||||||
from django.urls.resolvers import RegexPattern
|
from django.urls.resolvers import RegexPattern
|
||||||
|
|
||||||
from rest_framework.test import APIRequestFactory
|
from rest_framework.test import APIRequestFactory
|
||||||
|
@ -61,7 +60,7 @@ class FormatSuffixTests(TestCase):
|
||||||
|
|
||||||
def test_trailing_slash(self):
|
def test_trailing_slash(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^test/$', dummy_view),
|
path('test/', dummy_view),
|
||||||
]
|
]
|
||||||
self._test_trailing_slash(urlpatterns)
|
self._test_trailing_slash(urlpatterns)
|
||||||
|
|
||||||
|
@ -81,7 +80,7 @@ class FormatSuffixTests(TestCase):
|
||||||
|
|
||||||
def test_format_suffix(self):
|
def test_format_suffix(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^test$', dummy_view),
|
path('test', dummy_view),
|
||||||
]
|
]
|
||||||
self._test_format_suffix(urlpatterns)
|
self._test_format_suffix(urlpatterns)
|
||||||
|
|
||||||
|
@ -116,7 +115,7 @@ class FormatSuffixTests(TestCase):
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^test$', dummy_view, {'foo': 'bar'}),
|
path('test', dummy_view, {'foo': 'bar'}),
|
||||||
]
|
]
|
||||||
self._test_default_args(urlpatterns)
|
self._test_default_args(urlpatterns)
|
||||||
|
|
||||||
|
@ -135,15 +134,6 @@ class FormatSuffixTests(TestCase):
|
||||||
self._resolve_urlpatterns(urlpatterns, test_paths)
|
self._resolve_urlpatterns(urlpatterns, test_paths)
|
||||||
|
|
||||||
def test_included_urls(self):
|
def test_included_urls(self):
|
||||||
nested_patterns = [
|
|
||||||
url(r'^path$', dummy_view)
|
|
||||||
]
|
|
||||||
urlpatterns = [
|
|
||||||
url(r'^test/', include(nested_patterns), {'foo': 'bar'}),
|
|
||||||
]
|
|
||||||
self._test_included_urls(urlpatterns)
|
|
||||||
|
|
||||||
def test_included_urls_django2(self):
|
|
||||||
nested_patterns = [
|
nested_patterns = [
|
||||||
path('path', dummy_view)
|
path('path', dummy_view)
|
||||||
]
|
]
|
||||||
|
@ -152,44 +142,35 @@ class FormatSuffixTests(TestCase):
|
||||||
]
|
]
|
||||||
self._test_included_urls(urlpatterns)
|
self._test_included_urls(urlpatterns)
|
||||||
|
|
||||||
def test_included_urls_django2_mixed(self):
|
def test_included_urls_mixed(self):
|
||||||
nested_patterns = [
|
|
||||||
path('path', dummy_view)
|
|
||||||
]
|
|
||||||
urlpatterns = [
|
|
||||||
url('^test/', include(nested_patterns), {'foo': 'bar'}),
|
|
||||||
]
|
|
||||||
self._test_included_urls(urlpatterns)
|
|
||||||
|
|
||||||
def test_included_urls_django2_mixed_args(self):
|
|
||||||
nested_patterns = [
|
nested_patterns = [
|
||||||
path('path/<int:child>', dummy_view),
|
path('path/<int:child>', dummy_view),
|
||||||
url('^url/(?P<child>[0-9]+)$', dummy_view)
|
re_path(r'^re_path/(?P<child>[0-9]+)$', dummy_view)
|
||||||
]
|
]
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url('^purl/(?P<parent>[0-9]+)/', include(nested_patterns), {'foo': 'bar'}),
|
re_path(r'^pre_path/(?P<parent>[0-9]+)/', include(nested_patterns), {'foo': 'bar'}),
|
||||||
path('ppath/<int:parent>/', include(nested_patterns), {'foo': 'bar'}),
|
path('ppath/<int:parent>/', include(nested_patterns), {'foo': 'bar'}),
|
||||||
]
|
]
|
||||||
test_paths = [
|
test_paths = [
|
||||||
# parent url() nesting child path()
|
# parent re_path() nesting child path()
|
||||||
URLTestPath('/purl/87/path/42', (), {'parent': '87', 'child': 42, 'foo': 'bar', }),
|
URLTestPath('/pre_path/87/path/42', (), {'parent': '87', 'child': 42, 'foo': 'bar', }),
|
||||||
URLTestPath('/purl/87/path/42.api', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'api'}),
|
URLTestPath('/pre_path/87/path/42.api', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'api'}),
|
||||||
URLTestPath('/purl/87/path/42.asdf', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
|
URLTestPath('/pre_path/87/path/42.asdf', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
|
||||||
|
|
||||||
# parent path() nesting child url()
|
# parent path() nesting child re_path()
|
||||||
URLTestPath('/ppath/87/url/42', (), {'parent': 87, 'child': '42', 'foo': 'bar', }),
|
URLTestPath('/ppath/87/re_path/42', (), {'parent': 87, 'child': '42', 'foo': 'bar', }),
|
||||||
URLTestPath('/ppath/87/url/42.api', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'api'}),
|
URLTestPath('/ppath/87/re_path/42.api', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'api'}),
|
||||||
URLTestPath('/ppath/87/url/42.asdf', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
|
URLTestPath('/ppath/87/re_path/42.asdf', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
|
||||||
|
|
||||||
# parent path() nesting child path()
|
# parent path() nesting child path()
|
||||||
URLTestPath('/ppath/87/path/42', (), {'parent': 87, 'child': 42, 'foo': 'bar', }),
|
URLTestPath('/ppath/87/path/42', (), {'parent': 87, 'child': 42, 'foo': 'bar', }),
|
||||||
URLTestPath('/ppath/87/path/42.api', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'api'}),
|
URLTestPath('/ppath/87/path/42.api', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'api'}),
|
||||||
URLTestPath('/ppath/87/path/42.asdf', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
|
URLTestPath('/ppath/87/path/42.asdf', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
|
||||||
|
|
||||||
# parent url() nesting child url()
|
# parent re_path() nesting child re_path()
|
||||||
URLTestPath('/purl/87/url/42', (), {'parent': '87', 'child': '42', 'foo': 'bar', }),
|
URLTestPath('/pre_path/87/re_path/42', (), {'parent': '87', 'child': '42', 'foo': 'bar', }),
|
||||||
URLTestPath('/purl/87/url/42.api', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'api'}),
|
URLTestPath('/pre_path/87/re_path/42.api', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'api'}),
|
||||||
URLTestPath('/purl/87/url/42.asdf', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
|
URLTestPath('/pre_path/87/re_path/42.asdf', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
|
||||||
]
|
]
|
||||||
self._resolve_urlpatterns(urlpatterns, test_paths)
|
self._resolve_urlpatterns(urlpatterns, test_paths)
|
||||||
|
|
||||||
|
@ -202,13 +183,13 @@ class FormatSuffixTests(TestCase):
|
||||||
]
|
]
|
||||||
self._resolve_urlpatterns(urlpatterns, test_paths, allowed=allowed_formats)
|
self._resolve_urlpatterns(urlpatterns, test_paths, allowed=allowed_formats)
|
||||||
|
|
||||||
def test_allowed_formats(self):
|
def test_allowed_formats_re_path(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url('^test$', dummy_view),
|
re_path(r'^test$', dummy_view),
|
||||||
]
|
]
|
||||||
self._test_allowed_formats(urlpatterns)
|
self._test_allowed_formats(urlpatterns)
|
||||||
|
|
||||||
def test_allowed_formats_django2(self):
|
def test_allowed_formats_path(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('test', dummy_view),
|
path('test', dummy_view),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from django.conf.urls import url
|
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.routers import SimpleRouter
|
from rest_framework.routers import SimpleRouter
|
||||||
|
@ -64,12 +64,12 @@ class ResourceViewSet(ModelViewSet):
|
||||||
router = SimpleRouter()
|
router = SimpleRouter()
|
||||||
router.register(r'resources', ResourceViewSet)
|
router.register(r'resources', ResourceViewSet)
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', Root.as_view()),
|
path('', Root.as_view()),
|
||||||
url(r'^resource/$', ResourceRoot.as_view()),
|
path('resource/', ResourceRoot.as_view()),
|
||||||
url(r'^resource/customname$', CustomNameResourceInstance.as_view()),
|
path('resource/customname', CustomNameResourceInstance.as_view()),
|
||||||
url(r'^resource/(?P<key>[0-9]+)$', ResourceInstance.as_view()),
|
path('resource/<int:key>', ResourceInstance.as_view()),
|
||||||
url(r'^resource/(?P<key>[0-9]+)/$', NestedResourceRoot.as_view()),
|
path('resource/<int:key>/', NestedResourceRoot.as_view()),
|
||||||
url(r'^resource/(?P<key>[0-9]+)/(?P<other>[A-Za-z]+)$', NestedResourceInstance.as_view()),
|
path('resource/<int:key>/<str:other>', NestedResourceInstance.as_view()),
|
||||||
]
|
]
|
||||||
urlpatterns += router.urls
|
urlpatterns += router.urls
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import include, url
|
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
from django.urls import include, path, re_path
|
||||||
|
|
||||||
from rest_framework import serializers, status, versioning
|
from rest_framework import serializers, status, versioning
|
||||||
from rest_framework.decorators import APIView
|
from rest_framework.decorators import APIView
|
||||||
|
@ -144,14 +144,14 @@ class TestRequestVersion:
|
||||||
|
|
||||||
class TestURLReversing(URLPatternsTestCase, APITestCase):
|
class TestURLReversing(URLPatternsTestCase, APITestCase):
|
||||||
included = [
|
included = [
|
||||||
url(r'^namespaced/$', dummy_view, name='another'),
|
path('namespaced/', dummy_view, name='another'),
|
||||||
url(r'^example/(?P<pk>\d+)/$', dummy_pk_view, name='example-detail')
|
path('example/<int:pk>/', dummy_pk_view, name='example-detail')
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^v1/', include((included, 'v1'), namespace='v1')),
|
path('v1/', include((included, 'v1'), namespace='v1')),
|
||||||
url(r'^another/$', dummy_view, name='another'),
|
path('another/', dummy_view, name='another'),
|
||||||
url(r'^(?P<version>[v1|v2]+)/another/$', dummy_view, name='another'),
|
re_path(r'^(?P<version>[v1|v2]+)/another/$', dummy_view, name='another'),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_reverse_unversioned(self):
|
def test_reverse_unversioned(self):
|
||||||
|
@ -310,12 +310,12 @@ class TestAllowedAndDefaultVersion:
|
||||||
|
|
||||||
class TestHyperlinkedRelatedField(URLPatternsTestCase, APITestCase):
|
class TestHyperlinkedRelatedField(URLPatternsTestCase, APITestCase):
|
||||||
included = [
|
included = [
|
||||||
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'),
|
path('namespaced/<int:pk>/', dummy_pk_view, name='namespaced'),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^v1/', include((included, 'v1'), namespace='v1')),
|
path('v1/', include((included, 'v1'), namespace='v1')),
|
||||||
url(r'^v2/', include((included, 'v2'), namespace='v2'))
|
path('v2/', include((included, 'v2'), namespace='v2'))
|
||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -342,17 +342,17 @@ class TestHyperlinkedRelatedField(URLPatternsTestCase, APITestCase):
|
||||||
|
|
||||||
class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase, APITestCase):
|
class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase, APITestCase):
|
||||||
nested = [
|
nested = [
|
||||||
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='nested'),
|
path('namespaced/<int:pk>/', dummy_pk_view, name='nested'),
|
||||||
]
|
]
|
||||||
included = [
|
included = [
|
||||||
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'),
|
path('namespaced/<int:pk>/', dummy_pk_view, name='namespaced'),
|
||||||
url(r'^nested/', include((nested, 'nested-namespace'), namespace='nested-namespace'))
|
path('nested/', include((nested, 'nested-namespace'), namespace='nested-namespace'))
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^v1/', include((included, 'restframeworkv1'), namespace='v1')),
|
path('v1/', include((included, 'restframeworkv1'), namespace='v1')),
|
||||||
url(r'^v2/', include((included, 'restframeworkv2'), namespace='v2')),
|
path('v2/', include((included, 'restframeworkv2'), namespace='v2')),
|
||||||
url(r'^non-api/(?P<pk>\d+)/$', dummy_pk_view, name='non-api-view')
|
path('non-api/<int:pk>/', dummy_pk_view, name='non-api-view')
|
||||||
]
|
]
|
||||||
|
|
||||||
def _create_field(self, view_name, version):
|
def _create_field(self, view_name, version):
|
||||||
|
|
|
@ -2,9 +2,9 @@ from collections import OrderedDict
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import include, url
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
from django.urls import include, path
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
@ -124,7 +124,7 @@ router.register(r'mapping', ActionViewSetWithMapping, basename='mapping')
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^api/', include(router.urls)),
|
path('api/', include(router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,14 @@ URLConf for test suite.
|
||||||
|
|
||||||
We need only the docs urls for DocumentationRenderer tests.
|
We need only the docs urls for DocumentationRenderer tests.
|
||||||
"""
|
"""
|
||||||
from django.conf.urls import url
|
from django.urls import path
|
||||||
|
|
||||||
from rest_framework.compat import coreapi
|
from rest_framework.compat import coreapi
|
||||||
from rest_framework.documentation import include_docs_urls
|
from rest_framework.documentation import include_docs_urls
|
||||||
|
|
||||||
if coreapi:
|
if coreapi:
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^docs/', include_docs_urls(title='Test Suite API')),
|
path('docs/', include_docs_urls(title='Test Suite API')),
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
urlpatterns = []
|
urlpatterns = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user