test_query_cookie_header_model_extra_params.py — fastapi Source File
Architecture documentation for test_query_cookie_header_model_extra_params.py, a python file in the fastapi codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b9f7fa37_3873_9081_9fff_0162c3bf7d84["test_query_cookie_header_model_extra_params.py"] 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] b9f7fa37_3873_9081_9fff_0162c3bf7d84 --> 534f6e44_61b8_3c38_8b89_6934a6df9802 a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] b9f7fa37_3873_9081_9fff_0162c3bf7d84 --> a7c04dee_ee23_5891_b185_47ff6bed036d 6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"] b9f7fa37_3873_9081_9fff_0162c3bf7d84 --> 6913fbd4_39df_d14b_44bb_522e99b65b90 style b9f7fa37_3873_9081_9fff_0162c3bf7d84 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from fastapi import Cookie, FastAPI, Header, Query
from fastapi.testclient import TestClient
from pydantic import BaseModel
app = FastAPI()
class Model(BaseModel):
param: str
model_config = {"extra": "allow"}
@app.get("/query")
async def query_model_with_extra(data: Model = Query()):
return data
@app.get("/header")
async def header_model_with_extra(data: Model = Header()):
return data
@app.get("/cookie")
async def cookies_model_with_extra(data: Model = Cookie()):
return data
def test_query_pass_extra_list():
client = TestClient(app)
resp = client.get(
"/query",
params={
"param": "123",
"param2": ["456", "789"], # Pass a list of values as extra parameter
},
)
assert resp.status_code == 200
assert resp.json() == {
"param": "123",
"param2": ["456", "789"],
}
def test_query_pass_extra_single():
client = TestClient(app)
resp = client.get(
"/query",
params={
"param": "123",
"param2": "456",
},
)
assert resp.status_code == 200
assert resp.json() == {
"param": "123",
"param2": "456",
}
def test_header_pass_extra_list():
client = TestClient(app)
resp = client.get(
"/header",
headers=[
("param", "123"),
("param2", "456"), # Pass a list of values as extra parameter
("param2", "789"),
],
)
assert resp.status_code == 200
resp_json = resp.json()
assert "param2" in resp_json
assert resp_json["param2"] == ["456", "789"]
def test_header_pass_extra_single():
client = TestClient(app)
resp = client.get(
"/header",
headers=[
("param", "123"),
("param2", "456"),
],
)
assert resp.status_code == 200
resp_json = resp.json()
assert "param2" in resp_json
assert resp_json["param2"] == "456"
def test_cookie_pass_extra_list():
client = TestClient(app)
client.cookies = [
("param", "123"),
("param2", "456"), # Pass a list of values as extra parameter
("param2", "789"),
]
resp = client.get("/cookie")
assert resp.status_code == 200
resp_json = resp.json()
assert "param2" in resp_json
assert resp_json["param2"] == "789" # Cookies only keep the last value
Domain
Subdomains
Functions
Classes
Dependencies
- __init__.py
- pydantic
- testclient.py
Source
Frequently Asked Questions
What does test_query_cookie_header_model_extra_params.py do?
test_query_cookie_header_model_extra_params.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Applications subdomain.
What functions are defined in test_query_cookie_header_model_extra_params.py?
test_query_cookie_header_model_extra_params.py defines 8 function(s): cookies_model_with_extra, header_model_with_extra, query_model_with_extra, test_cookie_pass_extra_list, test_header_pass_extra_list, test_header_pass_extra_single, test_query_pass_extra_list, test_query_pass_extra_single.
What does test_query_cookie_header_model_extra_params.py depend on?
test_query_cookie_header_model_extra_params.py imports 3 module(s): __init__.py, pydantic, testclient.py.
Where is test_query_cookie_header_model_extra_params.py in the architecture?
test_query_cookie_header_model_extra_params.py is located at tests/test_query_cookie_header_model_extra_params.py (domain: FastAPI, subdomain: Applications, directory: tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free