Пример #1
0
class OrderedPerson(BaseEntity):
    first_name = String(max_length=50, required=True)
    last_name = String(max_length=50)
    age = Integer(default=21)

    class Meta:
        order_by = "first_name"
Пример #2
0
class PersonSQLite(BaseAggregate):
    first_name = String(max_length=50, required=True)
    last_name = String(max_length=50, required=True)
    age = Integer(default=21)

    class Meta:
        provider = "sqlite"
Пример #3
0
class DbPerson(BaseEntity):
    first_name = String(max_length=50, required=True)
    last_name = String(max_length=50)
    age = Integer(default=21)

    class Meta:
        schema_name = "pepes"
class ListArticlesCommand:
    token = String(max_length=1024)
    tag = String(max_length=50)
    author = String(max_length=50)
    favorited = String(max_length=50)
    limit = Integer(default=20)
    offset = Integer(default=0)
Пример #5
0
class ArticleDTO:
    slug = String(max_length=250)
    title = String(required=True, max_length=250)
    description = Text(required=True)
    body = Text(required=True)
    tag_list = List()
    created_at = DateTime(default=datetime.now())
    updated_at = DateTime(default=datetime.now())
    favorited = Boolean(default=False)
    favorites_count = Integer()

    @classmethod
    def for_article(cls, article: Article, user: User):
        favorited = article in [
            favorite.article for favorite in user.favorites
        ]

        return ArticleDTO(slug=article.slug,
                          title=article.title,
                          description=article.description,
                          body=article.body,
                          tag_list=article.tag_list,
                          created_at=article.created_at,
                          updated_at=article.updated_at,
                          author=article.author,
                          favorited=favorited)
Пример #6
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")
Пример #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")
Пример #8
0
class Author(BaseEntity):
    first_name = String(required=True, max_length=25)
    last_name = String(max_length=25)
    posts = HasMany('tests.aggregate.elements.Post')
    account = Reference('tests.aggregate.elements.Account')

    class Meta:
        aggregate_cls = Account
Пример #9
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('PostMeta')
    comments = HasMany('Comment')
class UserRepresentation:
    id = Identifier()
    email = String(required=True, max_length=250)
    username = String(required=True, max_length=50)
    bio = String(max_length=1024)
    token = Method('token_only_if_active')

    def token_only_if_active(self, user):
        if user.token_valid_until and user.token_valid_until > datetime.now():
            return user.token
        else:
            return None
Пример #11
0
class Person(BaseAggregate):
    first_name = String(max_length=50, required=True)
    last_name = String(max_length=50, required=True)
    age = Integer(default=21)

    @classmethod
    def add_newcomer(cls, person_dict):
        """Factory method to add a new Person to the system"""
        newcomer = Person(
            first_name=person_dict['first_name'],
            last_name=person_dict['last_name'],
            age=person_dict['age'],
        )

        return newcomer
Пример #12
0
class CreateArticleDTO:
    title = String(required=True, max_length=250)
    description = Text(required=True)
    body = Text(required=True)
    tag_list = List()

    author = CustomObject(User, required=True)
Пример #13
0
class ProfileDTO:
    username = String(required=True, max_length=50)
    bio = String(max_length=1024)
    image = String(max_length=1024)
    following = Boolean(default=False)

    @classmethod
    def for_user(cls, user: User, profile_user: User):
        following = profile_user in [item.following for item in user.follows]

        return ProfileDTO(
            username=profile_user.username,
            bio=profile_user.bio,
            image=profile_user.image,
            following=following
        )
Пример #14
0
class CommentVia(BaseEntity):
    content = Text()
    added_on = DateTime()
    posting_id = String()

    class Meta:
        aggregate_cls = PostVia
Пример #15
0
class Email(BaseValueObject):
    """An email address value object, with two clearly identified parts:
        * local_part
        * domain_part
    """

    # This is the external facing data attribute
    address = String(max_length=254, required=True)

    @classmethod
    def from_address(cls, address):
        """ Construct an Email VO from an email address.

        email = Email.from_address('*****@*****.**')

        """
        if not cls.validate(address):
            raise ValueError("Email address is invalid")

        return cls(address=address)

    @classmethod
    def validate(cls, address):
        """ Business rules of Email address """
        if (
            type(address) is not str
            or "@" not in address
            or address.count("@") > 1
            or len(address) > 255
        ):
            return False

        return True
