本文整理匯總了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
)