Add Cookie test and rename test file

This commit is contained in:
masaaya 2026-01-09 00:39:04 +09:00
parent 690f8d23c9
commit 9f713cab98
1 changed files with 14 additions and 1 deletions

View File

@ -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()