Browse Source

Add Cookie test and rename test file

pull/14616/head
masaaya 6 months ago
parent
commit
9f713cab98
  1. 15
      tests/test_json_type.py

15
tests/test_form_json_type.py → tests/test_json_type.py

@ -1,7 +1,7 @@
import json import json
from typing import Annotated 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 fastapi.testclient import TestClient
from pydantic import Json from pydantic import Json
@ -23,6 +23,11 @@ def header_json_list(x_items: Annotated[Json[list[str]], Header()]) -> list[str]
return x_items 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) client = TestClient(app)
@ -48,3 +53,11 @@ def test_header_json_list():
) )
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == ["abc", "def"] 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()
Loading…
Cancel
Save