diff --git a/flask_mailing/config.py b/flask_mailing/config.py index 6c3c60e..626bd3d 100644 --- a/flask_mailing/config.py +++ b/flask_mailing/config.py @@ -4,7 +4,7 @@ from flask.globals import current_app from jinja2 import Environment, FileSystemLoader -from pydantic import BaseSettings as Settings +from pydantic_settings import BaseSettings as Settings from pydantic import DirectoryPath, EmailStr, conint, validator from .errors import TemplateFolderDoesNotExist diff --git a/flask_mailing/connection.py b/flask_mailing/connection.py index b4b7a0b..d1259d5 100644 --- a/flask_mailing/connection.py +++ b/flask_mailing/connection.py @@ -1,5 +1,5 @@ import aiosmtplib -from pydantic import BaseSettings as Settings +from pydantic_settings import BaseSettings as Settings from .config import ConnectionConfig from .errors import ConnectionErrors, PydanticClassRequired diff --git a/flask_mailing/schemas.py b/flask_mailing/schemas.py index 6698531..8e83d96 100644 --- a/flask_mailing/schemas.py +++ b/flask_mailing/schemas.py @@ -34,23 +34,22 @@ class MultipartSubtypeEnum(Enum): class Message(BaseModel): - recipients: List["EmailStr"] + recipients: List[EmailStr] attachments: List[Union[FileStorage, Dict, str]] = [] subject: str = "" body: Optional[Union[str, list]] = None template_body: Optional[Union[list, dict]] = None template_params: Optional[Union[list, dict]] = None html: Optional[Union[str, List, Dict]] = None - cc: List["EmailStr"] = [] - bcc: List["EmailStr"] = [] - reply_to: List["EmailStr"] = [] + cc: List[EmailStr] = [] + bcc: List[EmailStr] = [] + reply_to: List[EmailStr] = [] charset: str = "utf-8" subtype: Optional[str] = None multipart_subtype: MultipartSubtypeEnum = MultipartSubtypeEnum.mixed - @validator("template_params") + @validator("template_params", pre=True, always=True) def validate_template_params(cls, value, values): - if values.get("template_body", None) is None: values["template_body"] = value return value @@ -129,8 +128,8 @@ def attach( self.attachments.append(fsob) return True - @validator("subtype") - def validate_subtype(cls, value, values, config, field): + @validator("subtype", pre=True, always=True) + def validate_subtype(cls, value, values): """Validate subtype field.""" if values.get("template_body"): return "html" @@ -139,7 +138,6 @@ def validate_subtype(cls, value, values, config, field): class Config: arbitrary_types_allowed = True - def validate_path(path): cur_dir = os.path.abspath(os.curdir) requested_path = os.path.abspath(os.path.relpath(path, start=cur_dir)) diff --git a/tests/test_checker.py b/tests/test_checker.py index f83d217..cbb4749 100644 --- a/tests/test_checker.py +++ b/tests/test_checker.py @@ -1,5 +1,4 @@ import pytest -from pydantic import EmailError from flask_mailing.utils.errors import DBProvaiderError @@ -40,8 +39,5 @@ async def test_default_checker(default_checker): assert default_checker.validate_email(email) is True - with pytest.raises(EmailError): - default_checker.validate_email("test#mail.com") - with pytest.raises(DBProvaiderError): await default_checker.close_connections()