Exemplo n.º 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
Exemplo n.º 3
0
        class Comment(BaseEntity):
            content = Text(required=True)

            post = Reference("Post")

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

    class Meta:
        aggregate_cls = PostViaWithReference
Exemplo n.º 5
0
class CommentVia(BaseEntity):
    content = Text()
    added_on = DateTime()
    posting_id = String()

    class Meta:
        aggregate_cls = PostVia
Exemplo n.º 6
0
class Comment(BaseEntity):
    content = Text(required=True)
    commented_at = DateTime(required=True, default=datetime.now())

    post = Reference(Post)

    class Meta:
        aggregate_cls = Post
Exemplo n.º 7
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())

    meta = HasOne("tests.unit_of_work.aggregate_elements.PostMeta")
    comments = HasMany("tests.unit_of_work.aggregate_elements.Comment")
Exemplo n.º 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")
Exemplo n.º 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
Exemplo n.º 11
0
class PostViaWithReference(BaseAggregate):
    content = Text(required=True)
    comments = HasMany(
        "tests.aggregate.elements.CommentViaWithReference", via="posting_id"
    )
    author = Reference("tests.aggregate.elements.Author")
Exemplo n.º 12
0
class ProfileWithAccountId(BaseAggregate):
    about_me = Text()
    account = Reference("tests.aggregate.elements.AccountWithId")
Exemplo n.º 13
0
class Profile(BaseAggregate):
    about_me = Text()
    account = Reference("tests.aggregate.elements.Account", via="username")
Exemplo n.º 14
0
class ProfileVia(BaseAggregate):
    profile_id = String(identifier=True)
    about_me = Text()
    account_email = String(max_length=255)
Exemplo n.º 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)
Exemplo n.º 16
0
    def test_init(self):
        """Test successful Text Field initialization"""

        address = Text()
        assert address is not None
Exemplo n.º 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)
Exemplo n.º 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"
Exemplo n.º 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
Exemplo n.º 20
0
class Post(BaseAggregate):
    content = Text(required=True)
    comments = HasMany("tests.aggregate.elements.Comment")
    author = Reference("tests.aggregate.elements.Author")
Exemplo n.º 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"
Exemplo n.º 22
0
class ProfileViaWithReference(BaseAggregate):
    about_me = Text()
    ac = Reference("tests.aggregate.elements.AccountViaWithReference")
Exemplo n.º 23
0
class ProviderCustomModel(BaseModel):
    name = Text()

    class Meta:
        entity_cls = Provider
        schema_name = "adults"
Exemplo n.º 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"
Exemplo n.º 25
0
class Post(BaseEventSourcedAggregate):
    topic = String()
    content = Text()
Exemplo n.º 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")
Exemplo n.º 27
0
 class Post(BaseAggregate):
     content = Text(required=True)
     comments = HasMany("Comment")
Exemplo n.º 28
0
 class ReceiverInlineModel:
     about = Text()
class Created(BaseEvent):
    id = Identifier(identifier=True)
    topic = String()
    content = Text()
Exemplo n.º 30
0
class Create(BaseCommand):
    id = Identifier()
    topic = String()
    content = Text()