Trying to write a unittest which should check whether user has inputted correct password.
Using Django's native auth function user.check_password for this.
The problem is that check_password woudn't accept user object's own password for some reason. For example, this raises an error:
assert user.check_password(user.password), "Password doesn't match"
user.password returns MD5 unicode string.
Does anyone know why doesn't this pass the check and how the check can be passed?
This is happening because
check_passwordaccepts a raw string and you are passing a hash to it.user.passwordis a hash of, and metadata about, thepassword.According to docs,
So, just pass the actual raw string password to
user.check_password()and the unittest will pass.