本文整理汇总了Python中app.user.models.User.is_following方法的典型用法代码示例。如果您正苦于以下问题:Python User.is_following方法的具体用法?Python User.is_following怎么用?Python User.is_following使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.user.models.User
的用法示例。
在下文中一共展示了User.is_following方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_follows
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import is_following [as 别名]
def test_follows(self):
u1 = User(username='cat', email='[email protected]', password='cat')
u2 = User(username='dog', email='[email protected]', password='dog')
db.session.add(u1)
db.session.add(u2)
db.session.commit()
self.assertFalse(u1.is_following(u2))
self.assertFalse(u1.is_followed_by(u2))
timestamp_before = datetime.utcnow()
u1.follow(u2)
db.session.add(u1)
db.session.commit()
timestamp_after = datetime.utcnow()
self.assertTrue(u1.is_following(u2))
self.assertFalse(u1.is_followed_by(u2))
self.assertTrue(u2.is_followed_by(u1))
self.assertTrue(u1.followed.count() == 1)
self.assertTrue(u2.followers.count() == 1)
f = u1.followed.all()[-1]
self.assertTrue(f.followed == u2)
#TODO:Fail
# print timestamp_before, f.timestamp, timestamp_after
# self.assertTrue(timestamp_before <= f.timestamp <= timestamp_after)
f = u2.followers.all()[-1]
self.assertTrue(f.follower == u1)
u1.unfollow(u2)
db.session.add(u1)
db.session.commit()
self.assertTrue(u1.followed.count() == 0)
self.assertTrue(u2.followers.count() == 0)
self.assertTrue(Follow.query.count() == 0)
u2.follow(u1)
db.session.add(u1)
db.session.add(u2)
db.session.commit()
db.session.delete(u2)
db.session.commit()
self.assertTrue(Follow.query.count() == 0)