Skip to content

Commit c7fb60b

Browse files
author
Carlton Gibson
authored
Django 2.0a1 compat (#5503)
* Update remaing `include` calls Missed as part of #5481 cleanup. * Provide app_name in include_docs_urls * Update remaining get_regex_pattern usages * Allow functools.partial in is_simple_callable check
1 parent cbfa444 commit c7fb60b

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

rest_framework/documentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ def include_docs_urls(
7676
url(r'^$', docs_view, name='docs-index'),
7777
url(r'^schema.js$', schema_js_view, name='schema-js')
7878
]
79-
return include(urls, namespace='api-docs')
79+
return include((urls, 'api-docs'), namespace='api-docs')

rest_framework/fields.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import copy
55
import datetime
66
import decimal
7+
import functools
78
import inspect
89
import re
910
import uuid
@@ -54,7 +55,7 @@ def is_simple_callable(obj):
5455
"""
5556
True if the object is a callable that takes no arguments.
5657
"""
57-
if not (inspect.isfunction(obj) or inspect.ismethod(obj)):
58+
if not (inspect.isfunction(obj) or inspect.ismethod(obj) or isinstance(obj, functools.partial)):
5859
return False
5960

6061
sig = inspect.signature(obj)

tests/test_routers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.test import TestCase, override_settings
1010

1111
from rest_framework import permissions, serializers, viewsets
12+
from rest_framework.compat import get_regex_pattern
1213
from rest_framework.decorators import detail_route, list_route
1314
from rest_framework.response import Response
1415
from rest_framework.routers import DefaultRouter, SimpleRouter
@@ -97,7 +98,7 @@ def regex_url_path_detail(self, request, *args, **kwargs):
9798

9899
urlpatterns = [
99100
url(r'^non-namespaced/', include(namespaced_router.urls)),
100-
url(r'^namespaced/', include(namespaced_router.urls, namespace='example', app_name='example')),
101+
url(r'^namespaced/', include((namespaced_router.urls, 'example'), namespace='example')),
101102
url(r'^example/', include(notes_router.urls)),
102103
url(r'^example2/', include(kwarged_notes_router.urls)),
103104

@@ -176,7 +177,7 @@ def setUp(self):
176177

177178
def test_custom_lookup_field_route(self):
178179
detail_route = notes_router.urls[-1]
179-
detail_url_pattern = detail_route.regex.pattern
180+
detail_url_pattern = get_regex_pattern(detail_route)
180181
assert '<uuid>' in detail_url_pattern
181182

182183
def test_retrieve_lookup_field_list_view(self):
@@ -213,7 +214,7 @@ class NoteViewSet(viewsets.ModelViewSet):
213214
def test_urls_limited_by_lookup_value_regex(self):
214215
expected = ['^notes/$', '^notes/(?P<uuid>[0-9a-f]{32})/$']
215216
for idx in range(len(expected)):
216-
assert expected[idx] == self.urls[idx].regex.pattern
217+
assert expected[idx] == get_regex_pattern(self.urls[idx])
217218

218219

219220
@override_settings(ROOT_URLCONF='tests.test_routers')
@@ -228,7 +229,7 @@ def setUp(self):
228229

229230
def test_custom_lookup_url_kwarg_route(self):
230231
detail_route = kwarged_notes_router.urls[-1]
231-
detail_url_pattern = detail_route.regex.pattern
232+
detail_url_pattern = get_regex_pattern(detail_route)
232233
assert '^notes/(?P<text>' in detail_url_pattern
233234

234235
def test_retrieve_lookup_url_kwarg_detail_view(self):
@@ -252,7 +253,7 @@ class NoteViewSet(viewsets.ModelViewSet):
252253
def test_urls_have_trailing_slash_by_default(self):
253254
expected = ['^notes/$', '^notes/(?P<pk>[^/.]+)/$']
254255
for idx in range(len(expected)):
255-
assert expected[idx] == self.urls[idx].regex.pattern
256+
assert expected[idx] == get_regex_pattern(self.urls[idx])
256257

257258

258259
class TestTrailingSlashRemoved(TestCase):
@@ -267,7 +268,7 @@ class NoteViewSet(viewsets.ModelViewSet):
267268
def test_urls_can_have_trailing_slash_removed(self):
268269
expected = ['^notes$', '^notes/(?P<pk>[^/.]+)$']
269270
for idx in range(len(expected)):
270-
assert expected[idx] == self.urls[idx].regex.pattern
271+
assert expected[idx] == get_regex_pattern(self.urls[idx])
271272

272273

273274
class TestNameableRoot(TestCase):

tests/test_schemas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rest_framework import (
1010
filters, generics, pagination, permissions, serializers
1111
)
12-
from rest_framework.compat import coreapi, coreschema
12+
from rest_framework.compat import coreapi, coreschema, get_regex_pattern
1313
from rest_framework.decorators import (
1414
api_view, detail_route, list_route, schema
1515
)
@@ -689,7 +689,7 @@ def test_should_include_endpoint_excludes_correctly(self):
689689
inspector = EndpointEnumerator(self.patterns)
690690

691691
# Not pretty. Mimics internals of EndpointEnumerator to put should_include_endpoint under test
692-
pairs = [(inspector.get_path_from_regex(pattern.regex.pattern), pattern.callback)
692+
pairs = [(inspector.get_path_from_regex(get_regex_pattern(pattern)), pattern.callback)
693693
for pattern in self.patterns]
694694

695695
should_include = [

tests/test_versioning.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class TestURLReversing(URLPatternsTestCase):
170170
]
171171

172172
urlpatterns = [
173-
url(r'^v1/', include(included, namespace='v1', app_name='v1')),
173+
url(r'^v1/', include((included, 'v1'), namespace='v1')),
174174
url(r'^another/$', dummy_view, name='another'),
175175
url(r'^(?P<version>[v1|v2]+)/another/$', dummy_view, name='another'),
176176
]
@@ -335,8 +335,8 @@ class TestHyperlinkedRelatedField(URLPatternsTestCase):
335335
]
336336

337337
urlpatterns = [
338-
url(r'^v1/', include(included, namespace='v1', app_name='v1')),
339-
url(r'^v2/', include(included, namespace='v2', app_name='v2'))
338+
url(r'^v1/', include((included, 'v1'), namespace='v1')),
339+
url(r'^v2/', include((included, 'v2'), namespace='v2'))
340340
]
341341

342342
def setUp(self):
@@ -367,12 +367,12 @@ class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase):
367367
]
368368
included = [
369369
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'),
370-
url(r'^nested/', include(nested, namespace='nested-namespace', app_name='nested-namespace'))
370+
url(r'^nested/', include((nested, 'nested-namespace'), namespace='nested-namespace'))
371371
]
372372

373373
urlpatterns = [
374-
url(r'^v1/', include(included, namespace='v1', app_name='restframeworkv1')),
375-
url(r'^v2/', include(included, namespace='v2', app_name='restframeworkv2')),
374+
url(r'^v1/', include((included, 'restframeworkv1'), namespace='v1')),
375+
url(r'^v2/', include((included, 'restframeworkv2'), namespace='v2')),
376376
url(r'^non-api/(?P<pk>\d+)/$', dummy_pk_view, name='non-api-view')
377377
]
378378

0 commit comments

Comments
 (0)