test_converters.py
This file
Path
tests/test_converters.py
42 lines · 1.1 KiB · Python
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 93a7f08 point at it.
pin os and python version in rtd buildDavid Lordbefore adoption93a7f08
lines 1–42why, one step back1from werkzeug.routing import BaseConverter23from flask import request4from flask import session5from flask import url_for678def test_custom_converters(app, client):9 class ListConverter(BaseConverter):10 def to_python(self, value):11 return value.split(",")1213 def to_url(self, value):14 base_to_url = super().to_url15 return ",".join(base_to_url(x) for x in value)1617 app.url_map.converters["list"] = ListConverter1819 @app.route("/<list:args>")20 def index(args):21 return "|".join(args)2223 assert client.get("/1,2,3").data == b"1|2|3"2425 with app.test_request_context():26 assert url_for("index", args=[4, 5, 6]) == "/4,5,6"272829def test_context_available(app, client):30 class ContextConverter(BaseConverter):31 def to_python(self, value):32 assert request is not None33 assert session is not None34 return value3536 app.url_map.converters["ctx"] = ContextConverter3738 @app.get("/<ctx:name>")39 def index(name):40 return name4142 assert client.get("/admin").data == b"admin"