update domain matching tests for Werkzeug 3.2
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 798e006 · Browse files · 3 files·+69 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+69 added−28 removed
- tests:+27 added−22 removed
- other:+42 added−6 removed
Provenance
- Commit
5e621a2- Tree
6793b11- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
798e006
3 files changed+69 added−28 removed
modified:tests/test_basic.py+27 added-22 removed
1 import gc2+import importlib.metadata3 import re4 import typing as t5 import uuid5-import warnings6 import weakref7 from contextlib import nullcontext8 from datetime import datetime9 from datetime import timezone1480 unmodified lines1490 assert repr(flask.g) == "<LocalProxy unbound>"1491 assert not flask.g1492 1493 1494+werkzeug_3_2 = importlib.metadata.version("werkzeug") >= "3.2."1495+1496+1497 @pytest.mark.parametrize(1495- ("subdomain_matching", "host_matching", "expect_base", "expect_abc", "expect_xyz"),1498+ ("subdomain_matching", "host_matching", "expect_subdomain", "expect_host"),1499 [1497- (False, False, "default", "default", "default"),1498- (True, False, "default", "abc", "<invalid>"),1499- (False, True, "default", "abc", "default"),1500+ (False, False, "default", "default"),1501+ (True, False, "abc", "<invalid>"),1502+ (False, True, "abc", "default"),1503 ],1504 )1505 def test_server_name_matching(1506 subdomain_matching: bool,1507 host_matching: bool,1505- expect_base: str,1506- expect_abc: str,1507- expect_xyz: str,1508+ expect_subdomain: str,1509+ expect_host: str,1510 ) -> None:1511 app = flask.Flask(1512 __name__,1513 subdomain_matching=subdomain_matching,9 unmodified lines1523 1524 client = app.test_client()1525 1526 r = client.get(base_url="http://example.test")1525- assert r.text == expect_base1527+ assert r.text == "default"1528 1529 r = client.get(base_url="http://abc.example.test")1528- assert r.text == expect_abc1530+ assert r.text == expect_subdomain1531 1532 with pytest.warns() if subdomain_matching else nullcontext():1533 r = client.get(base_url="http://xyz.other.test")1534 1535+ if werkzeug_3_2:1536+ assert r.text == "default"1537+ else:1533- assert r.text == expect_xyz1538+ assert r.text == expect_host1539 1540 1541 def test_server_name_subdomain():1542 app = flask.Flask(__name__, subdomain_matching=True)27 unmodified lines1570 app.config["SERVER_NAME"] = "dev.local"1571 rv = client.get("/", "https://dev.local")1572 assert rv.data == b"default"1573 1569- # suppress Werkzeug 0.15 warning about name mismatch1570- with warnings.catch_warnings():1571- warnings.filterwarnings(1572- "ignore", "Current server name", UserWarning, "flask.app"1573- )1574+ with pytest.warns(match="Current server name"):1575 rv = client.get("/", "http://foo.localhost")1576+1577+ if werkzeug_3_2:1578+ assert rv.status_code == 2001579+ else:1580 assert rv.status_code == 4041581 1582 rv = client.get("/", "http://foo.dev.local")1583 assert rv.data == b"subdomain"227 unmodified lines1811 @app.route("/")1812 def index():1813 return "", 2041814 1810- # suppress Werkzeug 0.15 warning about name mismatch1811- with warnings.catch_warnings():1812- warnings.filterwarnings(1813- "ignore", "Current server name", UserWarning, "flask.app"1814- )1815- # ip address can't match name1815+ with pytest.warns(match="Current server name") if matching else nullcontext():1816+ # ip address can't match name, but will fall back to default1817 rv = client.get("/", "http://127.0.0.1:3000/")1818+1819+ if werkzeug_3_2:1820+ assert rv.status_code == 2041821+ else:1822 assert rv.status_code == 404 if matching else 2041823 1824 # allow all subdomains if matching is disabled1825 rv = client.get("/", "http://www.localhost.localdomain:3000/")124 unmodified linesmodified:pyproject.toml+3 added
102 unmodified lines103 104 [tool.uv]105 default-groups = ["dev", "pre-commit", "tests", "typing"]106 107+[tool.uv.sources]108+werkzeug = { path = "../werkzeug" }109+110 [tool.pytest.ini_options]111 testpaths = ["tests"]112 filterwarnings = [113 "error",168 unmodified linesmodified:uv.lock+39 added-6 removed
461 unmodified lines462 { name = "itsdangerous", specifier = ">=2.2.0" },463 { name = "jinja2", specifier = ">=3.1.2" },464 { name = "markupsafe", specifier = ">=2.1.1" },465 { name = "python-dotenv", marker = "extra == 'dotenv'" },466- { name = "werkzeug", specifier = ">=3.1.0" },466+ { name = "werkzeug", directory = "../werkzeug" },467 ]468 provides-extras = ["async", "dotenv"]469 470 [package.metadata.requires-dev]1272 unmodified lines1743 ]1744 1745 [[package]]1746 name = "werkzeug"1747-version = "3.1.5"1748-source = { registry = "https://pypi.org/simple" }1747+version = "3.2.0.dev0"1748+source = { directory = "../werkzeug" }1749 dependencies = [1750 { name = "markupsafe" },1751 ]1752-sdist = { url = "https://files.pythonhosted.org/packages/5a/70/1469ef1d3542ae7c2c7b72bd5e3a4e6ee69d7978fa8a3af05a38eca5becf/werkzeug-3.1.5.tar.gz", hash = "sha256:6a548b0e88955dd07ccb25539d7d0cc97417ee9e179677d22c7041c8f078ce67", size = 864754, upload-time = "2026-01-08T17:49:23.247Z" }1753-wheels = [1754- { url = "https://files.pythonhosted.org/packages/ad/e4/8d97cca767bcc1be76d16fb76951608305561c6e056811587f36cb1316a8/werkzeug-3.1.5-py3-none-any.whl", hash = "sha256:5111e36e91086ece91f93268bb39b4a35c1e6f1feac762c9c822ded0a4e322dc", size = 225025, upload-time = "2026-01-08T17:49:21.859Z" },1752+1753+[package.metadata]1754+requires-dist = [1755+ { name = "markupsafe", specifier = ">=2.1.1" },1756+ { name = "watchdog", marker = "extra == 'watchdog'", specifier = ">=2.3" },1757 ]1758+provides-extras = ["watchdog"]1759+1760+[package.metadata.requires-dev]1761+dev = [1762+ { name = "ruff" },1763+ { name = "tox" },1764+ { name = "tox-uv" },1765+]1766+docs = [1767+ { name = "pallets-sphinx-themes" },1768+ { name = "sphinx", specifier = "<9" },1769+ { name = "sphinxcontrib-log-cabinet" },1770+]1771+docs-auto = [{ name = "sphinx-autobuild" }]1772+gha-update = [{ name = "gha-update", marker = "python_full_version >= '3.12'" }]1773+pre-commit = [1774+ { name = "pre-commit" },1775+ { name = "pre-commit-uv" },1776+]1777+tests = [1778+ { name = "cffi" },1779+ { name = "cryptography" },1780+ { name = "ephemeral-port-reserve" },1781+ { name = "pytest" },1782+ { name = "pytest-timeout" },1783+ { name = "watchdog" },1784+]1785+typing = [1786+ { name = "mypy" },1787+ { name = "pyright" },1788+]