Skip to content

Django 2.0a1 compat #5503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rest_framework/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
3 changes: 2 additions & 1 deletion rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import copy
import datetime
import decimal
import functools
import inspect
import re
import uuid
Expand Down Expand Up @@ -54,7 +55,7 @@ def is_simple_callable(obj):
"""
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)
Expand Down
13 changes: 7 additions & 6 deletions tests/test_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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
Expand Down Expand Up @@ -97,7 +98,7 @@ def regex_url_path_detail(self, request, *args, **kwargs):

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

Expand Down Expand Up @@ -176,7 +177,7 @@ def setUp(self):

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):
Expand Down Expand Up @@ -213,7 +214,7 @@ class NoteViewSet(viewsets.ModelViewSet):
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')
Expand All @@ -228,7 +229,7 @@ def setUp(self):

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):
Expand All @@ -252,7 +253,7 @@ class NoteViewSet(viewsets.ModelViewSet):
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):
Expand All @@ -267,7 +268,7 @@ class NoteViewSet(viewsets.ModelViewSet):
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):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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
)
Expand Down Expand Up @@ -689,7 +689,7 @@ def test_should_include_endpoint_excludes_correctly(self):
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 = [
Expand Down
12 changes: 6 additions & 6 deletions tests/test_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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')
]

Expand Down