|
|
@ -1,7 +1,7 @@ |
|
|
import json |
|
|
import json |
|
|
from typing import Annotated |
|
|
from typing import Annotated |
|
|
|
|
|
|
|
|
from fastapi import Cookie, FastAPI, Form, Header, Query |
|
|
from fastapi import FastAPI, Form, Header, Query |
|
|
from fastapi.testclient import TestClient |
|
|
from fastapi.testclient import TestClient |
|
|
from pydantic import Json |
|
|
from pydantic import Json |
|
|
|
|
|
|
|
|
@ -23,13 +23,6 @@ def header_json_list(x_items: Annotated[Json[list[str]], Header()]) -> list[str] |
|
|
return x_items |
|
|
return x_items |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/cookie-json-dict") |
|
|
|
|
|
def cookie_json_dict( |
|
|
|
|
|
session: Annotated[Json[dict[str, str]], Cookie()], |
|
|
|
|
|
) -> dict[str, str]: |
|
|
|
|
|
return session |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client = TestClient(app) |
|
|
client = TestClient(app) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -55,10 +48,3 @@ 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_dict(): |
|
|
|
|
|
client.cookies.set("session", json.dumps({"user": "test1", "role": "admin"})) |
|
|
|
|
|
response = client.get("/cookie-json-dict") |
|
|
|
|
|
assert response.status_code == 200, response.text |
|
|
|
|
|
assert response.json() == {"user": "test1", "role": "admin"} |
|
|
|
|
|
|