Skip to content
Myr

Correct tests

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

We've discovered that passing Unicode in Host actually works, except for test client limitations on Python 2 - and the only things that don't work are non-printable characters.

authored by Jarek Piórkowski · committed by Jarek Piórkowski · parent ed9775f · Browse files · 1 file+35 added−4 removed
This commit

State

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

Diff stats

1 file+35 added−4 removed

  • tests:+35 added−4 removed

1 file+35 added−4 removed

modified:tests/test_reqctx.py+35 added-4 removed
232 unmodified lines
233234def test_bad_environ_raises_bad_request():235 app = flask.Flask(__name__)236237 # We cannot use app.test_client() for the Unicode-rich Host header,238 # because werkzeug enforces latin1 on Python 2.239 # However it works when actually passed to the server.240241 from flask.testing import make_test_environ_builder242 builder = make_test_environ_builder(app)243 environ = builder.get_environ()244245 # use a non-printable character in the Host - this is key to this test246 environ['HTTP_HOST'] = u'\x8a'247248 with app.request_context(environ):249 response = app.full_dispatch_request()250 assert response.status_code == 400251252253def test_environ_for_valid_idna_completes():254 app = flask.Flask(__name__)255256 @app.route('/')257 def index():239 # shouldn't get here anyway240 assert False258 return 'Hello World!'259242 response = app.test_client().get('/', headers={'host': 'ąśź.com'})243 assert response.status_code == 400260 # We cannot use app.test_client() for the Unicode-rich Host header,261 # because werkzeug enforces latin1 on Python 2.262 # However it works when actually passed to the server.263264 from flask.testing import make_test_environ_builder265 builder = make_test_environ_builder(app)266 environ = builder.get_environ()267268 # these characters are all IDNA-compatible269 environ['HTTP_HOST'] = u'ąśźäüжŠßя.com'270271 with app.request_context(environ):272 response = app.full_dispatch_request()273274 assert response.status_code == 200275276277def test_normal_environ_completes():278 app = flask.Flask(__name__)279280 @app.route('/')
5 unmodified lines