Created
January 2, 2019 19:52
-
-
Save luiscberrocal/0f69973e18f8f43e8548d55506f4f1a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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