diff --git a/tests/test_form_json_type.py b/tests/test_json_type.py similarity index 73% rename from tests/test_form_json_type.py rename to tests/test_json_type.py index cbeb57f063..3e213eaca4 100644 --- a/tests/test_form_json_type.py +++ b/tests/test_json_type.py @@ -1,7 +1,7 @@ import json from typing import Annotated -from fastapi import FastAPI, Form, Header, Query +from fastapi import Cookie, FastAPI, Form, Header, Query from fastapi.testclient import TestClient from pydantic import Json @@ -23,6 +23,11 @@ def header_json_list(x_items: Annotated[Json[list[str]], Header()]) -> list[str] return x_items +@app.get("/cookie-json-list") +def cookie_json_list(items: Annotated[Json[list[str]], Cookie()]) -> list[str]: + return items + + client = TestClient(app) @@ -48,3 +53,11 @@ def test_header_json_list(): ) assert response.status_code == 200, response.text assert response.json() == ["abc", "def"] + + +def test_cookie_json_list(): + client.cookies.set("items", json.dumps(["abc", "def"])) + response = client.get("/cookie-json-list") + assert response.status_code == 200, response.text + assert response.json() == ["abc", "def"] + client.cookies.clear()