2011-02-19 13:26:27 +03:00
|
|
|
from django.conf.urls.defaults import patterns, url
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.test import TestCase
|
2011-04-25 07:50:28 +04:00
|
|
|
from django.utils import simplejson as json
|
2011-02-19 13:26:27 +03:00
|
|
|
|
2011-05-24 13:27:24 +04:00
|
|
|
from djangorestframework.views import View
|
2011-02-19 13:26:27 +03:00
|
|
|
|
|
|
|
|
2011-05-24 13:27:24 +04:00
|
|
|
class MockView(View):
|
2011-02-19 13:26:27 +03:00
|
|
|
"""Mock resource which simply returns a URL, so that we can ensure that reversed URLs are fully qualified"""
|
2011-04-25 04:03:23 +04:00
|
|
|
permissions = ()
|
2011-02-19 13:26:27 +03:00
|
|
|
|
2011-04-11 20:13:11 +04:00
|
|
|
def get(self, request):
|
2011-02-19 13:26:27 +03:00
|
|
|
return reverse('another')
|
|
|
|
|
|
|
|
urlpatterns = patterns('',
|
2011-05-04 12:21:17 +04:00
|
|
|
url(r'^$', MockView.as_view()),
|
|
|
|
url(r'^another$', MockView.as_view(), name='another'),
|
2011-02-19 13:26:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ReverseTests(TestCase):
|
|
|
|
"""Tests for """
|
|
|
|
urls = 'djangorestframework.tests.reverse'
|
|
|
|
|
|
|
|
def test_reversed_urls_are_fully_qualified(self):
|
2011-04-25 04:03:23 +04:00
|
|
|
try:
|
|
|
|
response = self.client.get('/')
|
|
|
|
except:
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
2011-02-19 13:26:27 +03:00
|
|
|
self.assertEqual(json.loads(response.content), 'http://testserver/another')
|