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]
class Create(BaseCommand): id = Identifier(identifier=True) topic = String() content = Text() class Meta: aggregate_cls = Post
class Comment(BaseEntity): content = Text(required=True) post = Reference("Post") class Meta: aggregate_cls = "Post"
class CommentViaWithReference(BaseEntity): content = Text() added_on = DateTime() posting = Reference("tests.aggregate.elements.PostVia") class Meta: aggregate_cls = PostViaWithReference
class CommentVia(BaseEntity): content = Text() added_on = DateTime() posting_id = String() class Meta: aggregate_cls = PostVia
class Comment(BaseEntity): content = Text(required=True) commented_at = DateTime(required=True, default=datetime.now()) post = Reference(Post) class Meta: aggregate_cls = Post
class Post(BaseAggregate): title = String(required=True, max_length=1000) slug = String(required=True, max_length=1024) content = Text(required=True) posted_at = DateTime(required=True, default=datetime.now()) meta = HasOne("tests.unit_of_work.aggregate_elements.PostMeta") comments = HasMany("tests.unit_of_work.aggregate_elements.Comment")
class Post(BaseAggregate): title = String(required=True, max_length=1000) slug = String(required=True, max_length=1024) content = Text(required=True) posted_at = DateTime(required=True, default=datetime.now()) post_meta = HasOne("tests.repository.child_entities.PostMeta") comments = HasMany("tests.repository.child_entities.Comment")
class Comment(BaseEntity): content = Text() added_on = DateTime() post = Reference("Post") class Meta: aggregate_cls = Post
class Post(BaseEventSourcedAggregate): topic = String() content = Text() is_published = Boolean(default=False) @classmethod def initialize(cls, identifier, topic, content): post = Post(id=identifier, topic=topic, content=content) post.raise_(Created(id=identifier, topic=topic, content=content)) return post def publish(self): # Perform some heavy validations if not self.is_published: self.raise_(Published(id=self.id)) @apply(Published) def mark_published(self, _: BaseEvent) -> None: self.is_published = True
class PostViaWithReference(BaseAggregate): content = Text(required=True) comments = HasMany( "tests.aggregate.elements.CommentViaWithReference", via="posting_id" ) author = Reference("tests.aggregate.elements.Author")
class ProfileWithAccountId(BaseAggregate): about_me = Text() account = Reference("tests.aggregate.elements.AccountWithId")
class Profile(BaseAggregate): about_me = Text() account = Reference("tests.aggregate.elements.Account", via="username")
class ProfileVia(BaseAggregate): profile_id = String(identifier=True) about_me = Text() account_email = String(max_length=255)
class Post(BaseAggregate): title = String(required=True, max_length=1000) slug = String(required=True, max_length=1024) content = Text(required=True) comments = HasMany(Comment)
def test_init(self): """Test successful Text Field initialization""" address = Text() assert address is not None
class Post(BaseAggregate): title = String(required=True, max_length=1000) slug = String(required=True, max_length=1024) content = Text(required=True) posted_at = DateTime(required=True, default=datetime.utcnow)
def test_that_sanitization_can_be_optionally_switched_off(): text_field = Text(sanitize=False) value = text_field._load("an <script>evil()</script> example") assert value == "an <script>evil()</script> example"
def test_sanitization_option_for_text_fields(): text_field1 = Text() assert text_field1.sanitize is True text_field1 = Text(sanitize=False) assert text_field1.sanitize is False
class Post(BaseAggregate): content = Text(required=True) comments = HasMany("tests.aggregate.elements.Comment") author = Reference("tests.aggregate.elements.Author")
def test_that_text_values_are_automatically_cleaned(): text_field = Text() value = text_field._load("an <script>evil()</script> example") assert value == u"an <script>evil()</script> example"
class ProfileViaWithReference(BaseAggregate): about_me = Text() ac = Reference("tests.aggregate.elements.AccountViaWithReference")
class ProviderCustomModel(BaseModel): name = Text() class Meta: entity_cls = Provider schema_name = "adults"
def test_type_validation(self): """Test type checking validation for the Field""" address = Text() value = address._load("My home address") assert value == "My home address"
class Post(BaseEventSourcedAggregate): topic = String() content = Text()
class Post(BaseAggregate): title = String(required=True, max_length=1000) slug = String(required=True, max_length=1024) content = Text(required=True) meta = HasOne("PostMeta")
class Post(BaseAggregate): content = Text(required=True) comments = HasMany("Comment")
class ReceiverInlineModel: about = Text()
class Created(BaseEvent): id = Identifier(identifier=True) topic = String() content = Text()
class Create(BaseCommand): id = Identifier() topic = String() content = Text()