tests for temp_password

This commit is contained in:
2026-09-28 09:56:59 +03:00
parent 54c670ddec
commit 6a6a95e863
2 changed files with 32 additions and 0 deletions
+28
View File
@@ -6,6 +6,7 @@ from fastapi import HTTPException
from jose import jwt
from src.models.configs_read.env import env_settings
from src.models.pydantic_models.model import validate_password
from src.service.auth.jwt import HashService, JwtService
@@ -146,3 +147,30 @@ class TestJwt:
async def test_token_to_hash_different_input(self, hash_service:HashService)->None:
assert hash_service.token_to_hash("abc")!=hash_service.token_to_hash("xyz")
@pytest.mark.parametrize("complexity",[
pytest.param(8,id="low_edge"),
pytest.param(9,id="low_edge+1"),
pytest.param(16,id="default"),
pytest.param(72,id="high_edge"),
pytest.param(71,id="high_edge-1")
])
async def test_generate_temp_password_positive(self, hash_service:HashService, complexity:int)->None:
for _ in range(10000):
password=await hash_service.generate_temp_password(complexity)
try:
validate_password(password)
except ValueError as e:
pytest.fail(f"{password!r}: {e}")
@pytest.mark.parametrize("complexity", [
pytest.param(73,id="too_long"),
pytest.param(7,id="too_short")
])
async def test_generate_temp_password_negative(self, hash_service:HashService, complexity:int)->None:
password = await hash_service.generate_temp_password(complexity)
with pytest.raises(ValueError, match="8-72"):
validate_password(password)