title: How do I get an Django ViewSet to return a 403 error on anonymous post
body: <p>I'm trying to get my app to return a 403 error when an anonymous user attempts to POST to it. Right now it returns a 201 code, but doesn't save the post to the database.</p>
  
  <p>The problem is that my unit test fails because it's checking for a 403 code.</p>
  
  <p>Here is my views</p>
  
  <pre><code>from post.models import Post
  from post.serializers import PostSerializer
  from post.permissions import IsOwnerOrReadOnly, IsOwnerOrAdmin
  from rest_framework import viewsets, status
  from rest_framework.response import Response
  
  class PostViewSet(viewsets.ModelViewSet):
      """
      This viewset automatically provides `list`, `create`, `retrieve`,
      `update` and `destroy` actions.
      """
      queryset = Post.objects.all()
      serializer_class = PostSerializer
      # The default will be that anyone can read a post, but only owners can change it
      permission_classes = (IsOwnerOrReadOnly,)
  
      def get_permissions(self):
          # Both owners and admins can destroy a post, so if we're destroying we change permissions
          if self.action in ('destroy',):
              self.permission_classes = [IsOwnerOrAdmin, ]
          return super(self.__class__, self).get_permissions()
  
      def perform_create(self, serializer):
          if self.request.user.is_authenticated:
              serializer.save(author=self.request.user)
          else:
              return Response('Cannot post anonymously', status=status.HTTP_403_FORBIDDEN)
  </code></pre>
  
  <p>You can see I'm checking if the user is authenticated and if not, return a Response with a 403 code, but for some reason a 201 code is being returned.</p>
  
  <p>How do I get it to return a 403 code?</p>