Beispiel #1
0
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
Beispiel #3
0
        class Comment(BaseEntity):
            content = Text(required=True)

            post = Reference("Post")

            class Meta:
                aggregate_cls = "Post"
Beispiel #4
0
class CommentViaWithReference(BaseEntity):
    content = Text()
    added_on = DateTime()
    posting = Reference("tests.aggregate.elements.PostVia")

    class Meta:
        aggregate_cls = PostViaWithReference
Beispiel #5
0
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")
Beispiel #8
0
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")
Beispiel #9
0
            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
Beispiel #11
0
class PostViaWithReference(BaseAggregate):
    content = Text(required=True)
    comments = HasMany(
        "tests.aggregate.elements.CommentViaWithReference", via="posting_id"
    )
    author = Reference("tests.aggregate.elements.Author")
Beispiel #12
0
class ProfileWithAccountId(BaseAggregate):
    about_me = Text()
    account = Reference("tests.aggregate.elements.AccountWithId")
Beispiel #13
0
class Profile(BaseAggregate):
    about_me = Text()
    account = Reference("tests.aggregate.elements.Account", via="username")
Beispiel #14
0
class ProfileVia(BaseAggregate):
    profile_id = String(identifier=True)
    about_me = Text()
    account_email = String(max_length=255)
Beispiel #15
0
        class Post(BaseAggregate):
            title = String(required=True, max_length=1000)
            slug = String(required=True, max_length=1024)
            content = Text(required=True)

            comments = HasMany(Comment)
Beispiel #16
0
    def test_init(self):
        """Test successful Text Field initialization"""

        address = Text()
        assert address is not None
Beispiel #17
0
 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)
Beispiel #18
0
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"
Beispiel #19
0
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
Beispiel #20
0
class Post(BaseAggregate):
    content = Text(required=True)
    comments = HasMany("tests.aggregate.elements.Comment")
    author = Reference("tests.aggregate.elements.Author")
Beispiel #21
0
def test_that_text_values_are_automatically_cleaned():
    text_field = Text()

    value = text_field._load("an <script>evil()</script> example")
    assert value == u"an &lt;script&gt;evil()&lt;/script&gt; example"
Beispiel #22
0
class ProfileViaWithReference(BaseAggregate):
    about_me = Text()
    ac = Reference("tests.aggregate.elements.AccountViaWithReference")
Beispiel #23
0
class ProviderCustomModel(BaseModel):
    name = Text()

    class Meta:
        entity_cls = Provider
        schema_name = "adults"
Beispiel #24
0
 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()
Beispiel #26
0
        class Post(BaseAggregate):
            title = String(required=True, max_length=1000)
            slug = String(required=True, max_length=1024)
            content = Text(required=True)

            meta = HasOne("PostMeta")
Beispiel #27
0
 class Post(BaseAggregate):
     content = Text(required=True)
     comments = HasMany("Comment")
Beispiel #28
0
 class ReceiverInlineModel:
     about = Text()
class Created(BaseEvent):
    id = Identifier(identifier=True)
    topic = String()
    content = Text()
Beispiel #30
0
class Create(BaseCommand):
    id = Identifier()
    topic = String()
    content = Text()