friend route
フラスコ アプリケーションをテストしようとしましたが、次のエラーが発生しました。
AttributeError: 'NoneType' object has no attribute 'data'
モデルをテストすることはできましたが、フラスコをテストしたい場合 ('You are now Friend with')、上記のエラーが発生します。
私はフラスコ試験の専門家ではありません。
何が問題なのか、どうすれば修正できるのか教えていただけますか?
ビュー.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'))
test.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