mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Update urlpatterns throughout tests
This commit is contained in:
parent
fee200ebf0
commit
ebb92cff78
|
@ -1,4 +1,4 @@
|
|||
from django.conf.urls import url
|
||||
from django.conf.urls import include, url
|
||||
from django.db import models
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
|
@ -28,10 +28,14 @@ def dummy_view(request):
|
|||
pass
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
patterns = [
|
||||
url(r'^example/(?P<pk>[0-9]+)/$', dummy_view, name='example-detail'),
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^', include((patterns, 'rest_framework')))
|
||||
]
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='tests.test_lazy_hyperlinks')
|
||||
class TestLazyHyperlinkNames(TestCase):
|
||||
|
|
|
@ -2,7 +2,7 @@ import uuid
|
|||
|
||||
import pytest
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
from django.conf.urls import url
|
||||
from django.conf.urls import include, url
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import override_settings
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
|
@ -146,7 +146,9 @@ class TestProxiedPrimaryKeyRelatedField(APISimpleTestCase):
|
|||
|
||||
|
||||
@override_settings(ROOT_URLCONF=[
|
||||
url(r'^example/(?P<name>.+)/$', lambda: None, name='example'),
|
||||
url(r'^', include(
|
||||
([url(r'^example/(?P<name>.+)/$', lambda: None, name='example')], 'rest_framework')
|
||||
)),
|
||||
])
|
||||
class TestHyperlinkedRelatedField(APISimpleTestCase):
|
||||
def setUp(self):
|
||||
|
|
|
@ -18,7 +18,7 @@ def dummy_view(request, pk):
|
|||
pass
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
patterns = [
|
||||
url(r'^dummyurl/(?P<pk>[0-9]+)/$', dummy_view, name='dummy-url'),
|
||||
url(r'^manytomanysource/(?P<pk>[0-9]+)/$', dummy_view, name='manytomanysource-detail'),
|
||||
url(r'^manytomanytarget/(?P<pk>[0-9]+)/$', dummy_view, name='manytomanytarget-detail'),
|
||||
|
@ -29,6 +29,10 @@ urlpatterns = [
|
|||
url(r'^nullableonetoonesource/(?P<pk>[0-9]+)/$', dummy_view, name='nullableonetoonesource-detail'),
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^', include((patterns, 'rest_framework')))
|
||||
]
|
||||
|
||||
|
||||
# ManyToMany
|
||||
class ManyToManyTargetSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
@ -473,15 +477,15 @@ class HyperlinkedNamespaceTests(TestCase):
|
|||
assert serializer.data == expected
|
||||
|
||||
def test_foreign_key_retrieve_no_namespace(self):
|
||||
patterns = [
|
||||
url(r'^', include(urlpatterns, namespace=None))
|
||||
url_conf = [
|
||||
url(r'^', include((patterns, 'rest_framework'), namespace=None))
|
||||
]
|
||||
with override_settings(ROOT_URLCONF=patterns):
|
||||
with override_settings(ROOT_URLCONF=url_conf):
|
||||
self.results()
|
||||
|
||||
def test_foreign_key_retrieve_namespace(self):
|
||||
patterns = [
|
||||
url(r'^', include(urlpatterns, namespace='api'))
|
||||
url_conf = [
|
||||
url(r'^', include((patterns, 'rest_framework'), namespace='api'))
|
||||
]
|
||||
with override_settings(ROOT_URLCONF=patterns):
|
||||
with override_settings(ROOT_URLCONF=url_conf):
|
||||
self.results()
|
||||
|
|
|
@ -145,9 +145,9 @@ class TestSimpleRouter(TestCase):
|
|||
|
||||
class TestRootView(URLPatternsTestCase, TestCase):
|
||||
urlpatterns = [
|
||||
url(r'^non-namespaced/', include(namespaced_router.urls)),
|
||||
url(r'^namespaced1/', include((namespaced_router.urls, 'namespaced1'), namespace='namespaced1')),
|
||||
url(r'^namespaced2/', include((namespaced_router.urls, 'namespaced2'), namespace='namespaced2')),
|
||||
url(r'^non-namespaced/', include(namespaced_router.urlpatterns)),
|
||||
url(r'^namespaced1/', include(namespaced_router.urlpatterns, namespace='namespaced1')),
|
||||
url(r'^namespaced2/', include(namespaced_router.urlpatterns, namespace='namespaced2')),
|
||||
]
|
||||
|
||||
def test_retrieve_namespaced_root(self):
|
||||
|
@ -167,8 +167,8 @@ class TestCustomLookupFields(URLPatternsTestCase, TestCase):
|
|||
Ensure that custom lookup fields are correctly routed.
|
||||
"""
|
||||
urlpatterns = [
|
||||
url(r'^example/', include(notes_router.urls)),
|
||||
url(r'^example2/', include(kwarged_notes_router.urls)),
|
||||
url(r'^example/', include(notes_router.urlpatterns)),
|
||||
url(r'^example2/', include(kwarged_notes_router.urlpatterns)),
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -225,8 +225,8 @@ class TestLookupUrlKwargs(URLPatternsTestCase, TestCase):
|
|||
Setup a deep lookup_field, but map it to a simple URL kwarg.
|
||||
"""
|
||||
urlpatterns = [
|
||||
url(r'^example/', include(notes_router.urls)),
|
||||
url(r'^example2/', include(kwarged_notes_router.urls)),
|
||||
url(r'^example/', include(notes_router.urlpatterns)),
|
||||
url(r'^example2/', include(kwarged_notes_router.urlpatterns)),
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -414,7 +414,7 @@ class TestDynamicListAndDetailRouter(TestCase):
|
|||
|
||||
class TestEmptyPrefix(URLPatternsTestCase, TestCase):
|
||||
urlpatterns = [
|
||||
url(r'^empty-prefix/', include(empty_prefix_router.urls)),
|
||||
url(r'^empty-prefix/', include(empty_prefix_router.urlpatterns)),
|
||||
]
|
||||
|
||||
def test_empty_prefix_list(self):
|
||||
|
@ -431,7 +431,7 @@ class TestEmptyPrefix(URLPatternsTestCase, TestCase):
|
|||
|
||||
class TestRegexUrlPath(URLPatternsTestCase, TestCase):
|
||||
urlpatterns = [
|
||||
url(r'^regex/', include(regex_url_path_router.urls)),
|
||||
url(r'^regex/', include(regex_url_path_router.urlpatterns)),
|
||||
]
|
||||
|
||||
def test_regex_url_path_list(self):
|
||||
|
|
|
@ -143,17 +143,21 @@ class TestRequestVersion:
|
|||
|
||||
|
||||
class TestURLReversing(URLPatternsTestCase, APITestCase):
|
||||
included = [
|
||||
versioned = [
|
||||
url(r'^namespaced/$', dummy_view, name='another'),
|
||||
url(r'^example/(?P<pk>\d+)/$', dummy_pk_view, name='example-detail')
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^v1/', include((included, 'v1'), namespace='v1')),
|
||||
included = [
|
||||
url(r'^another/$', dummy_view, name='another'),
|
||||
url(r'^(?P<version>[v1|v2]+)/another/$', dummy_view, name='another'),
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^v1/', include((versioned, 'rest_framework'), namespace='v1')),
|
||||
url(r'^', include((included, 'rest_framework'))),
|
||||
]
|
||||
|
||||
def test_reverse_unversioned(self):
|
||||
view = ReverseView.as_view()
|
||||
|
||||
|
@ -314,8 +318,8 @@ class TestHyperlinkedRelatedField(URLPatternsTestCase, APITestCase):
|
|||
]
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^v1/', include((included, 'v1'), namespace='v1')),
|
||||
url(r'^v2/', include((included, 'v2'), namespace='v2'))
|
||||
url(r'^v1/', include((included, 'rest_framework'), namespace='v1')),
|
||||
url(r'^v2/', include((included, 'rest_framework'), namespace='v2'))
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -344,17 +348,21 @@ class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase,
|
|||
nested = [
|
||||
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='nested'),
|
||||
]
|
||||
included = [
|
||||
versioned = [
|
||||
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'),
|
||||
url(r'^nested/', include((nested, 'nested-namespace'), namespace='nested-namespace'))
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^v1/', include((included, 'restframeworkv1'), namespace='v1')),
|
||||
url(r'^v2/', include((included, 'restframeworkv2'), namespace='v2')),
|
||||
included = [
|
||||
url(r'^non-api/(?P<pk>\d+)/$', dummy_pk_view, name='non-api-view')
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^v1/', include((versioned, 'rest_framework'), namespace='v1')),
|
||||
url(r'^v2/', include((versioned, 'rest_framework'), namespace='v2')),
|
||||
url(r'^', include((included, 'rest_framework'))),
|
||||
]
|
||||
|
||||
def _create_field(self, view_name, version):
|
||||
request = factory.get("/")
|
||||
request.versioning_scheme = NamespaceVersioning()
|
||||
|
@ -381,6 +389,7 @@ class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase,
|
|||
def test_non_api_url_is_properly_reversed_regardless_of_the_version(self):
|
||||
"""
|
||||
Regression test for #2711
|
||||
Note: non-api-views still need to be included in the 'rest_framework' namespace
|
||||
"""
|
||||
field = self._create_field('non-api-view', 'v1')
|
||||
assert field.to_representation(PKOnlyObject(10)) == 'http://testserver/non-api/10/'
|
||||
|
|
|
@ -62,7 +62,7 @@ router.register(r'actions-alt', ActionViewSet, base_name='actions-alt')
|
|||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^api/', include(router.urls)),
|
||||
url(r'^api/', include(router.urlpatterns)),
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user