I try to test friend route
for my flask application, but got the error:
AttributeError: 'NoneType' object has no attribute 'data'
I could test the model but when I want to test flask ('You are now Friend with ') I get the error above.
I am not expert in flask testing.
Can you tell me what is wrong and how can I fix it?
view.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