Skip to content

Instantly share code, notes, and snippets.

@luiscberrocal
Created January 2, 2019 19:52
Show Gist options
  • Save luiscberrocal/0f69973e18f8f43e8548d55506f4f1a9 to your computer and use it in GitHub Desktop.
Save luiscberrocal/0f69973e18f8f43e8548d55506f4f1a9 to your computer and use it in GitHub Desktop.
class JWTTestMixin(object):
def get_access_token(self, user):
token_url = reverse('token_obtain_pair')
pay_load = {'username': user.username, 'password': 'password'}
token_response = self.post(token_url, data=pay_load)
access_token = token_response.data['access']
return access_token
def get_with_token(self, url, access_token):
client = APIClient()
client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token))
response = client.get(url, data={'format': 'json'})
return response
def delete_with_token(self, url, access_token):
client = APIClient()
client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token))
response = client.delete(url, data={'format': 'json'})
return response
def put_with_token(self, url, access_token, data):
client = APIClient()
client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token))
response = client.put(url, data=data)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment