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

Function test_custom_converters

tests/test_converters.py:8–26  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

6
7
8def test_custom_converters(app, client):
9 class ListConverter(BaseConverter):
10 def to_python(self, value):
11 return value.split(",")
12
13 def to_url(self, value):
14 base_to_url = super().to_url
15 return ",".join(base_to_url(x) for x in value)
16
17 app.url_map.converters["list"] = ListConverter
18
19 @app.route("/<list:args>")
20 def index(args):
21 return "|".join(args)
22
23 assert client.get("/1,2,3").data == b"1|2|3"
24
25 with app.test_request_context():
26 assert url_for("index", args=[4, 5, 6]) == "/4,5,6"
27
28
29def test_context_available(app, client):

Callers

nothing calls this directly

Calls 3

url_forFunction · 0.90
test_request_contextMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected