为了提供一些背景信息,我正在测试当用户尝试通过PasswordChangeForm更新密码时会发生什么情况。如果新密码的任何部分包含用户名或用户的名字和/或姓氏,则不应进行密码更新。
因此,应该使用闪烁的消息将用户重定向到相同的表单。“密码不能包含:用户名;名字;姓氏” 闪烁的消息未呈现在运行测试时的模板。运行服务器后,将显示刷新消息。
我如何获取要呈现的消息,否则将通过测试?
if(isset($_GET['source'])){
$sourceId = $_GET['source'];
echo $_GET['shift1Oa'.$sourceId];
}
class UpdatePasswordTestCase(TestCase):
'''Verify that a User receives a message telling them
that a new password cannot contain their username, first name,
or last name.'''
@classmethod
def setUpTestData(cls):
cls.test_user = User.objects.create_user(
"test_user", password="Secret*#7_code!",
first_name='Fn', last_name='Ln'
)
cls.new_password = cls.test_user.get_full_name()
cls.passwords = {
'old_password': "Secret*#7_code!",
'new_password1': f"{cls.new_password}-{cls.test_user}",
'new_password2': f"{cls.new_password}-{cls.test_user}"
}
def test_password_update_fail(self):
self.client.force_login(self.test_user)
response = self.client.post(
reverse("accounts:change_password", kwargs={'user_id': 1}),
data=self.passwords
self.assertContains(response, "Password cannot contain")
# AssertionError: False is not true : Couldn't find 'Password cannot contain' in response