You should change your hello_username to the following:
@app.route('/hello/', methods=['POST']) def hello_username(): return "Hello %s" % request.form.get('username', 'nobody')
required from flask import request .
And an example showing that it works:
> curl -X POST -i 'http://localhost:2000/hello/' -d "username=alberto" HTTP/1.0 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 9 Server: Werkzeug/0.8.3 Python/2.7.2 Date: Fri, 21 Dec 2012 05:42:49 GMT Hello alberto
And your test should look like this:
def test_username(self, username): return self.app.post('/hello', data={"username":username})
EDIT
For your comment:
@app.route('/hello/<username>', methods=['POST']) def hello_username(username): print request.args return "Hello %s" % username
But, then I do not know why you are using POST, since it is essentially POST without any POST body.
> curl -X POST -i 'http://localhost:2000/hello/alberto' HTTP/1.0 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 13 Server: Werkzeug/0.8.3 Python/2.7.2 Date: Fri, 21 Dec 2012 06:29:25 GMT Hello alberto
In this case, I will remove the requirement for the POST data together:
@app.route('/hello/<username>', methods=['POST']) def hello_username(username): print request.args return "Hello %s" % username > curl -i 'http://localhost:2000/hello/alberto' HTTP/1.0 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 13 Server: Werkzeug/0.8.3 Python/2.7.2 Date: Fri, 21 Dec 2012 06:31:10 GMT
Test using get will
def test_username(self, username): return self.app.get('/hello/%s' % (username), follow_redirects=True)
Or, if you have 2.6+,
def test_username(self, username): return self.app.get('/hello/{username}'.format(username=username), follow_redirects=True)