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
This commit is contained in:
Carlton Gibson 2017-10-16 11:31:13 +02:00 committed by GitHub
parent cbfa444454
commit c7fb60bcd4
5 changed files with 18 additions and 16 deletions

View File

@ -76,4 +76,4 @@ def include_docs_urls(
url(r'^$', docs_view, name='docs-index'),
url(r'^schema.js$', schema_js_view, name='schema-js')
]
return include(urls, namespace='api-docs')
return include((urls, 'api-docs'), namespace='api-docs')

View File

@ -4,6 +4,7 @@ import collections
import copy
import datetime
import decimal
import functools
import inspect
import re
import uuid
@ -54,7 +55,7 @@ if six.PY3:
"""
True if the object is a callable that takes no arguments.
"""
if not (inspect.isfunction(obj) or inspect.ismethod(obj)):
if not (inspect.isfunction(obj) or inspect.ismethod(obj) or isinstance(obj, functools.partial)):
return False
sig = inspect.signature(obj)

View File

@ -9,6 +9,7 @@ from django.db import models
from django.test import TestCase, override_settings
from rest_framework import permissions, serializers, viewsets
from rest_framework.compat import get_regex_pattern
from rest_framework.decorators import detail_route, list_route
from rest_framework.response import Response
from rest_framework.routers import DefaultRouter, SimpleRouter
@ -97,7 +98,7 @@ regex_url_path_router.register(r'', RegexUrlPathViewSet, base_name='regex')
urlpatterns = [
url(r'^non-namespaced/', include(namespaced_router.urls)),
url(r'^namespaced/', include(namespaced_router.urls, namespace='example', app_name='example')),
url(r'^namespaced/', include((namespaced_router.urls, 'example'), namespace='example')),
url(r'^example/', include(notes_router.urls)),
url(r'^example2/', include(kwarged_notes_router.urls)),
@ -176,7 +177,7 @@ class TestCustomLookupFields(TestCase):
def test_custom_lookup_field_route(self):
detail_route = notes_router.urls[-1]
detail_url_pattern = detail_route.regex.pattern
detail_url_pattern = get_regex_pattern(detail_route)
assert '<uuid>' in detail_url_pattern
def test_retrieve_lookup_field_list_view(self):
@ -213,7 +214,7 @@ class TestLookupValueRegex(TestCase):
def test_urls_limited_by_lookup_value_regex(self):
expected = ['^notes/$', '^notes/(?P<uuid>[0-9a-f]{32})/$']
for idx in range(len(expected)):
assert expected[idx] == self.urls[idx].regex.pattern
assert expected[idx] == get_regex_pattern(self.urls[idx])
@override_settings(ROOT_URLCONF='tests.test_routers')
@ -228,7 +229,7 @@ class TestLookupUrlKwargs(TestCase):
def test_custom_lookup_url_kwarg_route(self):
detail_route = kwarged_notes_router.urls[-1]
detail_url_pattern = detail_route.regex.pattern
detail_url_pattern = get_regex_pattern(detail_route)
assert '^notes/(?P<text>' in detail_url_pattern
def test_retrieve_lookup_url_kwarg_detail_view(self):
@ -252,7 +253,7 @@ class TestTrailingSlashIncluded(TestCase):
def test_urls_have_trailing_slash_by_default(self):
expected = ['^notes/$', '^notes/(?P<pk>[^/.]+)/$']
for idx in range(len(expected)):
assert expected[idx] == self.urls[idx].regex.pattern
assert expected[idx] == get_regex_pattern(self.urls[idx])
class TestTrailingSlashRemoved(TestCase):
@ -267,7 +268,7 @@ class TestTrailingSlashRemoved(TestCase):
def test_urls_can_have_trailing_slash_removed(self):
expected = ['^notes$', '^notes/(?P<pk>[^/.]+)$']
for idx in range(len(expected)):
assert expected[idx] == self.urls[idx].regex.pattern
assert expected[idx] == get_regex_pattern(self.urls[idx])
class TestNameableRoot(TestCase):

View File

@ -9,7 +9,7 @@ from django.test import TestCase, override_settings
from rest_framework import (
filters, generics, pagination, permissions, serializers
)
from rest_framework.compat import coreapi, coreschema
from rest_framework.compat import coreapi, coreschema, get_regex_pattern
from rest_framework.decorators import (
api_view, detail_route, list_route, schema
)
@ -689,7 +689,7 @@ class SchemaGenerationExclusionTests(TestCase):
inspector = EndpointEnumerator(self.patterns)
# Not pretty. Mimics internals of EndpointEnumerator to put should_include_endpoint under test
pairs = [(inspector.get_path_from_regex(pattern.regex.pattern), pattern.callback)
pairs = [(inspector.get_path_from_regex(get_regex_pattern(pattern)), pattern.callback)
for pattern in self.patterns]
should_include = [

View File

@ -170,7 +170,7 @@ class TestURLReversing(URLPatternsTestCase):
]
urlpatterns = [
url(r'^v1/', include(included, namespace='v1', app_name='v1')),
url(r'^v1/', include((included, 'v1'), namespace='v1')),
url(r'^another/$', dummy_view, name='another'),
url(r'^(?P<version>[v1|v2]+)/another/$', dummy_view, name='another'),
]
@ -335,8 +335,8 @@ class TestHyperlinkedRelatedField(URLPatternsTestCase):
]
urlpatterns = [
url(r'^v1/', include(included, namespace='v1', app_name='v1')),
url(r'^v2/', include(included, namespace='v2', app_name='v2'))
url(r'^v1/', include((included, 'v1'), namespace='v1')),
url(r'^v2/', include((included, 'v2'), namespace='v2'))
]
def setUp(self):
@ -367,12 +367,12 @@ class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase):
]
included = [
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'),
url(r'^nested/', include(nested, namespace='nested-namespace', app_name='nested-namespace'))
url(r'^nested/', include((nested, 'nested-namespace'), namespace='nested-namespace'))
]
urlpatterns = [
url(r'^v1/', include(included, namespace='v1', app_name='restframeworkv1')),
url(r'^v2/', include(included, namespace='v2', app_name='restframeworkv2')),
url(r'^v1/', include((included, 'restframeworkv1'), namespace='v1')),
url(r'^v2/', include((included, 'restframeworkv2'), namespace='v2')),
url(r'^non-api/(?P<pk>\d+)/$', dummy_pk_view, name='non-api-view')
]