@@ -324,7 +324,7 @@ def test_valid_registration(self):
324324 response .status_code ,
325325 rest_framework .status .HTTP_200_OK ,
326326 )
327- self .assertIn ('token ' , response .data )
327+ self .assertIn ('access ' , response .data )
328328 self .assertTrue (
329329 user .models .User .objects .filter (
330330 email = 'minecraft.digger@gmail.com' ,
@@ -391,7 +391,7 @@ def test_signin_success(self):
391391
392392class JWTTests (rest_framework .test .APITestCase ):
393393 def setUp (self ):
394-
394+ self . signup_url = django . urls . reverse ( 'api-user:sign-up' )
395395 self .signin_url = django .urls .reverse ('api-user:sign-in' )
396396 self .protected_url = django .urls .reverse ('api-core:protected' )
397397 self .refresh_url = django .urls .reverse ('api-user:token_refresh' )
@@ -428,6 +428,47 @@ def test_access_protected_view_with_valid_token(self):
428428 self .assertEqual (response .status_code , 200 )
429429 self .assertEqual (response .data ['status' ], 'request was permitted' )
430430
431+ def test_registration_token_invalid_after_login (self ):
432+ data = {
433+ 'email' : 'test@example.com' ,
434+ 'password' : 'StrongPass123!cd' ,
435+ 'name' : 'John' ,
436+ 'surname' : 'Doe' ,
437+ 'other' : {'age' : 22 , 'country' : 'us' },
438+ }
439+ response = self .client .post (
440+ self .signup_url ,
441+ data ,
442+ format = 'json' ,
443+ )
444+ reg_access_token = response .data ['access' ]
445+
446+ self .client .credentials (
447+ HTTP_AUTHORIZATION = f'Bearer { reg_access_token } ' ,
448+ )
449+ response = self .client .get (self .protected_url )
450+ self .assertEqual (response .status_code , 200 )
451+
452+ login_data = {'email' : data ['email' ], 'password' : data ['password' ]}
453+ response = self .client .post (
454+ self .signin_url ,
455+ login_data ,
456+ format = 'json' ,
457+ )
458+ login_access_token = response .data ['access' ]
459+
460+ self .client .credentials (
461+ HTTP_AUTHORIZATION = f'Bearer { reg_access_token } ' ,
462+ )
463+ response = self .client .get (self .protected_url )
464+ self .assertEqual (response .status_code , 401 )
465+
466+ self .client .credentials (
467+ HTTP_AUTHORIZATION = f'Bearer { login_access_token } ' ,
468+ )
469+ response = self .client .get (self .protected_url )
470+ self .assertEqual (response .status_code , 200 )
471+
431472 def test_refresh_token_invalidation_after_new_login (self ):
432473
433474 first_login_response = self .client .post (
0 commit comments