本文整理汇总了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
)