mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 08:29:59 +03:00
Failing test case for hyperlinked generic related fields.
If the correct view_name is given to the ManyHyperlinkedRelatedField ('bookmarks-detail'), the test passes, though of course this only works because the test relationship is a Bookmark. When it does work, the returned URLs are not absolute ("http://testserver/..."). I assume this is because no real request/response context exists.
This commit is contained in:
parent
b7abf14d3a
commit
d5e6284df3
|
@ -1,9 +1,23 @@
|
|||
from django.test import TestCase
|
||||
from rest_framework import serializers
|
||||
from rest_framework import serializers, generics
|
||||
from rest_framework.tests.models import *
|
||||
from rest_framework.compat import patterns, url
|
||||
|
||||
|
||||
class BookmarkDetail(generics.RetrieveAPIView):
|
||||
model = ManyToManyModel
|
||||
serializer_class = serializers.HyperlinkedModelSerializer
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^bookmark/(?P<pk>\d+)/$', BookmarkDetail.as_view(), name='bookmarks-detail'),
|
||||
)
|
||||
|
||||
|
||||
class TestGenericRelations(TestCase):
|
||||
|
||||
urls = 'rest_framework.tests.genericrelations'
|
||||
|
||||
def setUp(self):
|
||||
bookmark = Bookmark(url='https://www.djangoproject.com/')
|
||||
bookmark.save()
|
||||
|
@ -31,3 +45,18 @@ class TestGenericRelations(TestCase):
|
|||
'url': u'https://www.djangoproject.com/'
|
||||
}
|
||||
self.assertEquals(serializer.data, expected)
|
||||
|
||||
def test_hyperlinked_generic_relation(self):
|
||||
|
||||
class BookmarkSerializer(serializers.ModelSerializer):
|
||||
tags = serializers.ManyHyperlinkedRelatedField(source='tags')
|
||||
|
||||
class Meta:
|
||||
model = Bookmark
|
||||
exclude = ('id', 'url')
|
||||
|
||||
serializer = BookmarkSerializer(self.bookmark)
|
||||
expected = {
|
||||
'tags': [u'/bookmark/1/', u'/bookmark/2/']
|
||||
}
|
||||
self.assertEquals(serializer.data, expected)
|
||||
|
|
Loading…
Reference in New Issue
Block a user