Browse Source

added a new test case with a Response instance and cleaned up the code

pull/938/head
Mikael Åhlén 11 years ago
parent
commit
dbc4096191
  1. 26
      flask/testsuite/basic.py

26
flask/testsuite/basic.py

@ -736,15 +736,21 @@ class BasicFunctionalityTestCase(FlaskTestCase):
'X-Foo': 'Testing', 'X-Foo': 'Testing',
'Content-Type': 'text/plain; charset=utf-8' 'Content-Type': 'text/plain; charset=utf-8'
} }
@app.route("/two_args") @app.route('/two_args')
def from_two_args_tuple(): def from_two_args_tuple():
return "Hello", { return 'Hello', {
'X-Foo': 'Test', 'X-Foo': 'Test',
'Content-Type': 'text/plain; charset=utf-8' 'Content-Type': 'text/plain; charset=utf-8'
} }
@app.route("/args_status") @app.route('/args_status')
def from_status_tuple(): def from_status_tuple():
return "Hi, status!", 400 return 'Hi, status!', 400
@app.route('/args_header')
def from_response_instance_status_tuple():
return flask.Response('Hello world', 404), {
"X-Foo": "Bar",
"X-Bar": "Foo"
}
c = app.test_client() c = app.test_client()
self.assert_equal(c.get('/unicode').data, u'Hällo Wörld'.encode('utf-8')) self.assert_equal(c.get('/unicode').data, u'Hällo Wörld'.encode('utf-8'))
@ -754,18 +760,20 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(rv.headers['X-Foo'], 'Testing') self.assert_equal(rv.headers['X-Foo'], 'Testing')
self.assert_equal(rv.status_code, 400) self.assert_equal(rv.status_code, 400)
self.assert_equal(rv.mimetype, 'text/plain') self.assert_equal(rv.mimetype, 'text/plain')
rv2 = c.get('/two_args')
rv2 = c.get("/two_args")
self.assert_equal(rv2.data, b'Hello') self.assert_equal(rv2.data, b'Hello')
self.assert_equal(rv2.headers['X-Foo'], 'Test') self.assert_equal(rv2.headers['X-Foo'], 'Test')
self.assert_equal(rv2.status_code, 200) self.assert_equal(rv2.status_code, 200)
self.assert_equal(rv2.mimetype, 'text/plain') self.assert_equal(rv2.mimetype, 'text/plain')
rv3 = c.get('/args_status')
rv3 = c.get("/args_status")
self.assert_equal(rv3.data, b'Hi, status!') self.assert_equal(rv3.data, b'Hi, status!')
self.assert_equal(rv3.status_code, 400) self.assert_equal(rv3.status_code, 400)
self.assert_equal(rv3.mimetype, 'text/html') self.assert_equal(rv3.mimetype, 'text/html')
rv4 = c.get('/args_header')
self.assert_equal(rv4.data, b'Hello world')
self.assert_equal(rv4.headers['X-Foo'], 'Bar')
self.assert_equal(rv4.headers['X-Bar'], 'Foo')
self.assert_equal(rv4.status_code, 404)
def test_make_response(self): def test_make_response(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)

Loading…
Cancel
Save