예제 #1
0
파일: email.py 프로젝트: proteanhq/protean
class BaseEmail(BaseContainer, OptionsMixin):  # FIXME Remove OptionsMixin
    """Base Email class that should implemented by all Domain Email Messages.

    This is also a marker class that is referenced when emails are registered
    with the domain.
    """

    element_type = DomainObjects.EMAIL

    @classmethod
    def _default_options(cls):
        return [("provider", "default")]

    subject = String()
    from_email = String()
    to = List(content_type=String)
    bcc = List(content_type=String)
    cc = List(content_type=String)
    reply_to = String()

    # Supplied content
    text = Text()
    html = Text()

    # JSON data with template
    data = Dict()
    template = String()

    def defaults(self):
        """
        Initialize a single email message (which can be sent to multiple
        recipients).
        """
        self.to = convert_str_values_to_list(self.to)
        self.cc = convert_str_values_to_list(self.cc)
        self.bcc = convert_str_values_to_list(self.bcc)
        self.reply_to = (
            convert_str_values_to_list(self.reply_to)
            if self.reply_to
            else self.from_email
        )

    @property
    def recipients(self):
        """
        Return a list of all recipients of the email (includes direct
        addressees as well as Cc and Bcc entries).
        """
        return [email for email in (self.to + self.cc + self.bcc) if email]
예제 #2
0
    def test_init(self):
        """Test successful List Field initialization"""

        tags = List()
        assert tags is not None

        assert tags._load(["x", "y", "z"]) == ["x", "y", "z"]
예제 #3
0
def test_that_only_specific_primitive_types_are_allowed_as_content_types(test_domain):
    List(content_type=String)
    List(content_type=Identifier)
    List(content_type=Integer)
    List(content_type=Float)
    List(content_type=Boolean)
    List(content_type=Date)
    List(content_type=DateTime)

    with pytest.raises(ValidationError) as error:
        List(content_type=Auto)

    assert error.value.messages == {"content_type": ["Content type not supported"]}
예제 #4
0
    def test_choice(self):
        """Test choices validations for the list field"""
        class StatusChoices(enum.Enum):
            """Set of choices for the status"""

            PENDING = "Pending"
            SUCCESS = "Success"
            ERROR = "Error"

        status = List(choices=StatusChoices)
        assert status is not None

        # Test loading of values to the status field
        assert status._load(["Pending"]) == ["Pending"]
        with pytest.raises(ValidationError) as e_info:
            status._load(["Pending", "Failure"])
        assert e_info.value.messages == {
            "unlinked": [
                "Value `'Failure'` is not a valid choice. "
                "Must be among ['Pending', 'Success', 'Error']"
            ]
        }
예제 #5
0
class GenericPostgres(BaseAggregate):
    ids = List()
    role = String()
예제 #6
0
class IntegerArrayUser(BaseAggregate):
    email = String(max_length=255, required=True, unique=True)
    roles = List(content_type=Integer)
예제 #7
0
class ArrayUser(BaseAggregate):
    email = String(max_length=255, required=True, unique=True)
    roles = List()  # Defaulted to String Content Type
예제 #8
0
class User(BaseAggregate):
    emails = List()
예제 #9
0
 class Lottery(BaseEntity):
     jackpot = Boolean()
     numbers = List(content_type=Integer, required=True)
예제 #10
0
 class Lottery(BaseEntity):
     numbers = List(content_type=Integer)
예제 #11
0
 def test_type_validation(self):
     """Test type checking validation for the Field"""
     numbers = List(content_type=Integer)
     with pytest.raises(ValidationError):
         numbers._load("x")
예제 #12
0
class ArrayUser(BaseAggregate):
    email = String(max_length=255, required=True, unique=True)
    roles = List()  # Defaulted to Text Content Type
    integers = List(content_type=Integer)