django-rest-framework/djangorestframework/tests/reverse.py

36 lines
1.0 KiB
Python
Raw Normal View History

from django.conf.urls.defaults import patterns, url
from django.test import TestCase
from django.utils import simplejson as json
2012-02-22 00:57:36 +04:00
from djangorestframework.renderers import JSONRenderer
from djangorestframework.reverse import reverse
2012-09-03 19:54:17 +04:00
from djangorestframework.views import APIView
from djangorestframework.response import Response
2012-09-03 19:54:17 +04:00
class MyView(APIView):
2012-02-22 00:57:36 +04:00
"""
Mock resource which simply returns a URL, so that we can ensure
that reversed URLs are fully qualified.
"""
renderers = (JSONRenderer, )
def get(self, request):
2012-02-25 22:45:17 +04:00
return Response(reverse('myview', request=request))
urlpatterns = patterns('',
2012-02-22 00:57:36 +04:00
url(r'^myview$', MyView.as_view(), name='myview'),
)
class ReverseTests(TestCase):
2012-02-22 00:57:36 +04:00
"""
Tests for fully qualifed URLs when using `reverse`.
"""
urls = 'djangorestframework.tests.reverse'
def test_reversed_urls_are_fully_qualified(self):
2012-02-22 00:57:36 +04:00
response = self.client.get('/myview')
self.assertEqual(json.loads(response.content), 'http://testserver/myview')