Home / File/ test_request_body_parameters_media_type.py — fastapi Source File

test_request_body_parameters_media_type.py — fastapi Source File

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

File python FastAPI Applications 4 imports 3 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  ecc1f57b_9ed7_2e84_303f_5f43516bb6a7["test_request_body_parameters_media_type.py"]
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  ecc1f57b_9ed7_2e84_303f_5f43516bb6a7 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  ecc1f57b_9ed7_2e84_303f_5f43516bb6a7 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  ecc1f57b_9ed7_2e84_303f_5f43516bb6a7 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  ecc1f57b_9ed7_2e84_303f_5f43516bb6a7 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style ecc1f57b_9ed7_2e84_303f_5f43516bb6a7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from fastapi import Body, FastAPI
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel

app = FastAPI()

media_type = "application/vnd.api+json"


# NOTE: These are not valid JSON:API resources
# but they are fine for testing requestBody with custom media_type
class Product(BaseModel):
    name: str
    price: float


class Shop(BaseModel):
    name: str


@app.post("/products")
async def create_product(data: Product = Body(media_type=media_type, embed=True)):
    pass  # pragma: no cover


@app.post("/shops")
async def create_shop(
    data: Shop = Body(media_type=media_type),
    included: list[Product] = Body(default=[], media_type=media_type),
):
    pass  # pragma: no cover


client = TestClient(app)


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == snapshot(
        {
            "openapi": "3.1.0",
            "info": {"title": "FastAPI", "version": "0.1.0"},
            "paths": {
                "/products": {
                    "post": {
                        "summary": "Create Product",
                        "operationId": "create_product_products_post",
                        "requestBody": {
                            "content": {
                                "application/vnd.api+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/Body_create_product_products_post"
                                    }
                                }
                            },
                            "required": True,
                        },
                        "responses": {
// ... (125 more lines)

Domain

Subdomains

Classes

Dependencies

Frequently Asked Questions

What does test_request_body_parameters_media_type.py do?
test_request_body_parameters_media_type.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_body_parameters_media_type.py?
test_request_body_parameters_media_type.py defines 3 function(s): create_product, create_shop, test_openapi_schema.
What does test_request_body_parameters_media_type.py depend on?
test_request_body_parameters_media_type.py imports 4 module(s): __init__.py, inline_snapshot, pydantic, testclient.py.
Where is test_request_body_parameters_media_type.py in the architecture?
test_request_body_parameters_media_type.py is located at tests/test_request_body_parameters_media_type.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