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


Python User.follow方法代碼示例

本文整理匯總了Python中vilya.models.user.User.follow方法的典型用法代碼示例。如果您正苦於以下問題:Python User.follow方法的具體用法?Python User.follow怎麽用?Python User.follow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vilya.models.user.User的用法示例。


在下文中一共展示了User.follow方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: FollowTest

# 需要導入模塊: from vilya.models.user import User [as 別名]
# 或者: from vilya.models.user.User import follow [as 別名]
class FollowTest(APITestCase):
    def setUp(self):
        super(FollowTest, self).setUp()
        user_name1 = 'zhangchi'
        email = '%[email protected]' % user_name1
        self.zhangchi = User(user_name1, email)
        user_name2 = 'lijunpeng'
        email = '%[email protected]' % user_name2
        self.lijunpeng = User(user_name2, email)
        self.api_token_zhangchi = self.create_api_token('zhangchi')
        self.api_token_lijunpeng = self.create_api_token('lijunpeng')

    def test_get_auth_user_following(self):
        self.zhangchi.follow('qingfeng')
        self.zhangchi.follow('lisong_intern')
        self.zhangchi.follow('xingben')

        ret = self.app.get(
            "/api/user/following",
            status=403
            ).json
        self.assertProblemType(ret['type'], "unauthorized")

        ret = self.app.get(
            "/api/user/following",
            headers=dict(
                Authorization="Bearer %s" % self.api_token_zhangchi.token),
            status=200
            ).json

        self.assertEquals(len(ret), 3)
        user_name_list = map(lambda x: x['username'], ret)
        self.assertTrue('xingben' in user_name_list)

        User('test1', '[email protected]').follow('zhangchi')
        User('test2', '[email protected]').follow('zhangchi')
        ret = self.app.get(
            "/api/user/followers",
            headers=dict(
                Authorization="Bearer %s" % self.api_token_zhangchi.token),
            status=200
            ).json
        self.assertEquals(len(ret), 2)
        user_name_list = map(lambda x: x['username'], ret)
        self.assertTrue('test1' in user_name_list)

    def test_follow(self):
        self.app.get(
            "/api/user/following/%s/" % (self.lijunpeng.username),
            headers=dict(
                Authorization="Bearer %s" % self.api_token_zhangchi.token),
            status=404
            )

        self.app.put(
            "/api/user/following/%s/" % (self.lijunpeng.username),
            headers=dict(
                Authorization="Bearer %s" % self.api_token_zhangchi.token),
            status=204
            )

        self.app.get(
            "/api/user/following/%s/" % (self.lijunpeng.username),
            headers=dict(
                Authorization="Bearer %s" % self.api_token_zhangchi.token),
            status=204
            )

        self.app.delete(
            "/api/user/following/%s/" % (self.lijunpeng.username),
            headers=dict(
                Authorization="Bearer %s" % self.api_token_zhangchi.token),
            status=204
            )

        self.app.get(
            "/api/user/following/%s/" % (self.lijunpeng.username),
            headers=dict(
                Authorization="Bearer %s" % self.api_token_zhangchi.token),
            status=404
            )
開發者ID:leeccong,項目名稱:code,代碼行數:83,代碼來源:test_follow.py


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