Home / File/ test_request_param_model_by_alias.py — fastapi Source File

test_request_param_model_by_alias.py — fastapi Source File

Architecture documentation for test_request_param_model_by_alias.py, a python file in the fastapi codebase. 4 imports, 0 dependents.

File python FastAPI Applications 4 imports 9 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  4f114e69_3a87_6047_e947_43781f48ce75["test_request_param_model_by_alias.py"]
  752ca3d8_e45b_84ed_d1a1_588cbc236b65["dirty_equals"]
  4f114e69_3a87_6047_e947_43781f48ce75 --> 752ca3d8_e45b_84ed_d1a1_588cbc236b65
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  4f114e69_3a87_6047_e947_43781f48ce75 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  4f114e69_3a87_6047_e947_43781f48ce75 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  4f114e69_3a87_6047_e947_43781f48ce75 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style 4f114e69_3a87_6047_e947_43781f48ce75 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from dirty_equals import IsPartialDict
from fastapi import Cookie, FastAPI, Header, Query
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field

app = FastAPI()


class Model(BaseModel):
    param: str = Field(alias="param_alias")


@app.get("/query")
async def query_model(data: Model = Query()):
    return {"param": data.param}


@app.get("/header")
async def header_model(data: Model = Header()):
    return {"param": data.param}


@app.get("/cookie")
async def cookie_model(data: Model = Cookie()):
    return {"param": data.param}


def test_query_model_with_alias():
    client = TestClient(app)
    response = client.get("/query", params={"param_alias": "value"})
    assert response.status_code == 200, response.text
    assert response.json() == {"param": "value"}


def test_header_model_with_alias():
    client = TestClient(app)
    response = client.get("/header", headers={"param_alias": "value"})
    assert response.status_code == 200, response.text
    assert response.json() == {"param": "value"}


def test_cookie_model_with_alias():
    client = TestClient(app)
    client.cookies.set("param_alias", "value")
    response = client.get("/cookie")
    assert response.status_code == 200, response.text
    assert response.json() == {"param": "value"}


def test_query_model_with_alias_by_name():
    client = TestClient(app)
    response = client.get("/query", params={"param": "value"})
    assert response.status_code == 422, response.text
    details = response.json()
    assert details["detail"][0]["input"] == {"param": "value"}


def test_header_model_with_alias_by_name():
    client = TestClient(app)
    response = client.get("/header", headers={"param": "value"})
    assert response.status_code == 422, response.text
    details = response.json()
    assert details["detail"][0]["input"] == IsPartialDict({"param": "value"})


def test_cookie_model_with_alias_by_name():
    client = TestClient(app)
    client.cookies.set("param", "value")
    response = client.get("/cookie")
    assert response.status_code == 422, response.text
    details = response.json()
    assert details["detail"][0]["input"] == {"param": "value"}

Domain

Subdomains

Classes

Dependencies

Frequently Asked Questions

What does test_request_param_model_by_alias.py do?
test_request_param_model_by_alias.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_request_param_model_by_alias.py?
test_request_param_model_by_alias.py defines 9 function(s): cookie_model, header_model, query_model, test_cookie_model_with_alias, test_cookie_model_with_alias_by_name, test_header_model_with_alias, test_header_model_with_alias_by_name, test_query_model_with_alias, test_query_model_with_alias_by_name.
What does test_request_param_model_by_alias.py depend on?
test_request_param_model_by_alias.py imports 4 module(s): __init__.py, dirty_equals, pydantic, testclient.py.
Where is test_request_param_model_by_alias.py in the architecture?
test_request_param_model_by_alias.py is located at tests/test_request_param_model_by_alias.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