Fix for Flask's ticket 126. A proper environment is now built to use

with `test_request_context()`.

Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>
This commit is contained in:
Pedro Algarvio 2010-10-21 20:31:13 +01:00 committed by Armin Ronacher
parent 5ecf01dd4e
commit 88883aa6db
2 changed files with 26 additions and 0 deletions

View file

@ -501,6 +501,23 @@ class BasicFunctionalityTestCase(unittest.TestCase):
self.assertEqual(repr(flask.g), '<LocalProxy unbound>')
self.assertFalse(flask.g)
def test_proper_test_request_context(self):
app = flask.Flask(__name__)
app.config.update(
SERVER_NAME='localhost.localdomain:5000'
)
@app.route('/')
def index():
return None
with app.test_request_context('/'):
assert flask.url_for('index', _external=True) == 'http://localhost.localdomain:5000/'
def testit():
with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):
pass
self.assertRaises(ValueError, testit)
class JSONTestCase(unittest.TestCase):