Добавил тест на смену пароля
This commit is contained in:
parent
49344e0cca
commit
747883091d
2 changed files with 35 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
|||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
from app.users.auth import verify_password
|
||||
from app.users.dao import UserDAO
|
||||
|
||||
|
||||
async def test_get_users(ac: AsyncClient):
|
||||
response = await ac.get("/users")
|
||||
|
@ -134,3 +137,33 @@ async def test_change_password(
|
|||
|
||||
assert response.status_code == statuscode
|
||||
|
||||
|
||||
@pytest.mark.parametrize("user_id,password1,password2,statuscode,username", [
|
||||
(1, "12311234", "12311231", 409, "12311241"),
|
||||
(1, "12311231", "12311231", 200, "string"),
|
||||
(1, "12341234", "12341234", 200, "string"),
|
||||
(3, "12341234", "12341234", 200, "urec"),
|
||||
(3, "12341234", "1234123", 422, "urec"),
|
||||
(3, "1234123", "12341234", 422, "urec"),
|
||||
(3, "1234123", "1234123", 422, "urec"),
|
||||
])
|
||||
async def test_password_recovery(
|
||||
user_id: int, password1: str, password2: str, statuscode: int, username: str, ac: AsyncClient
|
||||
):
|
||||
response = await ac.post("/users/password_recovery", json={
|
||||
"user_id": user_id,
|
||||
"password1": password1,
|
||||
"password2": password2
|
||||
})
|
||||
|
||||
assert response.status_code == statuscode
|
||||
if response.status_code == 200:
|
||||
assert response.json()["username"] == username
|
||||
user_data = await UserDAO.find_one_or_none(id=user_id)
|
||||
hashed_password = user_data.hashed_password
|
||||
assert verify_password(password1, hashed_password)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -68,8 +68,8 @@ class SUserCode(BaseModel):
|
|||
|
||||
class SUserPasswordChange(BaseModel):
|
||||
user_id: int
|
||||
password1: str
|
||||
password2: str
|
||||
password1: str = Query(None, min_length=8)
|
||||
password2: str = Query(None, min_length=8)
|
||||
|
||||
|
||||
class SRecoverEmailSent(BaseModel):
|
||||
|
|
Loading…
Add table
Reference in a new issue