test_json_customization() — flask Function Reference
Architecture documentation for the test_json_customization() function in test_json.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD 19555bad_e537_3fd6_8527_e6bcfd3a9379["test_json_customization()"] b6432813_8c45_5dc1_5241_b6184964d73b["test_json.py"] 19555bad_e537_3fd6_8527_e6bcfd3a9379 -->|defined in| b6432813_8c45_5dc1_5241_b6184964d73b 53777e07_54e8_db27_cec1_bad2487dcc8a["object_hook()"] 19555bad_e537_3fd6_8527_e6bcfd3a9379 -->|calls| 53777e07_54e8_db27_cec1_bad2487dcc8a 9f9b575f_e4c6_4dfb_af7d_18c05f7240a9["loads()"] 19555bad_e537_3fd6_8527_e6bcfd3a9379 -->|calls| 9f9b575f_e4c6_4dfb_af7d_18c05f7240a9 style 19555bad_e537_3fd6_8527_e6bcfd3a9379 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_json.py lines 223–257
def test_json_customization(app, client):
class X: # noqa: B903, for Python2 compatibility
def __init__(self, val):
self.val = val
def default(o):
if isinstance(o, X):
return f"<{o.val}>"
return DefaultJSONProvider.default(o)
class CustomProvider(DefaultJSONProvider):
def object_hook(self, obj):
if len(obj) == 1 and "_foo" in obj:
return X(obj["_foo"])
return obj
def loads(self, s, **kwargs):
kwargs.setdefault("object_hook", self.object_hook)
return super().loads(s, **kwargs)
app.json = CustomProvider(app)
app.json.default = default
@app.route("/", methods=["POST"])
def index():
return flask.json.dumps(flask.request.get_json()["x"])
rv = client.post(
"/",
data=flask.json.dumps({"x": {"_foo": 42}}),
content_type="application/json",
)
assert rv.data == b'"<42>"'
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does test_json_customization() do?
test_json_customization() is a function in the flask codebase, defined in tests/test_json.py.
Where is test_json_customization() defined?
test_json_customization() is defined in tests/test_json.py at line 223.
What does test_json_customization() call?
test_json_customization() calls 2 function(s): loads, object_hook.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free