title: Django Rest Framework JWT Unit Test
body: <p>I am using DRF with the JWT package for authentication. Now, I'm trying to write a unit test that authenticates itself with a JWT token. No matter how I try it, I can't get the test API client to authenticate itself via JWT. If I do the same with an API client (in my case, Postman), everything works.</p>
  <p>This is the test case:</p>
  <pre><code>from django.urls import reverse
  from rest_framework.test import APITestCase
  from rest_framework_jwt.settings import api_settings
  
  from backend.factories import member_factory
  
  jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
  jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
  
  
  class MemberTests(APITestCase):
      def test_get_member(self):
          member = member_factory()
  
          payload = jwt_payload_handler(member.user)
          token = jwt_encode_handler(payload)
  
          self.client.credentials(Authorization='JWT {0}'.format(token))
          response = self.client.get(reverse('member-detail', kwargs={'pk': member.pk}))
          assert response.status_code == 200
  </code></pre>
  <p>But I always get a <code>401 Authentication credentials were not provided</code>.</p>
  <p>In <code>response.request</code> I see the token is there, it's just not being applied I guess.</p>
  <p>If I rewrite the test to use <code>rest_framework.test.RequestsClient</code> and actually send it to the <a href="https://docs.djangoproject.com/en/1.11/topics/testing/tools/#liveservertestcase" rel="noreferrer">live_server</a> URL, it works.</p>
  <p>Any help on this?</p>
  <p>P.S.: I am aware of <code>force_authenticate()</code> and <a href="http://www.django-rest-framework.org/api-guide/testing/#loginkwargs" rel="noreferrer">login</a>, but I would like my unit tests to access the API the same as the API client will in production.</p>