test_basic.py
This file
Path
tests/test_basic.py
1,816 lines · 48.4 KiB · Python
Last changed by
Don't overwrite Vary header when setting for cookie access #2317Nina Zakharenkobefore adoptione7cd68b
History of this fileTake it
The walk stopped after 200 commits: lines older than d80fabd point at it.
Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1–27why, one step back1# -*- coding: utf-8 -*-2"""3 tests.basic4 ~~~~~~~~~~~~~~~~~~~~~56 The basic functionality.78 :copyright: (c) 2015 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112import pytest1314import re15import uuid16import time17import flask18import pickle19from datetime import datetime20from threading import Thread21from flask._compat import text_type22from werkzeug.exceptions import BadRequest, NotFound, Forbidden23from werkzeug.http import parse_date24from werkzeug.routing import BuildError25import werkzeug.serving2627DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 28why, one step back28def test_options_work(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 29–31why, one step back29 @app.route('/', methods=['GET', 'POST'])30 def index():31 return 'Hello World'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 32–33why, one step back3233 rv = client.open('/', method='OPTIONS')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 34–37why, one step back34 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']35 assert rv.data == b''3637DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 38why, one step back38def test_options_on_multiple_rules(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 39–45why, one step back39 @app.route('/', methods=['GET', 'POST'])40 def index():41 return 'Hello World'4243 @app.route('/', methods=['PUT'])44 def index_put():45 return 'Aha!'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 46–47why, one step back4647 rv = client.open('/', method='OPTIONS')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 48–50why, one step back48 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']4950Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
line 51why, one step back51def test_provide_automatic_options_attr():Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 52–55why, one step back52 app = flask.Flask(__name__)5354 def index():55 return 'Hello World!'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 56why, one step back56Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 57–65why, one step back57 index.provide_automatic_options = False58 app.route('/')(index)59 rv = app.test_client().open('/', method='OPTIONS')60 assert rv.status_code == 4056162 app = flask.Flask(__name__)6364 def index2():65 return 'Hello World!'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 66why, one step back66Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 67–70why, one step back67 index2.provide_automatic_options = True68 app.route('/', methods=['OPTIONS'])(index2)69 rv = app.test_client().open('/', method='OPTIONS')70 assert sorted(rv.allow) == ['OPTIONS']Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
lines 71–72why, one step back7172DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 73why, one step back73def test_provide_automatic_options_kwarg(app, client):Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
lines 74–84why, one step back74 def index():75 return flask.request.method7677 def more():78 return flask.request.method7980 app.add_url_rule('/', view_func=index, provide_automatic_options=False)81 app.add_url_rule(82 '/more', view_func=more, methods=['GET', 'POST'],83 provide_automatic_options=False84 )DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 85why, one step back85 assert client.get('/').data == b'GET'Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
line 86why, one step back86DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 87why, one step back87 rv = client.post('/')Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
lines 88–91why, one step back88 assert rv.status_code == 40589 assert sorted(rv.allow) == ['GET', 'HEAD']9091 # Older versions of Werkzeug.test.Client don't have an options methodDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 92–93why, one step back92 if hasattr(client, 'options'):93 rv = client.options('/')Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
line 94why, one step back94 else:DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 95why, one step back95 rv = client.open('/', method='OPTIONS')Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
lines 96–98why, one step back9697 assert rv.status_code == 40598DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 99why, one step back99 rv = client.head('/')Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
lines 100–101why, one step back100 assert rv.status_code == 200101 assert not rv.data # head truncatesDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 102–103why, one step back102 assert client.post('/more').data == b'POST'103 assert client.get('/more').data == b'GET'Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
line 104why, one step back104DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 105why, one step back105 rv = client.delete('/more')Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
lines 106–108why, one step back106 assert rv.status_code == 405107 assert sorted(rv.allow) == ['GET', 'HEAD', 'POST']108DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 109–110why, one step back109 if hasattr(client, 'options'):110 rv = client.options('/more')Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
line 111why, one step back111 else:DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 112why, one step back112 rv = client.open('/more', method='OPTIONS')Merge pull request #2249 from davidism/provide-automatic-optionsDavid Lordbefore adoption9569e8c
lines 113–114why, one step back113114 assert rv.status_code == 405Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 115–116why, one step back115116DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 117why, one step back117def test_request_dispatching(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 118–125why, one step back118 @app.route('/')119 def index():120 return flask.request.method121122 @app.route('/more', methods=['GET', 'POST'])123 def more():124 return flask.request.method125DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 126–127why, one step back126 assert client.get('/').data == b'GET'127 rv = client.post('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 128–129why, one step back128 assert rv.status_code == 405129 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS']DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 130why, one step back130 rv = client.head('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 131–132why, one step back131 assert rv.status_code == 200132 assert not rv.data # head truncatesDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 133–135why, one step back133 assert client.post('/more').data == b'POST'134 assert client.get('/more').data == b'GET'135 rv = client.delete('/more')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 136–139why, one step back136 assert rv.status_code == 405137 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']138139DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 140why, one step back140def test_disallow_string_for_allowed_methods(app):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 141–146why, one step back141 with pytest.raises(TypeError):142 @app.route('/', methods='GET POST')143 def index():144 return "Hey"145146DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 147why, one step back147def test_url_mapping(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 148–164why, one step back148 random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"149150 def index():151 return flask.request.method152153 def more():154 return flask.request.method155156 def options():157 return random_uuid4158159 app.add_url_rule('/', 'index', index)160 app.add_url_rule('/more', 'more', more, methods=['GET', 'POST'])161162 # Issue 1288: Test that automatic options are not added when non-uppercase 'options' in methods163 app.add_url_rule('/options', 'options', options, methods=['options'])164DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 165–166why, one step back165 assert client.get('/').data == b'GET'166 rv = client.post('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 167–168why, one step back167 assert rv.status_code == 405168 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS']DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 169why, one step back169 rv = client.head('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 170–171why, one step back170 assert rv.status_code == 200171 assert not rv.data # head truncatesDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 172–174why, one step back172 assert client.post('/more').data == b'POST'173 assert client.get('/more').data == b'GET'174 rv = client.delete('/more')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 175–176why, one step back175 assert rv.status_code == 405176 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 177why, one step back177 rv = client.open('/options', method='OPTIONS')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 178–181why, one step back178 assert rv.status_code == 200179 assert random_uuid4 in rv.data.decode("utf-8")180181DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 182why, one step back182def test_werkzeug_routing(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 183–193why, one step back183 from werkzeug.routing import Submount, Rule184 app.url_map.add(Submount('/foo', [185 Rule('/bar', endpoint='bar'),186 Rule('/', endpoint='index')187 ]))188189 def bar():190 return 'bar'191192 def index():193 return 'index'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 194why, one step back194Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 195–197why, one step back195 app.view_functions['bar'] = bar196 app.view_functions['index'] = index197DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 198–199why, one step back198 assert client.get('/foo/').data == b'index'199 assert client.get('/foo/bar').data == b'bar'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 200–201why, one step back200201DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 202why, one step back202def test_endpoint_decorator(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 203–216why, one step back203 from werkzeug.routing import Submount, Rule204 app.url_map.add(Submount('/foo', [205 Rule('/bar', endpoint='bar'),206 Rule('/', endpoint='index')207 ]))208209 @app.endpoint('bar')210 def bar():211 return 'bar'212213 @app.endpoint('index')214 def index():215 return 'index'216DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 217–218why, one step back217 assert client.get('/foo/').data == b'index'218 assert client.get('/foo/bar').data == b'bar'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 219–220why, one step back219220DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 221why, one step back221def test_session(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 222–232why, one step back222 app.secret_key = 'testkey'223224 @app.route('/set', methods=['POST'])225 def set():226 flask.session['value'] = flask.request.form['value']227 return 'value set'228229 @app.route('/get')230 def get():231 return flask.session['value']232DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 233–234why, one step back233 assert client.post('/set', data={'value': '42'}).data == b'value set'234 assert client.get('/get').data == b'42'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 235–236why, one step back235236DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 237why, one step back237def test_session_using_server_name(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 238–246why, one step back238 app.config.update(239 SECRET_KEY='foo',240 SERVER_NAME='example.com'241 )242243 @app.route('/')244 def index():245 flask.session['testing'] = 42246 return 'Hello World'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 247–248why, one step back247248 rv = client.get('/', 'http://example.com/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 249–252why, one step back249 assert 'domain=.example.com' in rv.headers['set-cookie'].lower()250 assert 'httponly' in rv.headers['set-cookie'].lower()251252DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 253why, one step back253def test_session_using_server_name_and_port(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 254–262why, one step back254 app.config.update(255 SECRET_KEY='foo',256 SERVER_NAME='example.com:8080'257 )258259 @app.route('/')260 def index():261 flask.session['testing'] = 42262 return 'Hello World'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 263–264why, one step back263264 rv = client.get('/', 'http://example.com:8080/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 265–268why, one step back265 assert 'domain=.example.com' in rv.headers['set-cookie'].lower()266 assert 'httponly' in rv.headers['set-cookie'].lower()267268DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 269why, one step back269def test_session_using_server_name_port_and_path(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 270–279why, one step back270 app.config.update(271 SECRET_KEY='foo',272 SERVER_NAME='example.com:8080',273 APPLICATION_ROOT='/foo'274 )275276 @app.route('/')277 def index():278 flask.session['testing'] = 42279 return 'Hello World'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 280–281why, one step back280281 rv = client.get('/', 'http://example.com:8080/foo')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 282–286why, one step back282 assert 'domain=example.com' in rv.headers['set-cookie'].lower()283 assert 'path=/foo' in rv.headers['set-cookie'].lower()284 assert 'httponly' in rv.headers['set-cookie'].lower()285286DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 287why, one step back287def test_session_using_application_root(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 288–306why, one step back288 class PrefixPathMiddleware(object):289 def __init__(self, app, prefix):290 self.app = app291 self.prefix = prefix292293 def __call__(self, environ, start_response):294 environ['SCRIPT_NAME'] = self.prefix295 return self.app(environ, start_response)296297 app.wsgi_app = PrefixPathMiddleware(app.wsgi_app, '/bar')298 app.config.update(299 SECRET_KEY='foo',300 APPLICATION_ROOT='/bar'301 )302303 @app.route('/')304 def index():305 flask.session['testing'] = 42306 return 'Hello World'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 307–308why, one step back307308 rv = client.get('/', 'http://example.com:8080/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 309–311why, one step back309 assert 'path=/bar' in rv.headers['set-cookie'].lower()310311DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 312why, one step back312def test_session_using_session_settings(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 313–326why, one step back313 app.config.update(314 SECRET_KEY='foo',315 SERVER_NAME='www.example.com:8080',316 APPLICATION_ROOT='/test',317 SESSION_COOKIE_DOMAIN='.example.com',318 SESSION_COOKIE_HTTPONLY=False,319 SESSION_COOKIE_SECURE=True,320 SESSION_COOKIE_PATH='/'321 )322323 @app.route('/')324 def index():325 flask.session['testing'] = 42326 return 'Hello World'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 327–328why, one step back327328 rv = client.get('/', 'http://www.example.com:8080/test/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 329–335why, one step back329 cookie = rv.headers['set-cookie'].lower()330 assert 'domain=.example.com' in cookie331 assert 'path=/' in cookie332 assert 'secure' in cookie333 assert 'httponly' not in cookie334335DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 336why, one step back336def test_session_localhost_warning(recwarn, app, client):Merge pull request #2282 from davidism/session-cookie-domainDavid Lordbefore adoptionff361d3
lines 337–346why, one step back337 app.config.update(338 SECRET_KEY='testing',339 SERVER_NAME='localhost:5000',340 )341342 @app.route('/')343 def index():344 flask.session['testing'] = 42345 return 'testing'346DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 347why, one step back347 rv = client.get('/', 'http://localhost:5000/')Merge pull request #2282 from davidism/session-cookie-domainDavid Lordbefore adoptionff361d3
lines 348–352why, one step back348 assert 'domain' not in rv.headers['set-cookie'].lower()349 w = recwarn.pop(UserWarning)350 assert '"localhost" is not a valid cookie domain' in str(w.message)351352DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 353why, one step back353def test_session_ip_warning(recwarn, app, client):Merge pull request #2282 from davidism/session-cookie-domainDavid Lordbefore adoptionff361d3
lines 354–363why, one step back354 app.config.update(355 SECRET_KEY='testing',356 SERVER_NAME='127.0.0.1:5000',357 )358359 @app.route('/')360 def index():361 flask.session['testing'] = 42362 return 'testing'363DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 364why, one step back364 rv = client.get('/', 'http://127.0.0.1:5000/')Merge pull request #2282 from davidism/session-cookie-domainDavid Lordbefore adoptionff361d3
lines 365–369why, one step back365 assert 'domain=127.0.0.1' in rv.headers['set-cookie'].lower()366 w = recwarn.pop(UserWarning)367 assert 'cookie domain is an IP' in str(w.message)368369Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 370–375why, one step back370def test_missing_session():371 app = flask.Flask(__name__)372373 def expect_exception(f, *args, **kwargs):374 e = pytest.raises(RuntimeError, f, *args, **kwargs)375 assert e.value.args and 'session is unavailable' in e.value.args[0]DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 376why, one step back376Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 377–382why, one step back377 with app.test_request_context():378 assert flask.session.get('missing_key') is None379 expect_exception(flask.session.__setitem__, 'foo', 42)380 expect_exception(flask.session.pop, 'foo')381382DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 383why, one step back383def test_session_expiration(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 384–398why, one step back384 permanent = True385 app.secret_key = 'testkey'386387 @app.route('/')388 def index():389 flask.session['test'] = 42390 flask.session.permanent = permanent391 return ''392393 @app.route('/test')394 def test():395 return text_type(flask.session.permanent)396397 rv = client.get('/')398 assert 'set-cookie' in rv.headersMerge pull request #2148 from drewja/masterDavid Lordbefore adoption22c613b
line 399why, one step back399 match = re.search(r'(?i)\bexpires=([^;]+)', rv.headers['set-cookie'])Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 400–409why, one step back400 expires = parse_date(match.group())401 expected = datetime.utcnow() + app.permanent_session_lifetime402 assert expires.year == expected.year403 assert expires.month == expected.month404 assert expires.day == expected.day405406 rv = client.get('/test')407 assert rv.data == b'True'408409 permanent = FalseDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 410why, one step back410 rv = client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 411–415why, one step back411 assert 'set-cookie' in rv.headers412 match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])413 assert match is None414415DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 416why, one step back416def test_session_stored_last(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 417–427why, one step back417 app.secret_key = 'development-key'418419 @app.after_request420 def modify_session(response):421 flask.session['foo'] = 42422 return response423424 @app.route('/')425 def dump_session_contents():426 return repr(flask.session.get('foo'))427DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 428–429why, one step back428 assert client.get('/').data == b'None'429 assert client.get('/').data == b'42'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 430–431why, one step back430431DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 432why, one step back432def test_session_special_types(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 433–449why, one step back433 app.secret_key = 'development-key'434 now = datetime.utcnow().replace(microsecond=0)435 the_uuid = uuid.uuid4()436437 @app.after_request438 def modify_session(response):439 flask.session['m'] = flask.Markup('Hello!')440 flask.session['u'] = the_uuid441 flask.session['dt'] = now442 flask.session['b'] = b'\xff'443 flask.session['t'] = (1, 2, 3)444 return response445446 @app.route('/')447 def dump_session_contents():448 return pickle.dumps(dict(flask.session))449DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 450–451why, one step back450 client.get('/')451 rv = pickle.loads(client.get('/').data)Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 452–460why, one step back452 assert rv['m'] == flask.Markup('Hello!')453 assert type(rv['m']) == flask.Markup454 assert rv['dt'] == now455 assert rv['u'] == the_uuid456 assert rv['b'] == b'\xff'457 assert type(rv['b']) == bytes458 assert rv['t'] == (1, 2, 3)459460DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 461why, one step back461def test_session_cookie_setting(app):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 462–502why, one step back462 app.secret_key = 'dev key'463 is_permanent = True464465 @app.route('/bump')466 def bump():467 rv = flask.session['foo'] = flask.session.get('foo', 0) + 1468 flask.session.permanent = is_permanent469 return str(rv)470471 @app.route('/read')472 def read():473 return str(flask.session.get('foo', 0))474475 def run_test(expect_header):476 with app.test_client() as c:477 assert c.get('/bump').data == b'1'478 assert c.get('/bump').data == b'2'479 assert c.get('/bump').data == b'3'480481 rv = c.get('/read')482 set_cookie = rv.headers.get('set-cookie')483 assert (set_cookie is not None) == expect_header484 assert rv.data == b'3'485486 is_permanent = True487 app.config['SESSION_REFRESH_EACH_REQUEST'] = True488 run_test(expect_header=True)489490 is_permanent = True491 app.config['SESSION_REFRESH_EACH_REQUEST'] = False492 run_test(expect_header=False)493494 is_permanent = False495 app.config['SESSION_REFRESH_EACH_REQUEST'] = True496 run_test(expect_header=False)497498 is_permanent = False499 app.config['SESSION_REFRESH_EACH_REQUEST'] = False500 run_test(expect_header=False)501502DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 503why, one step back503def test_session_vary_cookie(app, client):Merge pull request #2288 from davidism/vary-cookiesDavid Lordbefore adoptionb11f735
lines 504–522why, one step back504 app.secret_key = 'testkey'505506 @app.route('/set')507 def set_session():508 flask.session['test'] = 'test'509 return ''510511 @app.route('/get')512 def get():513 return flask.session.get('test')514515 @app.route('/getitem')516 def getitem():517 return flask.session['test']518519 @app.route('/setdefault')520 def setdefault():521 return flask.session.setdefault('test', 'default')522Don't overwrite Vary header when setting for cookie access #2317Nina Zakharenkobefore adoptione7cd68b
lines 523–536why, one step back523 @app.route('/vary-cookie-header-set')524 def vary_cookie_header_set():525 response = flask.Response()526 response.headers['Vary'] = 'Cookie'527 flask.session['test'] = 'test'528 return response529530 @app.route('/vary-header-set')531 def vary_header_set():532 response = flask.Response()533 response.headers['Vary'] = 'Accept-Encoding, Accept-Language'534 flask.session['test'] = 'test'535 return response536Merge pull request #2288 from davidism/vary-cookiesDavid Lordbefore adoptionb11f735
lines 537–540why, one step back537 @app.route('/no-vary-header')538 def no_vary_header():539 return ''540Don't overwrite Vary header when setting for cookie access #2317Nina Zakharenkobefore adoptione7cd68b
line 541why, one step back541 def expect(path, header_value='Cookie'):DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 542why, one step back542 rv = client.get(path)Merge pull request #2288 from davidism/vary-cookiesDavid Lordbefore adoptionb11f735
line 543why, one step back543Don't overwrite Vary header when setting for cookie access #2317Nina Zakharenkobefore adoptione7cd68b
lines 544–547why, one step back544 if header_value:545 # The 'Vary' key should exist in the headers only once.546 assert len(rv.headers.get_all('Vary')) == 1547 assert rv.headers['Vary'] == header_valueMerge pull request #2288 from davidism/vary-cookiesDavid Lordbefore adoptionb11f735
lines 548–554why, one step back548 else:549 assert 'Vary' not in rv.headers550551 expect('/set')552 expect('/get')553 expect('/getitem')554 expect('/setdefault')Don't overwrite Vary header when setting for cookie access #2317Nina Zakharenkobefore adoptione7cd68b
lines 555–557why, one step back555 expect('/vary-cookie-header-set')556 expect('/vary-header-set', 'Accept-Encoding, Accept-Language, Cookie')557 expect('/no-vary-header', None)Merge pull request #2288 from davidism/vary-cookiesDavid Lordbefore adoptionb11f735
lines 558–559why, one step back558559DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 560why, one step back560def test_flashes(app, req_ctx):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 561–562why, one step back561 app.secret_key = 'testkey'562DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 563–568why, one step back563 assert not flask.session.modified564 flask.flash('Zap')565 flask.session.modified = False566 flask.flash('Zip')567 assert flask.session.modified568 assert list(flask.get_flashed_messages()) == ['Zap', 'Zip']Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 569–570why, one step back569570DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 571why, one step back571def test_extended_flashing(app):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 572–635why, one step back572 # Be sure app.testing=True below, else tests can fail silently.573 #574 # Specifically, if app.testing is not set to True, the AssertionErrors575 # in the view functions will cause a 500 response to the test client576 # instead of propagating exceptions.577578 app.secret_key = 'testkey'579580 @app.route('/')581 def index():582 flask.flash(u'Hello World')583 flask.flash(u'Hello World', 'error')584 flask.flash(flask.Markup(u'<em>Testing</em>'), 'warning')585 return ''586587 @app.route('/test/')588 def test():589 messages = flask.get_flashed_messages()590 assert list(messages) == [591 u'Hello World',592 u'Hello World',593 flask.Markup(u'<em>Testing</em>')594 ]595 return ''596597 @app.route('/test_with_categories/')598 def test_with_categories():599 messages = flask.get_flashed_messages(with_categories=True)600 assert len(messages) == 3601 assert list(messages) == [602 ('message', u'Hello World'),603 ('error', u'Hello World'),604 ('warning', flask.Markup(u'<em>Testing</em>'))605 ]606 return ''607608 @app.route('/test_filter/')609 def test_filter():610 messages = flask.get_flashed_messages(611 category_filter=['message'], with_categories=True)612 assert list(messages) == [('message', u'Hello World')]613 return ''614615 @app.route('/test_filters/')616 def test_filters():617 messages = flask.get_flashed_messages(618 category_filter=['message', 'warning'], with_categories=True)619 assert list(messages) == [620 ('message', u'Hello World'),621 ('warning', flask.Markup(u'<em>Testing</em>'))622 ]623 return ''624625 @app.route('/test_filters_without_returning_categories/')626 def test_filters2():627 messages = flask.get_flashed_messages(628 category_filter=['message', 'warning'])629 assert len(messages) == 2630 assert messages[0] == u'Hello World'631 assert messages[1] == flask.Markup(u'<em>Testing</em>')632 return ''633634 # Create new test client on each test to clean flashed messages.635DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 636–638why, one step back636 client = app.test_client()637 client.get('/')638 client.get('/test_with_categories/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 639why, one step back639DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 640–642why, one step back640 client = app.test_client()641 client.get('/')642 client.get('/test_filter/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 643why, one step back643DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 644–646why, one step back644 client = app.test_client()645 client.get('/')646 client.get('/test_filters/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 647why, one step back647DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 648–650why, one step back648 client = app.test_client()649 client.get('/')650 client.get('/test_filters_without_returning_categories/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 651–652why, one step back651652DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 653why, one step back653def test_request_processing(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 654–670why, one step back654 evts = []655656 @app.before_request657 def before_request():658 evts.append('before')659660 @app.after_request661 def after_request(response):662 response.data += b'|after'663 evts.append('after')664 return response665666 @app.route('/')667 def index():668 assert 'before' in evts669 assert 'after' not in evts670 return 'request'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 671why, one step back671Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 672why, one step back672 assert 'after' not in evtsDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 673why, one step back673 rv = client.get('/').dataMerge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 674–677why, one step back674 assert 'after' in evts675 assert rv == b'request|after'676677DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 678why, one step back678def test_request_preprocessing_early_return(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 679–699why, one step back679 evts = []680681 @app.before_request682 def before_request1():683 evts.append(1)684685 @app.before_request686 def before_request2():687 evts.append(2)688 return "hello"689690 @app.before_request691 def before_request3():692 evts.append(3)693 return "bye"694695 @app.route('/')696 def index():697 evts.append('index')698 return "damnit"699DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 700why, one step back700 rv = client.get('/').data.strip()Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 701–704why, one step back701 assert rv == b'hello'702 assert evts == [1, 2]703704DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 705why, one step back705def test_after_request_processing(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 706–711why, one step back706 @app.route('/')707 def index():708 @flask.after_this_request709 def foo(response):710 response.headers['X-Foo'] = 'a header'711 return responseDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 712why, one step back712Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 713why, one step back713 return 'Test'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 714–715why, one step back714715 resp = client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 716–719why, one step back716 assert resp.status_code == 200717 assert resp.headers['X-Foo'] == 'a header'718719DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 720why, one step back720def test_teardown_request_handler(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 721–730why, one step back721 called = []722723 @app.teardown_request724 def teardown_request(exc):725 called.append(True)726 return "Ignored"727728 @app.route('/')729 def root():730 return "Response"DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 731–732why, one step back731732 rv = client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 733–737why, one step back733 assert rv.status_code == 200734 assert b'Response' in rv.data735 assert len(called) == 1736737DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 738why, one step back738def test_teardown_request_handler_debug_mode(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 739–748why, one step back739 called = []740741 @app.teardown_request742 def teardown_request(exc):743 called.append(True)744 return "Ignored"745746 @app.route('/')747 def root():748 return "Response"DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 749–750why, one step back749750 rv = client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 751–755why, one step back751 assert rv.status_code == 200752 assert b'Response' in rv.data753 assert len(called) == 1754755DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 756why, one step back756def test_teardown_request_handler_error(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 757–758why, one step back757 called = []758 app.config['LOGGER_HANDLER_POLICY'] = 'never'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 759why, one step back759 app.testing = FalseMerge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 760–787why, one step back760761 @app.teardown_request762 def teardown_request1(exc):763 assert type(exc) == ZeroDivisionError764 called.append(True)765 # This raises a new error and blows away sys.exc_info(), so we can766 # test that all teardown_requests get passed the same original767 # exception.768 try:769 raise TypeError()770 except:771 pass772773 @app.teardown_request774 def teardown_request2(exc):775 assert type(exc) == ZeroDivisionError776 called.append(True)777 # This raises a new error and blows away sys.exc_info(), so we can778 # test that all teardown_requests get passed the same original779 # exception.780 try:781 raise TypeError()782 except:783 pass784785 @app.route('/')786 def fails():787 1 // 0DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 788–789why, one step back788789 rv = client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 790–794why, one step back790 assert rv.status_code == 500791 assert b'Internal Server Error' in rv.data792 assert len(called) == 2793794DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 795why, one step back795def test_before_after_request_order(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 796–826why, one step back796 called = []797798 @app.before_request799 def before1():800 called.append(1)801802 @app.before_request803 def before2():804 called.append(2)805806 @app.after_request807 def after1(response):808 called.append(4)809 return response810811 @app.after_request812 def after2(response):813 called.append(3)814 return response815816 @app.teardown_request817 def finish1(exc):818 called.append(6)819820 @app.teardown_request821 def finish2(exc):822 called.append(5)823824 @app.route('/')825 def index():826 return '42'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 827–828why, one step back827828 rv = client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 829–832why, one step back829 assert rv.data == b'42'830 assert called == [1, 2, 3, 4, 5, 6]831832DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 833why, one step back833def test_error_handling(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 834why, one step back834 app.config['LOGGER_HANDLER_POLICY'] = 'never'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 835why, one step back835 app.testing = FalseMerge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 836–859why, one step back836837 @app.errorhandler(404)838 def not_found(e):839 return 'not found', 404840841 @app.errorhandler(500)842 def internal_server_error(e):843 return 'internal server error', 500844845 @app.errorhandler(Forbidden)846 def forbidden(e):847 return 'forbidden', 403848849 @app.route('/')850 def index():851 flask.abort(404)852853 @app.route('/error')854 def error():855 1 // 0856857 @app.route('/forbidden')858 def error2():859 flask.abort(403)DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 860–861why, one step back860861 rv = client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 862–863why, one step back862 assert rv.status_code == 404863 assert rv.data == b'not found'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 864why, one step back864 rv = client.get('/error')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 865–866why, one step back865 assert rv.status_code == 500866 assert b'internal server error' == rv.dataDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 867why, one step back867 rv = client.get('/forbidden')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 868–871why, one step back868 assert rv.status_code == 403869 assert b'forbidden' == rv.data870871DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 872why, one step back872def test_error_handling_processing(app, client):Merge pull request #2013 from pallets/bugfix/error-handler-error-handlerArmin Ronacherbefore adoption9e41eca
line 873why, one step back873 app.config['LOGGER_HANDLER_POLICY'] = 'never'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 874why, one step back874 app.testing = FalseMerge pull request #2013 from pallets/bugfix/error-handler-error-handlerArmin Ronacherbefore adoption9e41eca
lines 875–888why, one step back875876 @app.errorhandler(500)877 def internal_server_error(e):878 return 'internal server error', 500879880 @app.route('/')881 def broken_func():882 1 // 0883884 @app.after_request885 def after_request(resp):886 resp.mimetype = 'text/x-special'887 return resp888DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 889–891why, one step back889 resp = client.get('/')890 assert resp.mimetype == 'text/x-special'891 assert resp.data == b'internal server error'Merge pull request #2013 from pallets/bugfix/error-handler-error-handlerArmin Ronacherbefore adoption9e41eca
lines 892–893why, one step back892893DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 894why, one step back894def test_baseexception_error_handling(app, client):Merge branch '0.12-maintenance'Markus Unterwaditzerbefore adoptionde555c8
line 895why, one step back895 app.config['LOGGER_HANDLER_POLICY'] = 'never'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 896why, one step back896 app.testing = FalseMerge branch '0.12-maintenance'Markus Unterwaditzerbefore adoptionde555c8
lines 897–901why, one step back897898 @app.route('/')899 def broken_func():900 raise KeyboardInterrupt()901DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 902–903why, one step back902 with pytest.raises(KeyboardInterrupt):903 client.get('/')Merge branch '0.12-maintenance'Markus Unterwaditzerbefore adoptionde555c8
lines 904–909why, one step back904905 ctx = flask._request_ctx_stack.top906 assert ctx.preserved907 assert type(ctx._preserved_exc) is KeyboardInterrupt908909DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 910why, one step back910def test_before_request_and_routing_errors(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 911–917why, one step back911 @app.before_request912 def attach_something():913 flask.g.something = 'value'914915 @app.errorhandler(404)916 def return_something(error):917 return flask.g.something, 404DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 918–919why, one step back918919 rv = client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 920–923why, one step back920 assert rv.status_code == 404921 assert rv.data == b'value'922923DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 924why, one step back924def test_user_error_handling(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 925–936why, one step back925 class MyException(Exception):926 pass927928 @app.errorhandler(MyException)929 def handle_my_exception(e):930 assert isinstance(e, MyException)931 return '42'932933 @app.route('/')934 def index():935 raise MyException()936DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 937why, one step back937 assert client.get('/').data == b'42'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 938–939why, one step back938939DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 940why, one step back940def test_http_error_subclass_handling(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 941–966why, one step back941 class ForbiddenSubclass(Forbidden):942 pass943944 @app.errorhandler(ForbiddenSubclass)945 def handle_forbidden_subclass(e):946 assert isinstance(e, ForbiddenSubclass)947 return 'banana'948949 @app.errorhandler(403)950 def handle_forbidden_subclass(e):951 assert not isinstance(e, ForbiddenSubclass)952 assert isinstance(e, Forbidden)953 return 'apple'954955 @app.route('/1')956 def index1():957 raise ForbiddenSubclass()958959 @app.route('/2')960 def index2():961 flask.abort(403)962963 @app.route('/3')964 def index3():965 raise Forbidden()966DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 967–969why, one step back967 assert client.get('/1').data == b'banana'968 assert client.get('/2').data == b'apple'969 assert client.get('/3').data == b'apple'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 970–971why, one step back970971More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 972why, one step back972def test_trapping_of_bad_request_key_errors(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 973–975why, one step back973 @app.route('/fail')974 def fail():975 flask.request.form['missing_key']DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 976why, one step back976More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 977why, one step back977 assert client.get('/fail').status_code == 400Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 978–980why, one step back978979 app.config['TRAP_BAD_REQUEST_ERRORS'] = True980 with pytest.raises(KeyError) as e:More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 981why, one step back981 client.get("/fail")Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 982–984why, one step back982 assert e.errisinstance(BadRequest)983984DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 985why, one step back985def test_trapping_of_all_http_exceptions(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 986–992why, one step back986 app.config['TRAP_HTTP_EXCEPTIONS'] = True987988 @app.route('/fail')989 def fail():990 flask.abort(404)991992 with pytest.raises(NotFound):DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 993why, one step back993 client.get('/fail')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 994–995why, one step back994995DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 996why, one step back996def test_enctype_debug_helper(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 997–1006why, one step back997 from flask.debughelpers import DebugFilesKeyError998 app.debug = True9991000 @app.route('/fail', methods=['POST'])1001 def index():1002 return flask.request.files['foo'].filename10031004 # with statement is important because we leave an exception on the1005 # stack otherwise and we want to ensure that this is not the case1006 # to not negatively affect other tests.More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1007why, one step back1007 with client:Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1008why, one step back1008 with pytest.raises(DebugFilesKeyError) as e:More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1009why, one step back1009 client.post('/fail', data={'foo': 'index.txt'})Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1010–1013why, one step back1010 assert 'no file contents were transmitted' in str(e.value)1011 assert 'This was submitted: "index.txt"' in str(e.value)10121013More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1014why, one step back1014def test_response_types(app, client):Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1015–1016why, one step back1015 @app.route('/text')1016 def from_text():Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1017–1018why, one step back1017 return u'Hällo Wörld'1018Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1019–1020why, one step back1019 @app.route('/bytes')1020 def from_bytes():Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1021–1022why, one step back1021 return u'Hällo Wörld'.encode('utf-8')1022Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1023–1024why, one step back1023 @app.route('/full_tuple')1024 def from_full_tuple():Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1025–1029why, one step back1025 return 'Meh', 400, {1026 'X-Foo': 'Testing',1027 'Content-Type': 'text/plain; charset=utf-8'1028 }1029Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1030–1031why, one step back1030 @app.route('/text_headers')1031 def from_text_headers():Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1032–1036why, one step back1032 return 'Hello', {1033 'X-Foo': 'Test',1034 'Content-Type': 'text/plain; charset=utf-8'1035 }1036Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1037–1038why, one step back1037 @app.route('/text_status')1038 def from_text_status():Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1039–1040why, one step back1039 return 'Hi, status!', 4001040Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1041–1043why, one step back1041 @app.route('/response_headers')1042 def from_response_headers():1043 return flask.Response('Hello world', 404, {'X-Foo': 'Baz'}), {Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1044–1047why, one step back1044 "X-Foo": "Bar",1045 "X-Bar": "Foo"1046 }1047Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1048–1055why, one step back1048 @app.route('/response_status')1049 def from_response_status():1050 return app.response_class('Hello world', 400), 50010511052 @app.route('/wsgi')1053 def from_wsgi():1054 return NotFound()1055More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1056–1057why, one step back1056 assert client.get('/text').data == u'Hällo Wörld'.encode('utf-8')1057 assert client.get('/bytes').data == u'Hällo Wörld'.encode('utf-8')Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
line 1058why, one step back1058More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1059why, one step back1059 rv = client.get('/full_tuple')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1060–1064why, one step back1060 assert rv.data == b'Meh'1061 assert rv.headers['X-Foo'] == 'Testing'1062 assert rv.status_code == 4001063 assert rv.mimetype == 'text/plain'1064More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1065why, one step back1065 rv = client.get('/text_headers')Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1066–1069why, one step back1066 assert rv.data == b'Hello'1067 assert rv.headers['X-Foo'] == 'Test'1068 assert rv.status_code == 2001069 assert rv.mimetype == 'text/plain'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1070why, one step back1070More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1071why, one step back1071 rv = client.get('/text_status')Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1072–1075why, one step back1072 assert rv.data == b'Hi, status!'1073 assert rv.status_code == 4001074 assert rv.mimetype == 'text/html'1075More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1076why, one step back1076 rv = client.get('/response_headers')Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1077–1081why, one step back1077 assert rv.data == b'Hello world'1078 assert rv.headers.getlist('X-Foo') == ['Baz', 'Bar']1079 assert rv.headers['X-Bar'] == 'Foo'1080 assert rv.status_code == 4041081More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1082why, one step back1082 rv = client.get('/response_status')Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1083–1085why, one step back1083 assert rv.data == b'Hello world'1084 assert rv.status_code == 5001085More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1086why, one step back1086 rv = client.get('/wsgi')Merge pull request #2256 from davidism/refactor-make_responseDavid Lordbefore adoption970a800
lines 1087–1133why, one step back1087 assert b'Not Found' in rv.data1088 assert rv.status_code == 404108910901091def test_response_type_errors():1092 app = flask.Flask(__name__)1093 app.testing = True10941095 @app.route('/none')1096 def from_none():1097 pass10981099 @app.route('/small_tuple')1100 def from_small_tuple():1101 return 'Hello',11021103 @app.route('/large_tuple')1104 def from_large_tuple():1105 return 'Hello', 234, {'X-Foo': 'Bar'}, '???'11061107 @app.route('/bad_type')1108 def from_bad_type():1109 return True11101111 @app.route('/bad_wsgi')1112 def from_bad_wsgi():1113 return lambda: None11141115 c = app.test_client()11161117 with pytest.raises(TypeError) as e:1118 c.get('/none')1119 assert 'returned None' in str(e)11201121 with pytest.raises(TypeError) as e:1122 c.get('/small_tuple')1123 assert 'tuple must have the form' in str(e)11241125 pytest.raises(TypeError, c.get, '/large_tuple')11261127 with pytest.raises(TypeError) as e:1128 c.get('/bad_type')1129 assert 'it was a bool' in str(e)11301131 pytest.raises(TypeError, c.get, '/bad_wsgi')11321133More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1134–1138why, one step back1134def test_make_response(app, req_ctx):1135 rv = flask.make_response()1136 assert rv.status_code == 2001137 assert rv.data == b''1138 assert rv.mimetype == 'text/html'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1139why, one step back1139More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1140–1143why, one step back1140 rv = flask.make_response('Awesome')1141 assert rv.status_code == 2001142 assert rv.data == b'Awesome'1143 assert rv.mimetype == 'text/html'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1144why, one step back1144More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1145–1148why, one step back1145 rv = flask.make_response('W00t', 404)1146 assert rv.status_code == 4041147 assert rv.data == b'W00t'1148 assert rv.mimetype == 'text/html'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1149–1150why, one step back11491150More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1151–1156why, one step back1151def test_make_response_with_response_instance(app, req_ctx):1152 rv = flask.make_response(1153 flask.jsonify({'msg': 'W00t'}), 400)1154 assert rv.status_code == 4001155 assert rv.data == b'{"msg":"W00t"}\n'1156 assert rv.mimetype == 'application/json'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1157why, one step back1157More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1158–1162why, one step back1158 rv = flask.make_response(1159 flask.Response(''), 400)1160 assert rv.status_code == 4001161 assert rv.data == b''1162 assert rv.mimetype == 'text/html'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1163why, one step back1163More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1164–1169why, one step back1164 rv = flask.make_response(1165 flask.Response('', headers={'Content-Type': 'text/html'}),1166 400, [('X-Foo', 'bar')])1167 assert rv.status_code == 4001168 assert rv.headers['Content-Type'] == 'text/html'1169 assert rv.headers['X-Foo'] == 'bar'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1170–1171why, one step back11701171More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1172why, one step back1172def test_jsonify_no_prettyprint(app, req_ctx):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1173why, one step back1173 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": False})More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1174–1180why, one step back1174 compressed_msg = b'{"msg":{"submsg":"W00t"},"msg2":"foobar"}\n'1175 uncompressed_msg = {1176 "msg": {1177 "submsg": "W00t"1178 },1179 "msg2": "foobar"1180 }Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1181why, one step back1181More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1182–1184why, one step back1182 rv = flask.make_response(1183 flask.jsonify(uncompressed_msg), 200)1184 assert rv.data == compressed_msgMerge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1185–1186why, one step back11851186More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1187why, one step back1187def test_jsonify_prettyprint(app, req_ctx):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1188why, one step back1188 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": True})More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1189–1191why, one step back1189 compressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}1190 pretty_response = \1191 b'{\n "msg": {\n "submsg": "W00t"\n }, \n "msg2": "foobar"\n}\n'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1192why, one step back1192More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1193–1195why, one step back1193 rv = flask.make_response(1194 flask.jsonify(compressed_msg), 200)1195 assert rv.data == pretty_responseMerge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1196–1197why, one step back11961197More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1198why, one step back1198def test_jsonify_mimetype(app, req_ctx):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1199why, one step back1199 app.config.update({"JSONIFY_MIMETYPE": 'application/vnd.api+json'})More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1200–1205why, one step back1200 msg = {1201 "msg": {"submsg": "W00t"},1202 }1203 rv = flask.make_response(1204 flask.jsonify(msg), 200)1205 assert rv.mimetype == 'application/vnd.api+json'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1206–1207why, one step back12061207More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1208–1211why, one step back1208def test_jsonify_args_and_kwargs_check(app, req_ctx):1209 with pytest.raises(TypeError) as e:1210 flask.jsonify('fake args', kwargs='fake')1211 assert 'behavior undefined' in str(e.value)Add negative test for json.jsonify (#1876)dawran6before adoptione048aa4
lines 1212–1213why, one step back12121213More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1214why, one step back1214def test_url_generation(app, req_ctx):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1215–1217why, one step back1215 @app.route('/hello/<name>', methods=['POST'])1216 def hello():1217 passDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1218why, one step back1218More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1219–1221why, one step back1219 assert flask.url_for('hello', name='test x') == '/hello/test%20x'1220 assert flask.url_for('hello', name='test x', _external=True) == \1221 'http://localhost/hello/test%20x'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1222–1223why, one step back12221223More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1224why, one step back1224def test_build_error_handler(app):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1225–1244why, one step back1225 # Test base case, a URL which results in a BuildError.1226 with app.test_request_context():1227 pytest.raises(BuildError, flask.url_for, 'spam')12281229 # Verify the error is re-raised if not the current exception.1230 try:1231 with app.test_request_context():1232 flask.url_for('spam')1233 except BuildError as err:1234 error = err1235 try:1236 raise RuntimeError('Test case where BuildError is not current.')1237 except RuntimeError:1238 pytest.raises(1239 BuildError, app.handle_url_build_error, error, 'spam', {})12401241 # Test a custom handler.1242 def handler(error, endpoint, values):1243 # Just a test.1244 return '/test_handler/'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1245why, one step back1245Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1246–1250why, one step back1246 app.url_build_error_handlers.append(handler)1247 with app.test_request_context():1248 assert flask.url_for('spam') == '/test_handler/'12491250More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1251why, one step back1251def test_build_error_handler_reraise(app):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1252–1254why, one step back1252 # Test a custom handler which reraises the BuildError1253 def handler_raises_build_error(error, endpoint, values):1254 raise errorDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1255why, one step back1255Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1256–1261why, one step back1256 app.url_build_error_handlers.append(handler_raises_build_error)12571258 with app.test_request_context():1259 pytest.raises(BuildError, flask.url_for, 'not.existing')12601261More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1262why, one step back1262def test_url_for_passes_special_values_to_build_error_handler(app):Merge pull request #2017 from rocambolesque/patch-1David Lordbefore adoptionf4a1ca8
lines 1263–1276why, one step back1263 @app.url_build_error_handlers.append1264 def handler(error, endpoint, values):1265 assert values == {1266 '_external': False,1267 '_anchor': None,1268 '_method': None,1269 '_scheme': None,1270 }1271 return 'handled'12721273 with app.test_request_context():1274 flask.url_for('/')12751276More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1277why, one step back1277def test_custom_converters(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1278–1286why, one step back1278 from werkzeug.routing import BaseConverter12791280 class ListConverter(BaseConverter):1281 def to_python(self, value):1282 return value.split(',')12831284 def to_url(self, value):1285 base_to_url = super(ListConverter, self).to_url1286 return ','.join(base_to_url(x) for x in value)DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1287why, one step back1287Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1288–1292why, one step back1288 app.url_map.converters['list'] = ListConverter12891290 @app.route('/<list:args>')1291 def index(args):1292 return '|'.join(args)DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1293why, one step back1293More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1294why, one step back1294 assert client.get('/1,2,3').data == b'1|2|3'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1295–1296why, one step back12951296More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1297–1298why, one step back1297def test_static_files(app, client):1298 rv = client.get('/static/index.html')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1299–1302why, one step back1299 assert rv.status_code == 2001300 assert rv.data.strip() == b'<h1>Hello World!</h1>'1301 with app.test_request_context():1302 assert flask.url_for('static', filename='index.html') == \DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1303why, one step back1303 '/static/index.html'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1304–1306why, one step back1304 rv.close()13051306Merge pull request #1878 from untitaker/recwarnMarkus Unterwaditzerbefore adoption3d72099
lines 1307–1310why, one step back1307def test_static_path_deprecated(recwarn):1308 app = flask.Flask(__name__, static_path='/foo')1309 recwarn.pop(DeprecationWarning)1310Coverage for test_static_path_deprecated and test_static_url_path (#1860)jphilipsen05before adoption047efac
lines 1311–1313why, one step back1311 app.testing = True1312 rv = app.test_client().get('/foo/index.html')1313 assert rv.status_code == 200Merge pull request #1878 from untitaker/recwarnMarkus Unterwaditzerbefore adoption3d72099
lines 1314–1315why, one step back1314 rv.close()1315Coverage for test_static_path_deprecated and test_static_url_path (#1860)jphilipsen05before adoption047efac
lines 1316–1324why, one step back1316 with app.test_request_context():1317 assert flask.url_for('static', filename='index.html') == '/foo/index.html'131813191320def test_static_url_path():1321 app = flask.Flask(__name__, static_url_path='/foo')1322 app.testing = True1323 rv = app.test_client().get('/foo/index.html')1324 assert rv.status_code == 200Merge pull request #1878 from untitaker/recwarnMarkus Unterwaditzerbefore adoption3d72099
lines 1325–1326why, one step back1325 rv.close()1326Coverage for test_static_path_deprecated and test_static_url_path (#1860)jphilipsen05before adoption047efac
lines 1327–1330why, one step back1327 with app.test_request_context():1328 assert flask.url_for('static', filename='index.html') == '/foo/index.html'13291330Change Flask.__init__ to accept two new keyword arguments, host_matching and static_host. (#1560)jabbefore adoption00d6e33
lines 1331–1337why, one step back1331def test_static_route_with_host_matching():1332 app = flask.Flask(__name__, host_matching=True, static_host='example.com')1333 c = app.test_client()1334 rv = c.get('http://example.com/static/index.html')1335 assert rv.status_code == 2001336 rv.close()1337 with app.test_request_context():DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 1338–1339why, one step back1338 rv = flask.url_for('static', filename='index.html', _external=True)1339 assert rv == 'http://example.com/static/index.html'Change Flask.__init__ to accept two new keyword arguments, host_matching and static_host. (#1560)jabbefore adoption00d6e33
lines 1340–1347why, one step back1340 # Providing static_host without host_matching=True should error.1341 with pytest.raises(Exception):1342 flask.Flask(__name__, static_host='example.com')1343 # Providing host_matching=True with static_folder but without static_host should error.1344 with pytest.raises(Exception):1345 flask.Flask(__name__, host_matching=True)1346 # Providing host_matching=True without static_host but with static_folder=None should not error.1347 flask.Flask(__name__, host_matching=True, static_folder=None)Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1348–1354why, one step back134813491350def test_request_locals():1351 assert repr(flask.g) == '<LocalProxy unbound>'1352 assert not flask.g13531354More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1355why, one step back1355def test_test_app_proper_environ(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1356–1367why, one step back1356 app.config.update(1357 SERVER_NAME='localhost.localdomain:5000'1358 )13591360 @app.route('/')1361 def index():1362 return 'Foo'13631364 @app.route('/', subdomain='foo')1365 def subdomain():1366 return 'Foo SubDomain'1367More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1368why, one step back1368 rv = client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1369–1370why, one step back1369 assert rv.data == b'Foo'1370More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1371why, one step back1371 rv = client.get('/', 'http://localhost.localdomain:5000')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1372–1373why, one step back1372 assert rv.data == b'Foo'1373More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1374why, one step back1374 rv = client.get('/', 'https://localhost.localdomain:5000')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1375–1377why, one step back1375 assert rv.data == b'Foo'13761377 app.config.update(SERVER_NAME='localhost.localdomain')More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1378why, one step back1378 rv = client.get('/', 'https://localhost.localdomain')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1379–1382why, one step back1379 assert rv.data == b'Foo'13801381 try:1382 app.config.update(SERVER_NAME='localhost.localdomain:443')More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1383why, one step back1383 rv = client.get('/', 'https://localhost.localdomain')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1384–1395why, one step back1384 # Werkzeug 0.81385 assert rv.status_code == 4041386 except ValueError as e:1387 # Werkzeug 0.71388 assert str(e) == (1389 "the server name provided "1390 "('localhost.localdomain:443') does not match the "1391 "server name from the WSGI environment ('localhost.localdomain')"1392 )13931394 try:1395 app.config.update(SERVER_NAME='localhost.localdomain')More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1396why, one step back1396 rv = client.get('/', 'http://foo.localhost')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1397–1406why, one step back1397 # Werkzeug 0.81398 assert rv.status_code == 4041399 except ValueError as e:1400 # Werkzeug 0.71401 assert str(e) == (1402 "the server name provided "1403 "('localhost.localdomain') does not match the "1404 "server name from the WSGI environment ('foo.localhost')"1405 )1406More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1407why, one step back1407 rv = client.get('/', 'http://foo.localhost.localdomain')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1408–1410why, one step back1408 assert rv.data == b'Foo SubDomain'14091410More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1411why, one step back1411def test_exception_propagation(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1412–1417why, one step back1412 def apprunner(config_key):1413 app.config['LOGGER_HANDLER_POLICY'] = 'never'14141415 @app.route('/')1416 def index():1417 1 // 0DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1418why, one step back1418Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1419–1421why, one step back1419 if config_key is not None:1420 app.config[config_key] = True1421 with pytest.raises(Exception):More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1422why, one step back1422 client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1423why, one step back1423 else:More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1424why, one step back1424 assert client.get('/').status_code == 500Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1425–1440why, one step back14251426 # we have to run this test in an isolated thread because if the1427 # debug flag is set to true and an exception happens the context is1428 # not torn down. This causes other tests that run after this fail1429 # when they expect no exception on the stack.1430 for config_key in 'TESTING', 'PROPAGATE_EXCEPTIONS', 'DEBUG', None:1431 t = Thread(target=apprunner, args=(config_key,))1432 t.start()1433 t.join()143414351436@pytest.mark.parametrize('debug', [True, False])1437@pytest.mark.parametrize('use_debugger', [True, False])1438@pytest.mark.parametrize('use_reloader', [True, False])1439@pytest.mark.parametrize('propagate_exceptions', [None, True, False])1440def test_werkzeug_passthrough_errors(monkeypatch, debug, use_debugger,More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1441why, one step back1441 use_reloader, propagate_exceptions, app):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1442–1452why, one step back1442 rv = {}14431444 # Mocks werkzeug.serving.run_simple method1445 def run_simple_mock(*args, **kwargs):1446 rv['passthrough_errors'] = kwargs.get('passthrough_errors')14471448 monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)1449 app.config['PROPAGATE_EXCEPTIONS'] = propagate_exceptions1450 app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)14511452More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1453why, one step back1453def test_max_content_length(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1454–1469why, one step back1454 app.config['MAX_CONTENT_LENGTH'] = 6414551456 @app.before_request1457 def always_first():1458 flask.request.form['myfile']1459 assert False14601461 @app.route('/accept', methods=['POST'])1462 def accept_file():1463 flask.request.form['myfile']1464 assert False14651466 @app.errorhandler(413)1467 def catcher(error):1468 return '42'1469More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1470why, one step back1470 rv = client.post('/accept', data={'myfile': 'foo' * 100})Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1471–1473why, one step back1471 assert rv.data == b'42'14721473More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1474why, one step back1474def test_url_processors(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1475–1478why, one step back14751476 @app.url_defaults1477 def add_language_code(endpoint, values):1478 if flask.g.lang_code is not None and \DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1479why, one step back1479 app.url_map.is_endpoint_expecting(endpoint, 'lang_code'):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1480–1497why, one step back1480 values.setdefault('lang_code', flask.g.lang_code)14811482 @app.url_value_preprocessor1483 def pull_lang_code(endpoint, values):1484 flask.g.lang_code = values.pop('lang_code', None)14851486 @app.route('/<lang_code>/')1487 def index():1488 return flask.url_for('about')14891490 @app.route('/<lang_code>/about')1491 def about():1492 return flask.url_for('something_else')14931494 @app.route('/foo')1495 def something_else():1496 return flask.url_for('about', lang_code='en')1497More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1498–1500why, one step back1498 assert client.get('/de/').data == b'/de/about'1499 assert client.get('/de/about').data == b'/foo'1500 assert client.get('/foo').data == b'/en/about'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1501–1502why, one step back15011502More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1503why, one step back1503def test_inject_blueprint_url_defaults(app):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1504–1527why, one step back1504 bp = flask.Blueprint('foo.bar.baz', __name__,1505 template_folder='template')15061507 @bp.url_defaults1508 def bp_defaults(endpoint, values):1509 values['page'] = 'login'15101511 @bp.route('/<page>')1512 def view(page):1513 pass15141515 app.register_blueprint(bp)15161517 values = dict()1518 app.inject_url_defaults('foo.bar.baz.view', values)1519 expected = dict(page='login')1520 assert values == expected15211522 with app.test_request_context('/somepage'):1523 url = flask.url_for('foo.bar.baz.view')1524 expected = '/login'1525 assert url == expected15261527More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1528why, one step back1528def test_nonascii_pathinfo(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1529–1532why, one step back1529 @app.route(u'/киртест')1530 def index():1531 return 'Hello World!'1532More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1533why, one step back1533 rv = client.get(u'/киртест')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1534–1536why, one step back1534 assert rv.data == b'Hello World!'15351536More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1537why, one step back1537def test_debug_mode_complains_after_first_request(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1538–1542why, one step back1538 app.debug = True15391540 @app.route('/')1541 def index():1542 return 'Awesome'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1543why, one step back1543Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1544why, one step back1544 assert not app.got_first_requestMore DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1545why, one step back1545 assert client.get('/').data == b'Awesome'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1546–1556why, one step back1546 with pytest.raises(AssertionError) as e:1547 @app.route('/foo')1548 def broken():1549 return 'Meh'1550 assert 'A setup function was called' in str(e)15511552 app.debug = False15531554 @app.route('/foo')1555 def working():1556 return 'Meh'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1557why, one step back1557More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1558why, one step back1558 assert client.get('/foo').data == b'Meh'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1559–1561why, one step back1559 assert app.got_first_request15601561More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1562why, one step back1562def test_before_first_request_functions(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1563–1567why, one step back1563 got = []15641565 @app.before_first_request1566 def foo():1567 got.append(42)DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1568why, one step back1568More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1569why, one step back1569 client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1570why, one step back1570 assert got == [42]More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1571why, one step back1571 client.get('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1572–1575why, one step back1572 assert got == [42]1573 assert app.got_first_request15741575More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1576why, one step back1576def test_before_first_request_functions_concurrent(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1577–1584why, one step back1577 got = []15781579 @app.before_first_request1580 def foo():1581 time.sleep(0.2)1582 got.append(42)15831584 def get_and_assert():More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1585why, one step back1585 client.get("/")Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1586–1594why, one step back1586 assert got == [42]15871588 t = Thread(target=get_and_assert)1589 t.start()1590 get_and_assert()1591 t.join()1592 assert app.got_first_request15931594More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1595why, one step back1595def test_routing_redirect_debugging(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1596–1600why, one step back1596 app.debug = True15971598 @app.route('/foo/', methods=['GET', 'POST'])1599 def foo():1600 return 'success'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1601why, one step back1601More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1602why, one step back1602 with client:Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1603why, one step back1603 with pytest.raises(AssertionError) as e:More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1604why, one step back1604 client.post('/foo', data={})Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1605–1608why, one step back1605 assert 'http://localhost/foo/' in str(e)1606 assert ('Make sure to directly send '1607 'your POST-request to this URL') in str(e)1608More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1609why, one step back1609 rv = client.get('/foo', data={}, follow_redirects=True)Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1610–1612why, one step back1610 assert rv.data == b'success'16111612 app.debug = FalseMore DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1613–1614why, one step back1613 with client:1614 rv = client.post('/foo', data={}, follow_redirects=True)Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1615–1617why, one step back1615 assert rv.data == b'success'16161617More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1618why, one step back1618def test_route_decorator_custom_endpoint(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1619–1637why, one step back1619 app.debug = True16201621 @app.route('/foo/')1622 def foo():1623 return flask.request.endpoint16241625 @app.route('/bar/', endpoint='bar')1626 def for_bar():1627 return flask.request.endpoint16281629 @app.route('/bar/123', endpoint='123')1630 def for_bar_foo():1631 return flask.request.endpoint16321633 with app.test_request_context():1634 assert flask.url_for('foo') == '/foo/'1635 assert flask.url_for('bar') == '/bar/'1636 assert flask.url_for('123') == '/bar/123'1637More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
lines 1638–1640why, one step back1638 assert client.get('/foo/').data == b'foo'1639 assert client.get('/bar/').data == b'bar'1640 assert client.get('/bar/123').data == b'123'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1641–1642why, one step back16411642More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1643why, one step back1643def test_preserve_only_once(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1644–1651why, one step back1644 app.debug = True16451646 @app.route('/fail')1647 def fail_func():1648 1 // 016491650 for x in range(3):1651 with pytest.raises(ZeroDivisionError):More DRYing up the test suite (#2325)Christian Stade-Schuldtbefore adoption4ec1fbc
line 1652why, one step back1652 client.get('/fail')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1653–1661why, one step back16531654 assert flask._request_ctx_stack.top is not None1655 assert flask._app_ctx_stack.top is not None1656 # implicit appctx disappears too1657 flask._request_ctx_stack.top.pop()1658 assert flask._request_ctx_stack.top is None1659 assert flask._app_ctx_stack.top is None16601661DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1662why, one step back1662def test_preserve_remembers_exception(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1663–1679why, one step back1663 app.debug = True1664 errors = []16651666 @app.route('/fail')1667 def fail_func():1668 1 // 016691670 @app.route('/success')1671 def success_func():1672 return 'Okay'16731674 @app.teardown_request1675 def teardown_handler(exc):1676 errors.append(exc)16771678 # After this failure we did not yet call the teardown handler1679 with pytest.raises(ZeroDivisionError):DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1680why, one step back1680 client.get('/fail')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1681–1683why, one step back1681 assert errors == []16821683 # But this request triggers it, and it's an errorDRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1684why, one step back1684 client.get('/success')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1685–1688why, one step back1685 assert len(errors) == 21686 assert isinstance(errors[0], ZeroDivisionError)16871688 # At this point another request does nothing.DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1689why, one step back1689 client.get('/success')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1690–1693why, one step back1690 assert len(errors) == 31691 assert errors[1] is None16921693DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 1694–1699why, one step back1694def test_get_method_on_g(app_ctx):1695 assert flask.g.get('x') is None1696 assert flask.g.get('x', 11) == 111697 flask.g.x = 421698 assert flask.g.get('x') == 421699 assert flask.g.x == 42Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1700–1701why, one step back17001701DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 1702–1707why, one step back1702def test_g_iteration_protocol(app_ctx):1703 flask.g.foo = 231704 flask.g.bar = 421705 assert 'foo' in flask.g1706 assert 'foos' not in flask.g1707 assert sorted(flask.g) == ['bar', 'foo']Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1708–1709why, one step back17081709DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 1710–1711why, one step back1710def test_subdomain_basic_support(app, client):1711 app.config['SERVER_NAME'] = 'localhost.localdomain'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1712–1720why, one step back17121713 @app.route('/')1714 def normal_index():1715 return 'normal index'17161717 @app.route('/', subdomain='test')1718 def test_index():1719 return 'test index'1720DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1721why, one step back1721 rv = client.get('/', 'http://localhost.localdomain/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1722–1723why, one step back1722 assert rv.data == b'normal index'1723DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1724why, one step back1724 rv = client.get('/', 'http://test.localhost.localdomain/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1725–1727why, one step back1725 assert rv.data == b'test index'17261727DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 1728–1729why, one step back1728def test_subdomain_matching(app, client):1729 app.config['SERVER_NAME'] = 'localhost.localdomain'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1730–1734why, one step back17301731 @app.route('/', subdomain='<user>')1732 def index(user):1733 return 'index for %s' % user1734DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1735why, one step back1735 rv = client.get('/', 'http://mitsuhiko.localhost.localdomain/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1736–1738why, one step back1736 assert rv.data == b'index for mitsuhiko'17371738DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 1739–1740why, one step back1739def test_subdomain_matching_with_ports(app, client):1740 app.config['SERVER_NAME'] = 'localhost.localdomain:3000'Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1741–1745why, one step back17411742 @app.route('/', subdomain='<user>')1743 def index(user):1744 return 'index for %s' % user1745DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1746why, one step back1746 rv = client.get('/', 'http://mitsuhiko.localhost.localdomain:3000/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1747–1749why, one step back1747 assert rv.data == b'index for mitsuhiko'17481749DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1750why, one step back1750def test_multi_route_rules(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1751–1755why, one step back1751 @app.route('/')1752 @app.route('/<test>/')1753 def index(test='a'):1754 return test1755DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1756why, one step back1756 rv = client.open('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1757why, one step back1757 assert rv.data == b'a'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1758why, one step back1758 rv = client.open('/b/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1759–1761why, one step back1759 assert rv.data == b'b'17601761DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1762why, one step back1762def test_multi_route_class_views(app, client):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1763–1771why, one step back1763 class View(object):1764 def __init__(self, app):1765 app.add_url_rule('/', 'index', self.index)1766 app.add_url_rule('/<test>/', 'index', self.index)17671768 def index(self, test='a'):1769 return test17701771 _ = View(app)DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1772why, one step back1772 rv = client.open('/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
line 1773why, one step back1773 assert rv.data == b'a'DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1774why, one step back1774 rv = client.open('/b/')Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1775–1777why, one step back1775 assert rv.data == b'b'17761777DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1778why, one step back1778def test_run_defaults(monkeypatch, app):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1779–1789why, one step back1779 rv = {}17801781 # Mocks werkzeug.serving.run_simple method1782 def run_simple_mock(*args, **kwargs):1783 rv['result'] = 'running...'17841785 monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)1786 app.run()1787 assert rv['result'] == 'running...'17881789DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1790why, one step back1790def test_run_server_port(monkeypatch, app):Merge pull request #1855 from JamesTFarrington/sprintJeff Widmanbefore adoptiond80fabd
lines 1791–1800why, one step back1791 rv = {}17921793 # Mocks werkzeug.serving.run_simple method1794 def run_simple_mock(hostname, port, application, *args, **kwargs):1795 rv['result'] = 'running on %s:%s ...' % (hostname, port)17961797 monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)1798 hostname, port = 'localhost', 80001799 app.run(hostname, port, debug=True)1800 assert rv['result'] == 'running on %s:%s ...' % (hostname, port)add test and changelog for SERVER_NAME app.run defaultDavid Lordbefore adoption42fbbb4
lines 1801–1803why, one step back180118021803@pytest.mark.parametrize('host,port,expect_host,expect_port', (DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
lines 1804–1807why, one step back1804 (None, None, 'pocoo.org', 8080),1805 ('localhost', None, 'localhost', 8080),1806 (None, 80, 'pocoo.org', 80),1807 ('localhost', 80, 'localhost', 80),add test and changelog for SERVER_NAME app.run defaultDavid Lordbefore adoption42fbbb4
line 1808why, one step back1808))DRYing up the test suite using pytest fixtures (#2306)Christian Stade-Schuldtbefore adoption5b0b971
line 1809why, one step back1809def test_run_from_config(monkeypatch, host, port, expect_host, expect_port, app):add test and changelog for SERVER_NAME app.run defaultDavid Lordbefore adoption42fbbb4
lines 1810–1816why, one step back1810 def run_simple_mock(hostname, port, *args, **kwargs):1811 assert hostname == expect_host1812 assert port == expect_port18131814 monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)1815 app.config['SERVER_NAME'] = 'pocoo.org:8080'1816 app.run(host, port)