Django测试登录失败

时间:2014-11-13 18:51:22

标签: python django authentication testing login

我正在尝试使用Django进行一些简单的测试,但我无法成功登录用户。这是我的代码:

def createUser(isadmin):
    u = User.objects.create_user(username="Test" + ("Admin" if isadmin else "Regular"), password="test")
    return u

def loginUser(self, theusername, thepassword):

    print(theusername + " " + thepassword)
    a = self.client.login(username = theusername, password = thepassword)
    # Prints false - should be true, right?
    print(a)

稍后的某个地方:

class DailyEntriesIntTests(TestCase):
    def setUp(self):
        self.client = Client()
        u = createUser(False)
        loginUser(self, u.username, u.password)

这不是我需要登录的全部内容吗?

1 个答案:

答案 0 :(得分:0)

哎呀 - 密码已加密 - 我需要传入明文密码,然后方法正确返回“true”。