✅ Update test to add verification database records (#1178)
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlmodel import Session, select
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.security import verify_password
|
||||
from app.models import User
|
||||
from app.utils import generate_password_reset_token
|
||||
|
||||
|
||||
@@ -67,10 +70,10 @@ def test_recovery_password_user_not_exits(
|
||||
|
||||
|
||||
def test_reset_password(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
token = generate_password_reset_token(email=settings.FIRST_SUPERUSER)
|
||||
data = {"new_password": settings.FIRST_SUPERUSER_PASSWORD, "token": token}
|
||||
data = {"new_password": "changethis", "token": token}
|
||||
r = client.post(
|
||||
f"{settings.API_V1_STR}/reset-password/",
|
||||
headers=superuser_token_headers,
|
||||
@@ -79,6 +82,11 @@ def test_reset_password(
|
||||
assert r.status_code == 200
|
||||
assert r.json() == {"message": "Password updated successfully"}
|
||||
|
||||
user_query = select(User).where(User.email == settings.FIRST_SUPERUSER)
|
||||
user = db.exec(user_query).first()
|
||||
assert user
|
||||
assert verify_password(data["new_password"], user.hashed_password)
|
||||
|
||||
|
||||
def test_reset_password_invalid_token(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
|
Reference in New Issue
Block a user