Browse Source

Moved testcase for test client context binding to the TestToolsTestCase

pull/308/merge
Armin Ronacher 14 years ago
parent
commit
485a6c332b
  1. 60
      tests/flask_tests.py

60
tests/flask_tests.py

@ -153,36 +153,6 @@ class ContextTestCase(FlaskTestCase):
else: else:
assert 0, 'expected runtime error' assert 0, 'expected runtime error'
def test_test_client_context_binding(self):
app = flask.Flask(__name__)
@app.route('/')
def index():
flask.g.value = 42
return 'Hello World!'
@app.route('/other')
def other():
1/0
with app.test_client() as c:
resp = c.get('/')
assert flask.g.value == 42
assert resp.data == 'Hello World!'
assert resp.status_code == 200
resp = c.get('/other')
assert not hasattr(flask.g, 'value')
assert 'Internal Server Error' in resp.data
assert resp.status_code == 500
flask.g.value = 23
try:
flask.g.value
except (AttributeError, RuntimeError):
pass
else:
raise AssertionError('some kind of exception expected')
class BasicFunctionalityTestCase(FlaskTestCase): class BasicFunctionalityTestCase(FlaskTestCase):
@ -1111,6 +1081,36 @@ class TestToolsTestCase(FlaskTestCase):
with c.session_transaction(): with c.session_transaction():
self.assert_(req is flask.request._get_current_object()) self.assert_(req is flask.request._get_current_object())
def test_test_client_context_binding(self):
app = flask.Flask(__name__)
@app.route('/')
def index():
flask.g.value = 42
return 'Hello World!'
@app.route('/other')
def other():
1/0
with app.test_client() as c:
resp = c.get('/')
assert flask.g.value == 42
assert resp.data == 'Hello World!'
assert resp.status_code == 200
resp = c.get('/other')
assert not hasattr(flask.g, 'value')
assert 'Internal Server Error' in resp.data
assert resp.status_code == 500
flask.g.value = 23
try:
flask.g.value
except (AttributeError, RuntimeError):
pass
else:
raise AssertionError('some kind of exception expected')
class InstanceTestCase(FlaskTestCase): class InstanceTestCase(FlaskTestCase):

Loading…
Cancel
Save