@@ -205,6 +205,51 @@ def test_jwt_login_json_bad_creds(self):
205
205
self .assertEqual (response .status_code , 400 )
206
206
207
207
208
+ @override_settings (AUTH_USER_MODEL = 'tests.CustomUserUUID' )
209
+ class CustomUserUUIDObtainJSONWebTokenTests (TestCase ):
210
+ """JSON Web Token Authentication"""
211
+ urls = 'tests.test_views'
212
+
213
+ def setUp (self ):
214
+ from .models import CustomUserUUID
215
+
216
+
217
+ self .password = 'password'
218
+ user = CustomUserUUID .objects .create (email = self .email )
219
+ user .set_password (self .password )
220
+ user .save ()
221
+ self .user = user
222
+
223
+ self .data = {
224
+ 'email' : self .email ,
225
+ 'password' : self .password
226
+ }
227
+
228
+ def test_jwt_login_json (self ):
229
+ """
230
+ Ensure JWT login view using JSON POST works.
231
+ """
232
+ client = APIClient (enforce_csrf_checks = True )
233
+
234
+ response = client .post ('/auth-token/' , self .data , format = 'json' )
235
+
236
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
237
+ decoded_payload = utils .jwt_decode_handler (response .data ['token' ])
238
+ self .assertEqual (decoded_payload ['user_id' ], str (self .user .id ))
239
+
240
+ def test_jwt_login_json_bad_creds (self ):
241
+ """
242
+ Ensure JWT login view using JSON POST fails
243
+ if bad credentials are used.
244
+ """
245
+ client = APIClient (enforce_csrf_checks = True )
246
+
247
+ self .data ['password' ] = 'wrong'
248
+ response = client .post ('/auth-token/' , self .data , format = 'json' )
249
+
250
+ self .assertEqual (response .status_code , 400 )
251
+
252
+
208
253
class TokenTestCase (BaseTestCase ):
209
254
"""
210
255
Handlers for getting tokens from the API, or creating arbitrary ones.
0 commit comments