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)
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 )
def test_type_validation(self): """ Test type checking validation for the Field""" with pytest.raises(ValidationError): tags = Boolean() tags._load('x')
class Adult(BaseAggregate): name = String(max_length=50) married = Boolean(default=True)
class Youth(BaseAggregate): name = String(max_length=50) married = Boolean(default=False)
def test_init(self): """Test successful Boolean Field initialization""" married = Boolean() assert married is not None assert married._load(True) is True
class Lottery(BaseEntity): jackpot = Boolean() numbers = Dict(required=True)
class Lottery(BaseEntity): jackpot = Boolean() numbers = List(content_type=Integer, required=True)
class ProfileRepresentation: username = String(required=True, max_length=50) bio = String(max_length=1024) image = String(max_length=1024) following = Boolean()
def test_type_validation(self): """ Test type checking validation for the Field""" with pytest.raises(ValidationError): married = Boolean() married._load("x")