mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Clean up reverse tests
This commit is contained in:
parent
c2bbe628e6
commit
6cf2874cf2
|
@ -1,26 +1,16 @@
|
||||||
from django.conf.urls.defaults import patterns, url
|
from django.conf.urls.defaults import patterns, url
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils import simplejson as json
|
from django.test.client import RequestFactory
|
||||||
|
|
||||||
from rest_framework.renderers import JSONRenderer
|
|
||||||
from rest_framework.reverse import reverse
|
from rest_framework.reverse import reverse
|
||||||
from rest_framework.views import APIView
|
|
||||||
from rest_framework.response import Response
|
factory = RequestFactory()
|
||||||
|
|
||||||
|
|
||||||
class MyView(APIView):
|
def null_view(request):
|
||||||
"""
|
pass
|
||||||
Mock resource which simply returns a URL, so that we can ensure
|
|
||||||
that reversed URLs are fully qualified.
|
|
||||||
"""
|
|
||||||
renderers = (JSONRenderer, )
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
return Response(reverse('myview', request=request))
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^myview$', MyView.as_view(), name='myview'),
|
url(r'^view$', null_view, name='view'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,5 +21,6 @@ class ReverseTests(TestCase):
|
||||||
urls = 'rest_framework.tests.reverse'
|
urls = 'rest_framework.tests.reverse'
|
||||||
|
|
||||||
def test_reversed_urls_are_fully_qualified(self):
|
def test_reversed_urls_are_fully_qualified(self):
|
||||||
response = self.client.get('/myview')
|
request = factory.get('/view')
|
||||||
self.assertEqual(json.loads(response.content), 'http://testserver/myview')
|
url = reverse('view', request=request)
|
||||||
|
self.assertEqual(url, 'http://testserver/view')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user