"Unable to login with provided credentials"(测试中)
"Unable to login with provided credentials" (on Testing)
我正在为用户注册和登录编写一个测试用例,我测试了 postman (chrome),它可以工作,但测试用例没有。
我正在使用 djangorestframework-jwt
进行身份验证
测试:
class PublicUserTests(APITestCase):
def test_create_account(self):
url = "/api/user/create/"
data = {'email': 'clark@gmail.com', 'nombre': 'Clark', 'password': 'Clark'}
response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
def test_login(self):
url = "/api/auth/token/"
response = self.client.post(url, {"email": "clark@gmail.com", "password": "Clark"}, format='json')
print(response.status_text)
print(response.content)
self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
结果:
Creating test database for alias 'default'...
.BAD REQUEST
b'{"non_field_errors":["Unable to login with provided credentials."]}'
F
======================================================================
FAIL: test_login (user.tests.PublicUserTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/rizotas/Proyects/django/src/rescue/user/tests.py", line 86, in test_login
self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
AssertionError: 400 != 200 : ReturnDict([('non_field_errors', ['Unable to login with provided credentials.'])])
----------------------------------------------------------------------
Ran 2 tests in 0.116s
FAILED (failures=1)
Destroying test database for alias 'default'...
非常感谢您的帮助:)
未连接 TestCase 中的测试方法。因此,当 test_login
工作时,他看不到来自 test_create_account
的用户。
您需要在登录前创建用户 test_login
。
我正在为用户注册和登录编写一个测试用例,我测试了 postman (chrome),它可以工作,但测试用例没有。
我正在使用 djangorestframework-jwt
进行身份验证
测试:
class PublicUserTests(APITestCase):
def test_create_account(self):
url = "/api/user/create/"
data = {'email': 'clark@gmail.com', 'nombre': 'Clark', 'password': 'Clark'}
response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
def test_login(self):
url = "/api/auth/token/"
response = self.client.post(url, {"email": "clark@gmail.com", "password": "Clark"}, format='json')
print(response.status_text)
print(response.content)
self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
结果:
Creating test database for alias 'default'...
.BAD REQUEST
b'{"non_field_errors":["Unable to login with provided credentials."]}'
F
======================================================================
FAIL: test_login (user.tests.PublicUserTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/rizotas/Proyects/django/src/rescue/user/tests.py", line 86, in test_login
self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
AssertionError: 400 != 200 : ReturnDict([('non_field_errors', ['Unable to login with provided credentials.'])])
----------------------------------------------------------------------
Ran 2 tests in 0.116s
FAILED (failures=1)
Destroying test database for alias 'default'...
非常感谢您的帮助:)
未连接 TestCase 中的测试方法。因此,当 test_login
工作时,他看不到来自 test_create_account
的用户。
您需要在登录前创建用户 test_login
。