mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 18:13:57 +03:00
36 lines
1019 B
Python
36 lines
1019 B
Python
from django.conf.urls.defaults import patterns, url
|
|
from django.test import TestCase
|
|
from django.utils import simplejson as json
|
|
|
|
from djangorestframework.renderers import JSONRenderer
|
|
from djangorestframework.reverse import reverse
|
|
from djangorestframework.views import View
|
|
from djangorestframework.response import Response
|
|
|
|
|
|
class MyView(View):
|
|
"""
|
|
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('',
|
|
url(r'^myview$', MyView.as_view(), name='myview'),
|
|
)
|
|
|
|
|
|
class ReverseTests(TestCase):
|
|
"""
|
|
Tests for fully qualifed URLs when using `reverse`.
|
|
"""
|
|
urls = 'djangorestframework.tests.reverse'
|
|
|
|
def test_reversed_urls_are_fully_qualified(self):
|
|
response = self.client.get('/myview')
|
|
self.assertEqual(json.loads(response.content), 'http://testserver/myview')
|