mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-24 23:19:47 +03:00
fixed url test cases
This commit is contained in:
parent
f2cebb117a
commit
5743e50690
|
@ -27,7 +27,7 @@ class PhotoSerializer(serializers.Serializer):
|
||||||
|
|
||||||
|
|
||||||
class PhotoUrlSerializer(PhotoSerializer):
|
class PhotoUrlSerializer(PhotoSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='photoswithabsoluteurls-detail', use_absolute_urls=True)
|
url = serializers.HyperlinkedIdentityField(view_name='photoswithmixedurls-detail', use_absolute_urls=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Photo
|
model = Photo
|
||||||
|
@ -108,8 +108,8 @@ urlpatterns = patterns('',
|
||||||
url(r'^comments/(?P<pk>\d+)/$', BlogPostCommentDetail.as_view(), name='blogpostcomment-detail'),
|
url(r'^comments/(?P<pk>\d+)/$', BlogPostCommentDetail.as_view(), name='blogpostcomment-detail'),
|
||||||
url(r'^albums/(?P<title>\w[\w-]*)/$', AlbumDetail.as_view(), name='album-detail'),
|
url(r'^albums/(?P<title>\w[\w-]*)/$', AlbumDetail.as_view(), name='album-detail'),
|
||||||
url(r'^photos/$', PhotoListCreate.as_view(), name='photo-list'),
|
url(r'^photos/$', PhotoListCreate.as_view(), name='photo-list'),
|
||||||
url(r'^photos-with-absolute-urls/$', PhotoAbsoluteUrlList.as_view(), name='photoswithabsoluteurls-list'),
|
url(r'^photos-with-mixed-urls/$', PhotoUrlList.as_view(), name='photoswithmixedurls-list'),
|
||||||
url(r'^photos-with-absolute-urls/(?P<pk>\d+)/$', PhotoAbsoluteUrlDetail.as_view(), name='photoswithabsoluteurls-detail'),
|
url(r'^photos-with-mixed-urls/(?P<pk>\d+)/$', PhotoUrlDetail.as_view(), name='photoswithmixedurls-detail'),
|
||||||
url(r'^optionalrelation/(?P<pk>\d+)/$', OptionalRelationDetail.as_view(), name='optionalrelationmodel-detail'),
|
url(r'^optionalrelation/(?P<pk>\d+)/$', OptionalRelationDetail.as_view(), name='optionalrelationmodel-detail'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -289,28 +289,38 @@ class TestUrlOptionsView(TestCase):
|
||||||
"""
|
"""
|
||||||
Create a album and photos
|
Create a album and photos
|
||||||
"""
|
"""
|
||||||
self.album = Album.objects.create(title="Test album")
|
self.album = Album.objects.create(title="test-album")
|
||||||
items = ['beach', 'sunset', 'moon']
|
items = ['beach', 'sunset', 'moon']
|
||||||
for item in items:
|
for item in items:
|
||||||
Photo(description=item, album=self.album).save()
|
Photo(description=item, album=self.album).save()
|
||||||
self.objects = Photo.objects
|
self.objects = Photo.objects
|
||||||
self.data = [
|
self.data = [
|
||||||
{
|
{
|
||||||
'url': '/photos-with-absolute-urls/%d/' % obj.id,
|
'url': 'http://testserver/photos-with-mixed-urls/%d/' % obj.id,
|
||||||
'description': obj.text,
|
'description': obj.description,
|
||||||
'album_url': 'http://testserver/optionalrelation/%d/' % obj.album
|
'album_url': '/albums/%s/' % obj.album.title
|
||||||
}
|
}
|
||||||
for obj in self.objects.all()
|
for obj in self.objects.all()
|
||||||
]
|
]
|
||||||
self.list_view = PhotoUrlList.as_view()
|
self.list_view = PhotoUrlList.as_view()
|
||||||
self.detail_view = PhotoUrlDetail.as_view()
|
self.detail_view = PhotoUrlDetail.as_view()
|
||||||
|
|
||||||
|
def test_get_list_view(self):
|
||||||
|
"""
|
||||||
|
GET requests to RetrieveAPIView with optional relations should return None
|
||||||
|
for non existing relations.
|
||||||
|
"""
|
||||||
|
request = factory.get('/photos-with-mixed-urls/')
|
||||||
|
response = self.list_view(request)
|
||||||
|
self.assertEquals(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEquals(response.data, self.data[:])
|
||||||
|
|
||||||
def test_get_detail_view(self):
|
def test_get_detail_view(self):
|
||||||
"""
|
"""
|
||||||
GET requests to RetrieveAPIView with optional relations should return None
|
GET requests to RetrieveAPIView with optional relations should return None
|
||||||
for non existing relations.
|
for non existing relations.
|
||||||
"""
|
"""
|
||||||
request = factory.get('/photos-with-absolute-urls/1')
|
request = factory.get('/photos-with-mixed-urls/1/')
|
||||||
response = self.detail_view(request)
|
response = self.detail_view(request, pk=1)
|
||||||
self.assertEquals(response.status_code, status.HTTP_200_OK)
|
self.assertEquals(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertEquals(response.data, self.data[0:2])
|
self.assertEquals(response.data, self.data[0])
|
Loading…
Reference in New Issue
Block a user