我正在为用户注册和登录编写一个测试用例,我测试了 whit 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'...
非常感谢你帮助我:)