2017-04-04 4 views
2

AllAuth를 사용하여 프로그래밍 방식으로 로그인하는 간단한 방법이 있습니까? 쿠키 또는 세션에 대해별로 신경 쓰지 않고 AllAuth 사용자 계정에 해당하는 Client을 얻고 싶습니다.Django-AllAuth를 사용하여 프로그래밍 방식으로 로그인 하시겠습니까?

예 :

from django.test import Client 
from django.contrib.auth.models import User 

user = User.objects.first() # assuming user registered with AllAuth 
client.login(username=user.username) # password needed! 

AllAuth 사용자 계정은 위의 코드를 작동하지 않도록 암호가 보장되지 않습니다. 그렇다면 어떻게하면 클라이언트가 암호없이 로그인하여 테스트를 쉽게 할 수 있습니까?

+2

겠습니까 ['force_login' (https://docs.djangoproject.com/en/1.10/topics/testing/되어 사용 tools/# django.test.Client.force_login)가 작동합니까? – Alasdair

답변

1

APITestCase's있어서 여기 force_authenticate

class Test(APITestCase): 
    def setUp(self): 
     self.user = ... #get the user 
     self.client.force_authenticate(user=self.user) 

를 사용 docs