コード例 #1
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)
コード例 #2
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
        )
コード例 #3
0
 def test_type_validation(self):
     """ Test type checking validation for the Field"""
     with pytest.raises(ValidationError):
         tags = Boolean()
         tags._load('x')
コード例 #4
0
 class Adult(BaseAggregate):
     name = String(max_length=50)
     married = Boolean(default=True)
コード例 #5
0
 class Youth(BaseAggregate):
     name = String(max_length=50)
     married = Boolean(default=False)
コード例 #6
0
    def test_init(self):
        """Test successful Boolean Field initialization"""

        married = Boolean()
        assert married is not None
        assert married._load(True) is True
コード例 #7
0
ファイル: test_fields.py プロジェクト: nadirhamid/protean
 class Lottery(BaseEntity):
     jackpot = Boolean()
     numbers = Dict(required=True)
コード例 #8
0
ファイル: test_fields.py プロジェクト: nadirhamid/protean
 class Lottery(BaseEntity):
     jackpot = Boolean()
     numbers = List(content_type=Integer, required=True)
コード例 #9
0
class ProfileRepresentation:
    username = String(required=True, max_length=50)
    bio = String(max_length=1024)
    image = String(max_length=1024)
    following = Boolean()
コード例 #10
0
 def test_type_validation(self):
     """ Test type checking validation for the Field"""
     with pytest.raises(ValidationError):
         married = Boolean()
         married._load("x")