我正在尝试使用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)
这不是我需要登录的全部内容吗?
答案 0 :(得分:0)
哎呀 - 密码已加密 - 我需要传入明文密码,然后方法正确返回“true”。