136 lines
4.5 KiB
Python
136 lines
4.5 KiB
Python
# #region Test.Schemas.Edge [C:1] [TYPE Module] [SEMANTICS test,schemas,auth,translate,edge]
|
|
# @BRIEF Edge-case coverage for schemas/auth.py and schemas/translate.py uncovered lines.
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
|
|
# ── auth.py: password validation ─────────────────────────────────
|
|
|
|
|
|
class TestUserCreatePasswordValidation:
|
|
"""Password strength validator edge cases (line 151)."""
|
|
|
|
def test_password_min_length_raises(self):
|
|
from src.schemas.auth import UserCreate
|
|
|
|
with pytest.raises(ValidationError) as exc:
|
|
UserCreate(
|
|
username="test",
|
|
email="test@x.com",
|
|
password="Ab1", # too short (3 chars, min 8)
|
|
)
|
|
errors = exc.value.errors()
|
|
assert any("at least 8" in str(e["msg"]) for e in errors)
|
|
|
|
def test_password_missing_uppercase_raises(self):
|
|
from src.schemas.auth import UserCreate
|
|
|
|
with pytest.raises(ValidationError) as exc:
|
|
UserCreate(
|
|
username="test",
|
|
email="test@x.com",
|
|
password="abcdefgh1", # no uppercase
|
|
)
|
|
errors = exc.value.errors()
|
|
assert any("uppercase" in str(e["msg"]) for e in errors)
|
|
|
|
def test_password_missing_lowercase_raises(self):
|
|
from src.schemas.auth import UserCreate
|
|
|
|
with pytest.raises(ValidationError) as exc:
|
|
UserCreate(
|
|
username="test",
|
|
email="test@x.com",
|
|
password="ABCDEFGH1", # no lowercase
|
|
)
|
|
errors = exc.value.errors()
|
|
assert any("lowercase" in str(e["msg"]) for e in errors)
|
|
|
|
def test_password_missing_digit_raises(self):
|
|
from src.schemas.auth import UserCreate
|
|
|
|
with pytest.raises(ValidationError) as exc:
|
|
UserCreate(
|
|
username="test",
|
|
email="test@x.com",
|
|
password="Abcdefgh", # no digit
|
|
)
|
|
errors = exc.value.errors()
|
|
assert any("digit" in str(e["msg"]) for e in errors)
|
|
|
|
def test_password_valid(self):
|
|
from src.schemas.auth import UserCreate
|
|
|
|
user = UserCreate(
|
|
username="test",
|
|
email="test@x.com",
|
|
password="ValidPassword1",
|
|
)
|
|
assert user.password == "ValidPassword1"
|
|
assert user.roles == []
|
|
|
|
|
|
# ── translate.py: BCP-47 validation and pattern length ────────────
|
|
|
|
|
|
class TestTranslateSchemasEdge:
|
|
"""BCP-47 validation and pattern length validation."""
|
|
|
|
def test_bcp47_empty_list(self):
|
|
from src.schemas.translate import _validate_bcp47_list
|
|
|
|
result = _validate_bcp47_list([])
|
|
assert result == []
|
|
|
|
def test_bcp47_none_list(self):
|
|
from src.schemas.translate import _validate_bcp47_list
|
|
|
|
result = _validate_bcp47_list(None)
|
|
assert result is None
|
|
|
|
def test_bcp47_valid_tags(self):
|
|
from src.schemas.translate import _validate_bcp47_list
|
|
|
|
result = _validate_bcp47_list(["en", "ru", "zh-CN", "pt-BR"])
|
|
assert result == ["en", "ru", "zh-CN", "pt-BR"]
|
|
|
|
def test_bcp47_invalid_tag_raises(self):
|
|
from src.schemas.translate import _validate_bcp47_list
|
|
|
|
with pytest.raises(ValueError) as exc:
|
|
_validate_bcp47_list(["en", "invalid tag with spaces"])
|
|
assert "BCP-47" in str(exc.value)
|
|
|
|
def test_bcp47_empty_tag_raises(self):
|
|
from src.schemas.translate import _validate_bcp47_list
|
|
|
|
with pytest.raises(ValueError) as exc:
|
|
_validate_bcp47_list(["en", ""])
|
|
assert "BCP-47" in str(exc.value)
|
|
|
|
def test_bulk_find_replace_pattern_too_long(self):
|
|
from src.schemas.translate import BulkFindReplaceRequest
|
|
|
|
with pytest.raises(ValidationError) as exc:
|
|
BulkFindReplaceRequest(
|
|
find_pattern="x" * 501,
|
|
replacement_text="test",
|
|
target_language="en",
|
|
)
|
|
errors = exc.value.errors()
|
|
assert any("500" in str(e["msg"]) for e in errors)
|
|
|
|
def test_bulk_find_replace_pattern_valid(self):
|
|
from src.schemas.translate import BulkFindReplaceRequest
|
|
|
|
req = BulkFindReplaceRequest(
|
|
find_pattern="old text",
|
|
replacement_text="new text",
|
|
target_language="en",
|
|
)
|
|
assert req.find_pattern == "old text"
|
|
assert req.replacement_text == "new text"
|
|
assert req.submit_to_dictionary_with_context is False
|
|
# #endregion Test.Schemas.Edge
|