当前位置: 首页>>代码示例>>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;未经允许,请勿转载。