title: Django [AssertionError: 401 != 201]
body: <p>I'm writing tests for my API. Now i want to test post method.</p>
  
  <p>Here's my <code>views.py</code>:</p>
  
  <pre><code>class TaskViewSet(viewsets.ModelViewSet):
  
      queryset = Task.objects.all()
      serializer_class = serializers.TaskSerializer
      authentication_classes = (BasicAuthentication,)
      permission_classes = (permissions.IsAuthenticated, permissions.IsAdminUser)
  </code></pre>
  
  <p>Here's my <code>tests.py</code>:</p>
  
  <pre><code>class UserFactory(DjangoModelFactory):
  
      class Meta:
          model = User
  
      username = 'dima'
      password = 'moonmvm2k14'
      email = 'admin@admin.com'
      is_superuser = True
      is_active = True
      is_staff = True
  
  
  class TaskFactory(DjangoModelFactory):
  
      class Meta:
          model = Task
  
      title = "TASK N1"
      description = "smth"
      person = factory.SubFactory(UserFactory)
      deadline = date.today()
  
  
  class ViewTest(APITestCase):
  
      def setUp(self):
          self.task = TaskFactory()
  
          self.username = 'myuser'
          self.password = 'test' 
          self.email = 'admin@mgmail.com'
  
          self.admin = User.objects.create_superuser(self.username, self.password, self.email)
  
          self.client = APIClient()
          self.client.login(username=self.admin.username, password=self.admin.password)
  
      def test_post_task(self):
          url = '/task-list/'
          json_tasks = serializers.TaskSerializer(self.task)
          data = json_tasks.data
          response = self.client.post(url, data)
          tasks_count = Task.objects.count()
          self.assertEqual(response.status_code, status.HTTP_201_CREATED)
          self.assertEqual(tasks_count, 2)
  
  </code></pre>
  
  <p>But when i try to test it i see this error:</p>
  
  <p><code>AssertionError: 401 != 201</code></p>
  
  <p>I don't know why my test fails with Not Authorized Status Code.</p>
  
  <p>So, what's the problem and how can I solve it?</p>