我尝试测试friend route
我的烧瓶应用程序,但收到错误:
AttributeError: 'NoneType' object has no attribute 'data'
我可以测试模型但是当我想测试烧瓶时('你现在是朋友')我得到了上面的错误。
我不是烧瓶测试的专家。
你能告诉我出了什么问题,我该如何解决?
视图.py:
@layout.route('/friend/<name>')
@login_required
def friend(name):
user = Users.query.filter_by(name = name).first()
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)
if u is None:
flash('You have been Friend with ' + name + '.')
return redirect(url_for('layout.user',page=1,sortby='normal'))
db.session.add(u)
db.session.commit()
flash('You are now Friend with ' + name + '!')
return redirect(url_for('layout.user', page=1,sortby='normal'))
测试.py:
def test_friend(self):
u1 = Users(name='monk1', email='monk1@example.com', age=25)
u2 = Users(name='monk2', email='monk2@example.com', age=27)
db.session.add(u1)
db.session.add(u2)
db.session.commit()
response = self.assertTrue(u1.be_friend(u2))
self.assertTrue('You have been Friend with monk2', response.data)
# I got error Here if I comment this line the test whole model.py works well But Now I want to test flash too that I get the mentioned error