From afe8961b7cb16262aec39d141452918147ec3af7 Mon Sep 17 00:00:00 2001 From: gcoinstash-cmd Date: Sat, 12 Sep 2026 17:08:34 -0700 Subject: [PATCH] test(json): add unit tests for jsonify response mimetype and content-type invariance --- tests/test_json_response_headers_suite.py | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test_json_response_headers_suite.py diff --git a/tests/test_json_response_headers_suite.py b/tests/test_json_response_headers_suite.py new file mode 100644 index 0000000000..1350dc259a --- /dev/null +++ b/tests/test_json_response_headers_suite.py @@ -0,0 +1,29 @@ +import pytest +from flask import Flask, jsonify + +def test_jsonify_mimetype_and_content_type_invariance(): + """Verify jsonify sets application/json mimetype and content-type header.""" + app = Flask(__name__) + + @app.route("/api/ping") + def ping(): + return jsonify(status="ok", code=200) + + with app.test_client() as client: + response = client.get("/api/ping") + assert response.status_code == 200 + assert response.mimetype == "application/json" + assert "application/json" in response.headers.get("Content-Type", "") + assert response.json == {"status": "ok", "code": 200} + +def test_jsonify_empty_dictionary(): + app = Flask(__name__) + + @app.route("/api/empty") + def empty(): + return jsonify({}) + + with app.test_client() as client: + response = client.get("/api/empty") + assert response.status_code == 200 + assert response.json == {}