本文整理汇总了Python中app.users.models.User.followed_posts方法的典型用法代码示例。如果您正苦于以下问题:Python User.followed_posts方法的具体用法?Python User.followed_posts怎么用?Python User.followed_posts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.followed_posts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_followed_posts
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import followed_posts [as 别名]
def test_followed_posts(self):
# create 4 users
user1 = User(name='mark', email='[email protected]')
user2 = User(name='rudy', email='[email protected]')
user3 = User(name='jack', email='[email protected]')
user4 = User(name='william', email='[email protected]')
db.session.add(user1)
db.session.add(user2)
db.session.add(user3)
db.session.add(user4)
# create 4 posts
utcnow = datetime.utcnow()
post1 = Post(body='post from mark', author=user1, timestamp=utcnow + timedelta(seconds=1))
post2 = Post(body='post from rudy', author=user2, timestamp=utcnow + timedelta(seconds=2))
post3 = Post(body='post from jack', author=user3, timestamp=utcnow + timedelta(seconds=3))
post4 = Post(body='post from william', author=user4, timestamp=utcnow + timedelta(seconds=4))
db.session.add(post1)
db.session.add(post2)
db.session.add(post3)
db.session.add(post4)
db.session.commit()
# setup the followers
user1 = user1.follow(user2)
user2 = user2.follow(user3)
user2 = user2.follow(user4)
user3 = user3.follow(user1)
user3 = user3.follow(user3)
user4 = user4.follow(user1)
user4 = user4.follow(user3)
user4 = user4.follow(user4)
db.session.add(user1)
db.session.add(user2)
db.session.add(user3)
db.session.add(user4)
db.session.commit()
f1 = user1.followed_posts()
f2 = user2.followed_posts()
f3 = user3.followed_posts()
f4 = user4.followed_posts()
self.assertEqual(f1.count(), 1)
self.assertEqual(f2.count(), 2)
self.assertEqual(f3.count(), 2)
self.assertEqual(f4.count(), 3)
self.assertEqual(f1.all(), [post2])
self.assertEqual(f2.all(), [post4, post3])
self.assertEqual(f3.all(), [post3, post1])
self.assertEqual(f4.all(), [post4, post3, post1])