2023-05-10 15:31:30 +02:00
|
|
|
from flask import url_for
|
|
|
|
|
|
|
|
from app.db import Session
|
|
|
|
from app.models import User, ResetPasswordCode
|
|
|
|
from tests.utils import create_new_user, random_token
|
|
|
|
|
|
|
|
|
2023-05-15 12:34:58 +02:00
|
|
|
def test_successful_reset_password(flask_client):
|
2023-05-10 15:31:30 +02:00
|
|
|
user = create_new_user()
|
|
|
|
original_pass_hash = user.password
|
|
|
|
user_id = user.id
|
|
|
|
reset_code = random_token()
|
|
|
|
ResetPasswordCode.create(user_id=user.id, code=reset_code)
|
|
|
|
ResetPasswordCode.create(user_id=user.id, code=random_token())
|
|
|
|
Session.commit()
|
|
|
|
|
|
|
|
r = flask_client.post(
|
|
|
|
url_for("auth.reset_password", code=reset_code),
|
|
|
|
data={"password": "1231idsfjaads"},
|
|
|
|
)
|
|
|
|
|
2023-05-15 12:34:58 +02:00
|
|
|
assert r.status_code == 302
|
2023-05-10 15:31:30 +02:00
|
|
|
|
2023-05-15 12:34:58 +02:00
|
|
|
assert ResetPasswordCode.get_by(user_id=user_id) is None
|
2023-05-10 15:31:30 +02:00
|
|
|
user = User.get(user_id)
|
|
|
|
assert user.password != original_pass_hash
|