Пример #16
0
class Building(BaseValueObject):
    name = String(max_length=50)
    floors = Integer()
    status = String(choices=BuildingStatus)

    def defaults(self):
        if not self.status:
            if self.floors == 4:
                self.status = BuildingStatus.DONE.value
            else:
                self.status = BuildingStatus.WIP.value

    def clean(self):
        errors = defaultdict(list)
        if self.floors >= 4 and self.status != BuildingStatus.DONE.value:
            errors["status"].append("should be DONE")
        return errors
Пример #17
0
class Person(BaseAggregate):
    first_name = String(max_length=50, required=True)
    last_name = String(max_length=50, required=True)
    age = Integer(default=21)

    @classmethod
    def add_newcomer(cls, person_dict):
        """Factory method to add a new Person to the system"""
        newcomer = Person(
            first_name=person_dict['first_name'],
            last_name=person_dict['last_name'],
            age=person_dict['age'],
            )

        # Publish Event via the domain
        current_domain.publish(PersonAdded(person=newcomer))

        return newcomer
Пример #18
0
    def test_choice(self):
        """ Test choices validations for the string field """
        class StatusChoices(enum.Enum):
            """ Set of choices for the status"""
            PENDING = 'Pending'
            SUCCESS = 'Success'
            ERROR = 'Error'

        status = String(max_length=10, 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('Failure')
        assert e_info.value.messages == {
            'unlinked': [
                "Value `'Failure'` is not a valid choice. "
                "Must be one of ['Pending', 'Success', 'Error']"
            ]
        }
Пример #19
0
class UserUpdateCommand:
    token = String(required=True, max_length=1024)
    email = String(max_length=250)
    username = String(max_length=50)
    password = String(max_length=255)
    bio = String(max_length=1024)
    image = String(max_length=1024)
Пример #20
0
class Tag:
    name = String(required=True, max_length=50)
    added_at = DateTime(default=datetime.now())
    last_seen_at = DateTime(default=datetime.now())

    @classmethod
    def create(self, tag_name, added_at=datetime.now()):
        return Tag(name=tag_name.lower(), added_at=added_at, last_seen_at=added_at)

    def touch(self, updated_at=datetime.now()):
        self.last_seen_at = updated_at

        return self
Пример #21
0
class Email(BaseValueObject):
    REGEXP = r'\"?([-a-zA-Z0-9.`?{}]+@\w+\.\w+)\"?'

    # This is the external facing data attribute
    address = String(max_length=254, required=True)

    def clean(self):
        """ Business rules of Email address """
        errors = defaultdict(list)

        if not bool(re.match(Email.REGEXP, self.address)):
            errors['address'].append('is invalid')

        return errors
Пример #22
0
class Balance(BaseValueObject):
    """A composite amount object, containing two parts:
        * currency code - a three letter unique currency code
        * amount - a float value
    """

    currency = String(max_length=3, choices=Currency)
    amount = Float()

    def clean(self):
        errors = defaultdict(list)
        if self.amount and self.amount < -1000000000000.0:
            errors["amount"].append("cannot be less than 1 Trillion")
        return errors

    def replace(self, **kwargs):
        # FIXME Find a way to do this generically and move method to `BaseValueObject`
        currency = kwargs.pop("currency", None)
        amount = kwargs.pop("amount", None)
        return Balance(currency=currency or self.currency, amount=amount or self.amount)
Пример #23
0
class Person(BaseAggregate):
    first_name = String(max_length=50, required=True)
    last_name = String(max_length=50, required=True)
    age = Integer(default=21)
Пример #24
0
class EventLog(BaseAggregate):
    kind = String(max_length=50, required=True)
    payload = Dict(required=True)
    timestamp = DateTime(required=True, default=datetime.utcnow)
Пример #25
0
class User(BaseAggregate):
    email = String(max_length=255, required=True, unique=True)
    password = String(max_length=3026)
Пример #26
0
class Person(BaseAggregate):
    first_name = String(max_length=50, required=True)
    last_name = String(max_length=50, required=True)
    age = Integer(default=21)
    created_at = DateTime(default=datetime.now())
class UserRegistrationCommand:
    email = String(required=True, max_length=250)
    username = String(required=True, max_length=50)
    password = String(required=True, max_length=255)
Пример #28
0
 class ChangePasswordCommand:
     old_password = String(required=True, max_length=255)
     new_password = String(required=True, max_length=255)
Пример #29
0
class ComplexUser(BaseAggregate):
    email = ValueObjectField(Email, required=True)
    password = String(required=True, max_length=255)
Пример #30
0
class OrderedRoleSubclass(Role):
    bar = String(max_length=25)

    class Meta:
        order_by = 'bar'