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

30 lines
913 B
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:12:14 +04:00
from djangorestframework.utils import reverse
from djangorestframework.views import View
from djangorestframework.response import Response
class MockView(View):
"""Mock resource which simply returns a URL, so that we can ensure that reversed URLs are fully qualified"""
permissions = ()
def get(self, request):
2012-02-22 00:12:14 +04:00
return Response(reverse('another', request))
urlpatterns = patterns('',
2011-05-04 12:21:17 +04:00
url(r'^$', MockView.as_view()),
url(r'^another$', MockView.as_view(), name='another'),
)
class ReverseTests(TestCase):
"""Tests for """
urls = 'djangorestframework.tests.reverse'
def test_reversed_urls_are_fully_qualified(self):
2011-06-28 11:53:53 +04:00
response = self.client.get('/')
self.assertEqual(json.loads(response.content), 'http://testserver/another')