diff options
| author | Ludwig Kraatz | 2012-11-13 19:15:42 +0100 |
|---|---|---|
| committer | Ludwig Kraatz | 2012-11-13 19:15:42 +0100 |
| commit | b341dc70af828d066eb3891e8eafb6337cdd2d04 (patch) | |
| tree | 353031cd15c006a8b1f94a0e1cee96b0443d6fd3 /rest_framework/tests/hyperlinkedserializers.py | |
| parent | 851dff1644f6dafd29838a997a788df51c0570a3 (diff) | |
| download | django-rest-framework-b341dc70af828d066eb3891e8eafb6337cdd2d04.tar.bz2 | |
fixed ugly code
Location header is set just, if there is a Location field on the
serializer.
Diffstat (limited to 'rest_framework/tests/hyperlinkedserializers.py')
| -rw-r--r-- | rest_framework/tests/hyperlinkedserializers.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/rest_framework/tests/hyperlinkedserializers.py b/rest_framework/tests/hyperlinkedserializers.py index cc5a19c1..5fc935ae 100644 --- a/rest_framework/tests/hyperlinkedserializers.py +++ b/rest_framework/tests/hyperlinkedserializers.py @@ -8,17 +8,16 @@ factory = RequestFactory() class BlogPostCommentSerializer(serializers.ModelSerializer): - custom_identity_field = serializers.HyperlinkedIdentityField(view_name='blogpostcomment-detail') + url = serializers.HyperlinkedIdentityField(view_name='blogpostcomment-detail') text = serializers.CharField() blog_post_url = serializers.HyperlinkedRelatedField(source='blog_post', view_name='blogpost-detail') class Meta: model = BlogPostComment - fields = ('text', 'blog_post_url') + fields = ('text', 'blog_post_url', 'url') class PhotoSerializer(serializers.Serializer): - """ When Adding a HyperlinkedIdentityField to this serializer, the TestCreateWithForeignKeysAndCustomSlug will fail """ description = serializers.CharField() album_url = serializers.HyperlinkedRelatedField(source='album', view_name='album-detail', queryset=Album.objects.all(), slug_field='title', slug_url_kwarg='title') @@ -222,7 +221,7 @@ class TestCreateWithForeignKeysAndCustomSlug(TestCase): request = factory.post('/photos/', data=data) response = self.list_create_view(request).render() self.assertEqual(response.status_code, status.HTTP_201_CREATED) - self.assertNotIn("Location",response,msg="A Serializer without HyperlinkedIdentityField can not produce a valid Location header (for now). Thats why there shouldn'd be one") + self.assertNotIn("Location", response, msg="Location should only be included if there is a 'url' field on the serializer") self.assertEqual(self.post.photo_set.count(), 1) self.assertEqual(self.post.photo_set.all()[0].description, 'A test photo') |
