mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Update versioning tests w/ new URLPatternsTestCase
This commit is contained in:
parent
c490e5ac9c
commit
44c2a5ce39
|
@ -7,33 +7,12 @@ from rest_framework.decorators import APIView
|
|||
from rest_framework.relations import PKOnlyObject
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.reverse import reverse
|
||||
from rest_framework.test import APIRequestFactory, APITestCase
|
||||
from rest_framework.test import (
|
||||
APIRequestFactory, APITestCase, URLPatternsTestCase
|
||||
)
|
||||
from rest_framework.versioning import NamespaceVersioning
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='tests.test_versioning')
|
||||
class URLPatternsTestCase(APITestCase):
|
||||
"""
|
||||
Isolates URL patterns used during testing on the test class itself.
|
||||
For example:
|
||||
|
||||
class MyTestCase(URLPatternsTestCase):
|
||||
urlpatterns = [
|
||||
...
|
||||
]
|
||||
|
||||
def test_something(self):
|
||||
...
|
||||
"""
|
||||
def setUp(self):
|
||||
global urlpatterns
|
||||
urlpatterns = self.urlpatterns
|
||||
|
||||
def tearDown(self):
|
||||
global urlpatterns
|
||||
urlpatterns = []
|
||||
|
||||
|
||||
class RequestVersionView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
return Response({'version': request.version})
|
||||
|
@ -163,7 +142,7 @@ class TestRequestVersion:
|
|||
assert response.data == {'version': None}
|
||||
|
||||
|
||||
class TestURLReversing(URLPatternsTestCase):
|
||||
class TestURLReversing(URLPatternsTestCase, APITestCase):
|
||||
included = [
|
||||
url(r'^namespaced/$', dummy_view, name='another'),
|
||||
url(r'^example/(?P<pk>\d+)/$', dummy_pk_view, name='example-detail')
|
||||
|
@ -329,7 +308,7 @@ class TestAllowedAndDefaultVersion:
|
|||
assert response.data == {'version': 'v2'}
|
||||
|
||||
|
||||
class TestHyperlinkedRelatedField(URLPatternsTestCase):
|
||||
class TestHyperlinkedRelatedField(URLPatternsTestCase, APITestCase):
|
||||
included = [
|
||||
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'),
|
||||
]
|
||||
|
@ -361,7 +340,7 @@ class TestHyperlinkedRelatedField(URLPatternsTestCase):
|
|||
self.field.to_internal_value('/v2/namespaced/3/')
|
||||
|
||||
|
||||
class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase):
|
||||
class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase, APITestCase):
|
||||
nested = [
|
||||
url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='nested'),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue
Block a user