2015-01-29 2 views
0

사용자 등록 및 로그인을위한 테스트 케이스를 프로그래밍 중이며, 우편 번호 (크롬)를 테스트했지만 테스트 케이스는 작동하지 않습니다. 내가 인증을 위해 djangorestframework-jwt을 사용하고"제공된 자격 증명을 사용하여 로그인 할 수 없습니다."(테스트 중)

테스트 :

class PublicUserTests(APITestCase): 

    def test_create_account(self): 
     url = "/api/user/create/" 
     data = {'email': '[email protected]', '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": "[email protected]", "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에서

+0

self.client.login()을 사용해 보셨나요? – tgpatel

+0

예,하지만 False가 반환됩니다. – rizotas

+0

그 작품을위한 길을 찾았고, 두 가지 기능을 결합했습니다. 그러나 이것은 좋은 습관입니까? – rizotas

답변

1

시험 방법. 따라서 test_login이 작동하면 그는 test_create_account에서 사용자를 볼 수 없습니다.

test_login에 로그인하기 전에 사용자를 생성해야합니다.

관련 문제