fixed url test cases

This commit is contained in:
Stephan Groß 2012-12-13 14:04:38 +01:00
parent f2cebb117a
commit 5743e50690

View File

@ -27,7 +27,7 @@ class PhotoSerializer(serializers.Serializer):
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:
model = Photo
@ -108,8 +108,8 @@ urlpatterns = patterns('',
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'^photos/$', PhotoListCreate.as_view(), name='photo-list'),
url(r'^photos-with-absolute-urls/$', PhotoAbsoluteUrlList.as_view(), name='photoswithabsoluteurls-list'),
url(r'^photos-with-absolute-urls/(?P<pk>\d+)/$', PhotoAbsoluteUrlDetail.as_view(), name='photoswithabsoluteurls-detail'),
url(r'^photos-with-mixed-urls/$', PhotoUrlList.as_view(), name='photoswithmixedurls-list'),
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'),
)
@ -289,28 +289,38 @@ class TestUrlOptionsView(TestCase):
"""
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']
for item in items:
Photo(description=item, album=self.album).save()
self.objects = Photo.objects
self.data = [
{
'url': '/photos-with-absolute-urls/%d/' % obj.id,
'description': obj.text,
'album_url': 'http://testserver/optionalrelation/%d/' % obj.album
}
for obj in self.objects.all()
{
'url': 'http://testserver/photos-with-mixed-urls/%d/' % obj.id,
'description': obj.description,
'album_url': '/albums/%s/' % obj.album.title
}
for obj in self.objects.all()
]
self.list_view = PhotoUrlList.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):
"""
GET requests to RetrieveAPIView with optional relations should return None
for non existing relations.
"""
request = factory.get('/photos-with-absolute-urls/1')
response = self.detail_view(request)
request = factory.get('/photos-with-mixed-urls/1/')
response = self.detail_view(request, pk=1)
self.assertEquals(response.status_code, status.HTTP_200_OK)
self.assertEquals(response.data, self.data[0:2])
self.assertEquals(response.data, self.data[0])