Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit ce60e47

Browse files
committed
Added JWT TestCase Class and Client
1 parent 5d46cbd commit ce60e47

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rest_framework_jwt/test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from rest_framework.test import APITestCase, APIClient
2+
from rest_framework import status
3+
4+
5+
class APIJWTClient(APIClient):
6+
def login(self, username, password):
7+
"""
8+
Returns True if login is possible; False if the provided credentials
9+
are incorrect, or the user is inactive.
10+
"""
11+
response = self.post('/api-token-auth/', {"username": username, "password": password},
12+
format='json')
13+
if response.status_code == status.HTTP_200_OK:
14+
self.credentials(HTTP_AUTHORIZATION='JWT ' + response.data['token'])
15+
16+
return True
17+
else:
18+
return False
19+
20+
21+
class APIJWTTestCase(APITestCase):
22+
client_class = APIJWTClient

0 commit comments

Comments
 (0)