Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

JEW token authentication in Django UTC

 def test_api_jwt(self):

    url = reverse('api-jwt-auth')
    u = user_model.objects.create_user(username='user', email='user@foo.com', password='pass')
    u.is_active = False
    u.save()

    resp = self.client.post(url, {'email':'user@foo.com', 'password':'pass'}, format='json')
    self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)

    u.is_active = True
    u.save()

    resp = self.client.post(url, {'username':'user@foo.com', 'password':'pass'}, format='json')
    self.assertEqual(resp.status_code, status.HTTP_200_OK)
    self.assertTrue('token' in resp.data)
    token = resp.data['token']
    #print(token)

    verification_url = reverse('api-jwt-verify')
    resp = self.client.post(verification_url, {'token': token}, format='json')
    self.assertEqual(resp.status_code, status.HTTP_200_OK)

    resp = self.client.post(verification_url, {'token': 'abc'}, format='json')
    self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)

    client = APIClient()
    client.credentials(HTTP_AUTHORIZATION='JWT ' + 'abc')
    resp = client.get('/api/v1/account/', data={'format': 'json'})
    self.assertEqual(resp.status_code, status.HTTP_401_UNAUTHORIZED)
    client.credentials(HTTP_AUTHORIZATION='JWT ' + token)
    resp = client.get('/api/v1/account/', data={'format': 'json'})
    self.assertEqual(resp.status_code, status.HTTP_200_OK)
Comment

PREVIOUS NEXT
Code Example
Python :: Python run module with and without "-m" option and import path setting 
Python :: python import module with minus in its name 
Python :: python split clever looping 
Python :: lipa na mpesa daraja python 
Python :: apply diff subset pandas 
Python :: what hormone causes the feeling of love 
Python :: Grid-Strategy 
Python :: Insurance= contract.x_studio_social_security_basic salary of ins = 1500 result = contract.x_studio_social_security_basic_salary*100 
Python :: Example of Python Inline comments 
Python :: get data from s3 bucket python 
Python :: df.sample(frac=1) 
Python :: python class udp 
Python :: chrome drivers documentation 
Python :: convert integer unix to timestamp python 
Python :: duplicate a list with lowercase in python 
Python :: if the answer satisfiest the condition so how to stop it to run further ahead in python 
Python :: to the power python markdown 
Python :: python chunks iterator 
Python :: coin flip numpy 
Python :: python does strftime work with date objects 
Python :: rendere eseguibile python 
Python :: successful=true for number in range (3) print ("Attempt") if successful: print ("Successful") breal 
Python :: python use var in another function 
Python :: how to find projectile angle from distance python 
Python :: organize order columns dataframe 
Python :: slug in redirect django 
Python :: print a box like the ones below 
Python :: python keyboard monitoring 
Python :: is python the best robotic langauge 
Python :: how to make a config txt file on python 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =