0

I am trying to generate token from from rest_framework.authtoken.models import Token. View is successfully created, but I am writing test for post api using APIClient() from rest_framework.test import APIClient. def test_address_api_auth_token(self):

 data = { "username": self.user.username, "password": self.user.password } self.client.force_authenticate(user=self.user) response = self.client.post('/api-token-auth/', data, format='json') self.assertEqual(response.status_code, 200) 

Although user and password are created by model. but still I am getting this error -> AssertionError: 400 != 200. Error message -> Invalid usernamen and password .

1 Answer 1

0

Django stores password encrypted. Therefore, by doing self.user.password you're sending another string and will always fail the authentication.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.