MCPcopy
hub / github.com/pallets/flask / test_server_name_subdomain

Function test_server_name_subdomain

tests/test_basic.py:1557–1599  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1555
1556
1557def test_server_name_subdomain():
1558 app = flask.Flask(__name__, subdomain_matching=True)
1559 client = app.test_client()
1560
1561 @app.route("/")
1562 def index():
1563 return "default"
1564
1565 @app.route("/", subdomain="foo")
1566 def subdomain():
1567 return "subdomain"
1568
1569 app.config["SERVER_NAME"] = "dev.local:5000"
1570 rv = client.get("/")
1571 assert rv.data == b"default"
1572
1573 rv = client.get("/", "http://dev.local:5000")
1574 assert rv.data == b"default"
1575
1576 rv = client.get("/", "https://dev.local:5000")
1577 assert rv.data == b"default"
1578
1579 app.config["SERVER_NAME"] = "dev.local:443"
1580 rv = client.get("/", "https://dev.local")
1581
1582 # Werkzeug 1.0 fixes matching https scheme with 443 port
1583 if rv.status_code != 404:
1584 assert rv.data == b"default"
1585
1586 app.config["SERVER_NAME"] = "dev.local"
1587 rv = client.get("/", "https://dev.local")
1588 assert rv.data == b"default"
1589
1590 # suppress Werkzeug 0.15 warning about name mismatch
1591 with warnings.catch_warnings():
1592 warnings.filterwarnings(
1593 "ignore", "Current server name", UserWarning, "flask.app"
1594 )
1595 rv = client.get("/", "http://foo.localhost")
1596 assert rv.status_code == 404
1597
1598 rv = client.get("/", "http://foo.dev.local")
1599 assert rv.data == b"subdomain"
1600
1601
1602@pytest.mark.parametrize("key", ["TESTING", "PROPAGATE_EXCEPTIONS", "DEBUG", None])

Callers

nothing calls this directly

Calls 2

test_clientMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected