當前位置: 首頁>>代碼示例>>Python>>正文


Python User.followed_posts方法代碼示例

本文整理匯總了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])
開發者ID:dingweihua,項目名稱:microblog,代碼行數:52,代碼來源:test_models.py


注:本文中的app.users.models.User.followed_posts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。