本文整理匯總了Python中app.users.models.User.is_following方法的典型用法代碼示例。如果您正苦於以下問題:Python User.is_following方法的具體用法?Python User.is_following怎麽用?Python User.is_following使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app.users.models.User
的用法示例。
在下文中一共展示了User.is_following方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_follow
# 需要導入模塊: from app.users.models import User [as 別名]
# 或者: from app.users.models.User import is_following [as 別名]
def test_follow(self):
user1 = User(name='mark', email='[email protected]')
user2 = User(name='rudy', email='[email protected]')
db.session.add(user1)
db.session.add(user2)
db.session.commit()
self.assertEqual(user1.is_following(user2), False)
self.assertEqual(user1.unfollow(user2), None)
user1 = user1.follow(user2)
db.session.add(user1)
db.session.commit()
# user1 has already followed user2
self.assertEqual(user1.follow(user2), None)
self.assertEqual(user1.followed.count(), 1)
self.assertEqual(user1.followed.first().name, 'rudy')
self.assertEqual(user2.followers.count(), 1)
self.assertEqual(user2.followers.first().name, 'mark')
user1 = user1.unfollow(user2)
db.session.add(user1)
db.session.commit()
self.assertEqual(user1.unfollow(user2), None)
self.assertEqual(user1.is_following(user2), False)
self.assertEqual(user1.followed.count(), 0)
self.assertEqual(user2.followers.count(), 0)