Jew Token Authentication In Django Utc

[Solved] Jew Token Authentication In Django Utc | Basic - Code Explorer | yomemimo.com
Question : JEW token authentication in Django UTC

Answered by : magnificent-mouse-tychw7286zfc

 def test_api_jwt(self): url = reverse('api-jwt-auth') u = user_model.objects.create_user(username='user', email='[email protected]', password='pass') u.is_active = False u.save() resp = self.client.post(url, {'email':'[email protected]', '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':'[email protected]', '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)

Source : https://stackoverflow.com/questions/47576635/django-rest-framework-jwt-unit-test | Last Update : Mon, 31 May 21

Answers related to jew token authentication in django utc

Code Explorer Popular Question For Basic