#NEWLINE# def test_user_cannot_use_expired_token( self ) : #NEWLINE# #INDENT# response = self . client . post ( self . auth_url , data = { #NEWLINE# #INDENT# 'username' : self . username , #NEWLINE# 'password' : self . password , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status_code , status . HTTP_200_OK ) #NEWLINE# token = response . data [ 'token' ] #NEWLINE# mocked_now = ( timezone . now ( ) + timezone . timedelta ( hours = 1 ) ) #NEWLINE# with patch ( 'django.utils.timezone.now' , ( lambda : mocked_now ) ) : #NEWLINE# #INDENT# self . client . credentials ( HTTP_AUTHORIZATION = ( 'Token ' + token ) ) #NEWLINE# response = self . client . get ( self . test_url ) #NEWLINE# self . assertEqual ( response . status_code , status . HTTP_401_UNAUTHORIZED ) #NEWLINE# self . assertEqual ( response . data [ 'detail' ] , 'Token has expired.' )