假设我有烧瓶应用程序现在我想测试 u=g.user.be_friend(user) 如果他们以前不是朋友的话,这会让用户彼此成为朋友但我不知道如何测试 g.user 和大多数重要的是 g.user.be_friend 你能帮忙thanx吗?
视图.py:
user = Users.query.filter_by(name = name).first()
if user is None:
flash('User %s not found.' % name)
return redirect(url_for('layout.user'))
if user == g.user:
flash('You can\'t Friend yourself!')
return redirect(url_for('layout.user',page=1, sortby='normal'))
u = g.user.be_friend(user)
mytest_app.py:
def test_friend_main(self):
e1 = Users(name='admine1', email='admine2@gmail.com', age=25)
e2 = Users(name='teste2', email='teste2@gmail.com', age=27)
db.session.add_all([e1, e2])
db.session.commit()
with self.client:
self.assertTrue(g.user =='admine1')
e1.be_friend(e2)
response=self.client.get('/friend/admine1', follow_redirects=True)
self.assertTrue('You are now Friend with !',response.data)