title: Testing Flask web app with unittest POST Error 500
body: <p>This is my test.py file:</p>
  
  <pre><code>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 to account 1' in response.data
  
  
  if __name__ == '__main__':
       unittest.main()
  </code></pre>
  
  <p>The test_index method works fine, but the self.app.post keeps returning (in print response.data):</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&gt;
  &lt;title&gt;500 Internal Server Error&lt;/title&gt;
  &lt;h1&gt;Internal Server Error&lt;/h1&gt;
  &lt;p&gt;The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.&lt;/p&gt;
  </code></pre>
  
  <p>The method in my views.py is the following:</p>
  
  <pre><code>@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"]) + " to account "+str(request.json["account"])
    return message
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>This is my first time testing a Flask web app, so I am still a bit confused!</p>
  
  <p>Thank you :-)</p>