python - Testing Flask web app with unittest POST Error 500 -
this test.py file:
import unittest, views, json class flasktestcase(unittest.testcase): def setup(self): self.app = views.app.test_client() def test_index(self): rv = self.app.get('/') assert 'hamptons bank' in rv.data def test_credit(self): response = self.app.post('/credit', data=json.dumps({ 'amount': '20', 'account': '1' }), content_type='application/json') print response.data assert 'deposit of 20 account 1' in response.data if __name__ == '__main__': unittest.main()
the test_index method works fine, self.app.post keeps returning (in print response.data):
<!doctype html public "-//w3c//dtd html 3.2 final//en"> <title>500 internal server error</title> <h1>internal server error</h1> <p>the server encountered internal error , unable complete request. either server overloaded or there error in application.</p>
the method in views.py following:
@app.route('/credit', methods=['post']) def credit_account(): bank = bank() amount = int(request.json["amount"]) depositcommand = depositcommand(find_account(request.json["account"]), amount) bank.execute(depositcommand) message = "deposit of " + str(request.json["amount"]) + " account "+str(request.json["account"]) return message
what doing wrong?
this first time testing flask web app, still bit confused!
thank :-)
(from comment above): when testing, should set app.config['debug'] = true
, app.config['testing'] = true
.
Comments
Post a Comment