在下面的测试中,令牌没有被识别为有效。在我的手动测试中,它是有效的,所以我猜我在密码生成的方式中遗漏了一些东西。
def test_actual_reset_password(self):
new_password = "myNewPassword012*"
token_generator = PasswordResetTokenGenerator()
user = UserFactory.create()
token = token_generator.make_token(user=user)
response = self.assert_page_loading(path="/forgot-password/reset/{0}/".format(token))
print response
# That loads the page with the error message mentioning that the token was already used
# So I cannot carry on:
form = response.form
form['new_password1'] = new_password
form['new_password2'] = new_password
response = form.submit()
在django的源代码中,在PasswordResetForm中,我找到了这段代码;我看不出有什么区别:
def save(self, ..., token_generator=default_token_generator, ...):
"""
Generates a one-use only link for resetting password and sends to the
user.
"""
...
for user in self.users_cache:
...
c = {
...
'token': token_generator.make_token(user),
...
}
...
send_mail(subject, email, from_email, [user.email])
3条答案
按热度按时间5t7ly7z51#
好吧,我只是在搜索如何做到这一点的信息,你的问题促使我自己去弄清楚。我不知道你是否还在做这件事,但我是这样做的:
就这样!一点也不难。
k10s72fa2#
下面是我在功能测试中的做法:
sirbozc53#
这适用于Django 4.1:
有关进口品包括: