Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

with `test_request_context()`.

authored by Pedro Algarvio · committed by Armin Ronacher · parent 5ecf01d · Browse files · 2 files+26 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>

Diff stats

2 files+26 added−0 removed

  • tests:+17 added−0 removed
  • other:+9 added−0 removed

2 files+26 added−0 removed

modified:flask/app.py+9 added
861 unmodified lines
862 :func:`werkzeug.create_environ` for more information, this863 function accepts the same arguments).864 """865 from werkzeug import create_environ866 environ_overrides = kwargs.setdefault('environ_overrides', {})867 if self.config.get('SERVER_NAME'):868 server_name = self.config.get('SERVER_NAME')869 if ':' not in server_name:870 server_name += ':80'871 http_host, http_port = server_name.split(':')872 environ_overrides.setdefault('SERVER_NAME', server_name)873 environ_overrides.setdefault('HTTP_HOST', server_name)874 environ_overrides.setdefault('SERVER_PORT', http_port)875 return self.request_context(create_environ(*args, **kwargs))876877 def wsgi_app(self, environ, start_response):878 """The actual WSGI application. This is not implemented in
42 unmodified lines
modified:tests/flask_tests.py+17 added
499 unmodified lines
500 def test_request_locals(self):501 self.assertEqual(repr(flask.g), '<LocalProxy unbound>')502 self.assertFalse(flask.g)503504 def test_proper_test_request_context(self):505 app = flask.Flask(__name__)506 app.config.update(507 SERVER_NAME='localhost.localdomain:5000'508 )509 @app.route('/')510 def index():511 return None512513 with app.test_request_context('/'):514 assert flask.url_for('index', _external=True) == 'http://localhost.localdomain:5000/'515516 def testit():517 with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):518 pass519 self.assertRaises(ValueError, testit)520521522class JSONTestCase(unittest.TestCase):523524 def test_jsonify(self):525 d = dict(a=23, b=42, c=[1, 2, 3])
744 unmodified lines