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

Function test_server_name_matching

tests/test_basic.py:1523–1554  ·  view source on GitHub ↗
(
    subdomain_matching: bool,
    host_matching: bool,
    expect_base: str,
    expect_abc: str,
    expect_xyz: str,
)

Source from the content-addressed store, hash-verified

1521 ],
1522)
1523def test_server_name_matching(
1524 subdomain_matching: bool,
1525 host_matching: bool,
1526 expect_base: str,
1527 expect_abc: str,
1528 expect_xyz: str,
1529) -> None:
1530 app = flask.Flask(
1531 __name__,
1532 subdomain_matching=subdomain_matching,
1533 host_matching=host_matching,
1534 static_host="example.test" if host_matching else None,
1535 )
1536 app.config["SERVER_NAME"] = "example.test"
1537
1538 @app.route("/", defaults={"name": "default"}, host="<name>")
1539 @app.route("/", subdomain="<name>", host="<name>.example.test")
1540 def index(name: str) -> str:
1541 return name
1542
1543 client = app.test_client()
1544
1545 r = client.get(base_url="http://example.test")
1546 assert r.text == expect_base
1547
1548 r = client.get(base_url="http://abc.example.test")
1549 assert r.text == expect_abc
1550
1551 with pytest.warns() if subdomain_matching else nullcontext():
1552 r = client.get(base_url="http://xyz.other.test")
1553
1554 assert r.text == expect_xyz
1555
1556
1557def test_server_name_subdomain():

Callers

nothing calls this directly

Calls 2

test_clientMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected