Skip to content
Myr

Merge pull request #3261 from pallets/fix-server-name-warnings

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

fix tests failing with server name warnings

authored by David Lord · committed by GitHub · parents 6369537, dbd4520 · Browse files · 5 files+36 added−62 removed
This commit

State

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

Diff stats

5 files+36 added−62 removed

  • tests:+34 added−60 removed
  • other:+2 added−2 removed

5 files+36 added−62 removed

modified:tests/conftest.py-7 removed
194 unmodified lines
195 def inner(name):196 request.addfinalizer(lambda: sys.modules.pop(name, None))197198 return inner199200201@pytest.fixture(autouse=True)202def catch_deprecation_warnings(recwarn):203 yield204 gc.collect()205 assert not recwarn.list, '\n'.join(str(w.message) for w in recwarn.list)
modified:tests/test_basic.py+31 added-45 removed
1440 unmodified lines
1441 assert repr(flask.g) == '<LocalProxy unbound>'1442 assert not flask.g144314441445def test_test_app_proper_environ():1445def test_server_name_subdomain():1446 app = flask.Flask(__name__, subdomain_matching=True)1447 app.config.update(1448 SERVER_NAME='localhost.localdomain:5000'1449 )1447 client = app.test_client()14481452 @app.route('/')1449 @app.route("/")1450 def index():1454 return 'Foo'1451 return "default"14521456 @app.route('/', subdomain='foo')1453 @app.route("/", subdomain="foo")1454 def subdomain():1458 return 'Foo SubDomain'1455 return "subdomain"14561457 app.config["SERVER_NAME"] = "dev.local:5000"1460 rv = client.get('/')1461 assert rv.data == b'Foo'1458 rv = client.get("/")1459 assert rv.data == b"default"14601463 rv = client.get('/', 'http://localhost.localdomain:5000')1464 assert rv.data == b'Foo'1461 rv = client.get("/", "http://dev.local:5000")1462 assert rv.data == b"default"14631466 rv = client.get('/', 'https://localhost.localdomain:5000')1467 assert rv.data == b'Foo'1464 rv = client.get("/", "https://dev.local:5000")1465 assert rv.data == b"default"14661469 app.config.update(SERVER_NAME='localhost.localdomain')1470 rv = client.get('/', 'https://localhost.localdomain')1471 assert rv.data == b'Foo'1467 app.config["SERVER_NAME"] = "dev.local:443"1468 rv = client.get("/", "https://dev.local")14691473 try:1474 app.config.update(SERVER_NAME='localhost.localdomain:443')1475 rv = client.get('/', 'https://localhost.localdomain')1476 # Werkzeug 0.81477 assert rv.status_code == 4041478 except ValueError as e:1479 # Werkzeug 0.71480 assert str(e) == (1481 "the server name provided "1482 "('localhost.localdomain:443') does not match the "1483 "server name from the WSGI environment ('localhost.localdomain')"1484 )1470 # Werkzeug 1.0 fixes matching https scheme with 443 port1471 if rv.status_code != 404:1472 assert rv.data == b"default"14731486 try:1487 app.config.update(SERVER_NAME='localhost.localdomain')1488 rv = client.get('/', 'http://foo.localhost')1489 # Werkzeug 0.81474 app.config["SERVER_NAME"] = "dev.local"1475 rv = client.get("/", "https://dev.local")1476 assert rv.data == b"default"14771478 # suppress Werkzeug 1.0 warning about name mismatch1479 with pytest.warns(None):1480 rv = client.get("/", "http://foo.localhost")1481 assert rv.status_code == 4041491 except ValueError as e:1492 # Werkzeug 0.71493 assert str(e) == (1494 "the server name provided "1495 "('localhost.localdomain') does not match the "1496 "server name from the WSGI environment ('foo.localhost')"1497 )14821499 rv = client.get('/', 'http://foo.localhost.localdomain')1500 assert rv.data == b'Foo SubDomain'1483 rv = client.get("/", "http://foo.dev.local")1484 assert rv.data == b"subdomain"148514861487def test_exception_propagation(app, client):1488 def apprunner(config_key):
348 unmodified lines
1837 @app.route('/')1838 def index():1839 return '', 20418401841 # suppress Werkzeug 0.15 warning about name mismatch1842 with pytest.warns(None):1857 # ip address can't match name1858 rv = client.get('/', 'http://127.0.0.1:3000/')1859 assert rv.status_code == 404 if matching else 2041843 # ip address can't match name1844 rv = client.get('/', 'http://127.0.0.1:3000/')1845 assert rv.status_code == 404 if matching else 20418461847 # allow all subdomains if matching is disabled1848 rv = client.get('/', 'http://www.localhost.localdomain:3000/')1849 assert rv.status_code == 404 if matching else 204
99 unmodified lines
modified:tests/test_helpers.py+1 added-1 removed
441 unmodified lines
442 rv.direct_passthrough = False443 assert rv.data == f.read()444 rv.close()445446 def test_send_file_xsendfile(self, app, req_ctx, catch_deprecation_warnings):446 def test_send_file_xsendfile(self, app, req_ctx):447 app.use_x_sendfile = True448 rv = flask.send_file('static/index.html')449 assert rv.direct_passthrough450 assert 'x-sendfile' in rv.headers
506 unmodified lines
modified:tests/test_reqctx.py+2 added-7 removed
86 unmodified lines
87 with app.test_request_context('/'):88 assert flask.url_for('sub', _external=True) == \89 'http://foo.localhost.localdomain:5000/'9091 try:91 # suppress Werkzeug 0.15 warning about name mismatch92 with pytest.warns(None):93 with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):94 pass94 except ValueError as e:95 assert str(e) == (96 "the server name provided "97 "('localhost.localdomain:5000') does not match the "98 "server name from the WSGI environment ('localhost')"99 )9596 app.config.update(SERVER_NAME='localhost')97 with app.test_request_context('/', environ_overrides={'SERVER_NAME': 'localhost'}):98 pass
124 unmodified lines
modified:tox.ini+2 added-2 removed
31 unmodified lines
32 pip install -q -e examples/tutorial[test]33 pip install -q -e examples/javascript[test]3435 # pytest-cov doesn't seem to play nice with -p36 coverage run -p -m pytest --tb=short {posargs:tests examples}36 coverage run -p -m pytest --tb=short -Werror {posargs:tests examples}3738[testenv:nightly]39# courtesy Python nightly test, don't fail the build in CI40ignore_outcome = true41commands =42 pip install -q -e examples/tutorial[test]43 pip install -q -e examples/javascript[test]44 coverage run -p -m pytest --tb=short --junitxml=test-results.xml {posargs:tests examples}44 coverage run -p -m pytest --tb=short -Werror --junitxml=test-results.xml {posargs:tests examples}4546[testenv:stylecheck]47deps = pre-commit48skip_install = true
26 unmodified lines