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

Commit 744d90b

Browse files
committed
Merge pull request #72 from davideme/master
Added JWT TestCase Class and Client
2 parents 42efdf1 + e6152ed commit 744d90b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

rest_framework_jwt/test.py

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

0 commit comments

Comments
 (0)