title: Flask Application Unit-Test Assertion Error
body: <p>I've been long time reader, but this is my first time posting.</p>
  
  <p>Ok, so I'm trying to unit test a demo application in Flask and I don't know what I'm doing wrong.</p>
  
  <p>these are my "routes" in a file called <strong>manager.py</strong>:</p>
  
  <pre><code>@app.route('/')
  @app.route('/index')
  def hello():
      return render_template('base.html')
  
  
  @app.route('/hello/&lt;username&gt;')
  def hello_username(username):
      return "Hello %s" % username 
  </code></pre>
  
  <p>The first route is loading base.html template renders a "hi" message, which is working in the unit-test but the second route gets an assertion error.</p>
  
  <p>and this is my testing file <strong>manage_test.py</strong>:</p>
  
  <pre><code>class ManagerTestCase(unittest.TestCase):
  
      def setUp(self):
          self.app = app.test_client()
  
      def t_username(self, username):
          return self.app.post('/hello/&lt;username&gt;', follow_redirects=True)
  
      def test_username(self):
          rv = self.t_username('alberto')
          assert "Hello alberto" in rv.data
  
      def test_empty_db(self):
          rv = self.app.get('/')
          assert 'hi' in rv.data
  </code></pre>
  
  <p>This is the output from the unit-test run:</p>
  
  <pre><code>.F
  ======================================================================
  FAIL: test_username (tests.manage_tests.ManagerTestCase)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "/Users/albertogg/Dropbox/code/Python/flask-bootstrap/tests/manage_tests.py", line 15, in test_username
      assert "Hello alberto" in rv.data
  AssertionError
  
  ----------------------------------------------------------------------
  Ran 2 tests in 0.015s
  
  FAILED (failures=1)
  </code></pre>
  
  <p>I want to know if you guys can help me! what am I doing wrong or missing?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I did this and it's working</p>
  
  <p><pre> <code>
      class ManagerTestCase(unittest.TestCase):</p>
  
  <pre><code>    def setUp(self):
          self.app = app.test_client()
  
      def t_username(self, username):
          return self.app.get('/hello/%s' % (username), follow_redirects=True')
          # either that or the Advanced string formatting from the answer are working.
  
      def test_username(self):
          rv = self.t_username('alberto')
          assert "Hello alberto" in rv.data
  
      def test_empty_db(self):
          rv = self.app.get('/')
          assert 'hi' in rv.data
  </code></pre>
  
  <p></pre> </code></p>