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]
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"]
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"]}
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']" ] }
class GenericPostgres(BaseAggregate): ids = List() role = String()
class IntegerArrayUser(BaseAggregate): email = String(max_length=255, required=True, unique=True) roles = List(content_type=Integer)
class ArrayUser(BaseAggregate): email = String(max_length=255, required=True, unique=True) roles = List() # Defaulted to String Content Type
class User(BaseAggregate): emails = List()
class Lottery(BaseEntity): jackpot = Boolean() numbers = List(content_type=Integer, required=True)
class Lottery(BaseEntity): numbers = List(content_type=Integer)
def test_type_validation(self): """Test type checking validation for the Field""" numbers = List(content_type=Integer) with pytest.raises(ValidationError): numbers._load("x")
class ArrayUser(BaseAggregate): email = String(max_length=255, required=True, unique=True) roles = List() # Defaulted to Text Content Type integers = List(content_type=Integer)