Home / File/ test_repeated_dependency_schema.py — fastapi Source File

test_repeated_dependency_schema.py — fastapi Source File

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

File python FastAPI Routing 3 imports 5 functions

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

from fastapi import Depends, FastAPI, Header, status
from fastapi.testclient import TestClient
from inline_snapshot import snapshot

app = FastAPI()


def get_header(*, someheader: str = Header()):
    return someheader


def get_something_else(*, someheader: str = Depends(get_header)):
    return f"{someheader}123"


@app.get("/")
def get_deps(dep1: str = Depends(get_header), dep2: str = Depends(get_something_else)):
    return {"dep1": dep1, "dep2": dep2}


client = TestClient(app)


def test_response():
    response = client.get("/", headers={"someheader": "hello"})
    assert response.status_code == status.HTTP_200_OK
    assert response.json() == {"dep1": "hello", "dep2": "hello123"}


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == status.HTTP_200_OK
    actual_schema = response.json()
    assert (
        len(actual_schema["paths"]["/"]["get"]["parameters"]) == 1
    )  # primary goal of this test
    assert actual_schema == snapshot(
        {
            "components": {
                "schemas": {
                    "HTTPValidationError": {
                        "properties": {
                            "detail": {
                                "items": {
                                    "$ref": "#/components/schemas/ValidationError"
                                },
                                "title": "Detail",
                                "type": "array",
                            }
                        },
                        "title": "HTTPValidationError",
                        "type": "object",
                    },
                    "ValidationError": {
                        "properties": {
                            "ctx": {"title": "Context", "type": "object"},
                            "input": {"title": "Input"},
                            "loc": {
                                "items": {
                                    "anyOf": [{"type": "string"}, {"type": "integer"}]
                                },
                                "title": "Location",
                                "type": "array",
                            },
                            "msg": {"title": "Message", "type": "string"},
                            "type": {"title": "Error Type", "type": "string"},
                        },
                        "required": ["loc", "msg", "type"],
                        "title": "ValidationError",
                        "type": "object",
                    },
                }
            },
            "info": {"title": "FastAPI", "version": "0.1.0"},
            "openapi": "3.1.0",
            "paths": {
                "/": {
                    "get": {
                        "operationId": "get_deps__get",
                        "parameters": [
                            {
                                "in": "header",
                                "name": "someheader",
                                "required": True,
                                "schema": {"title": "Someheader", "type": "string"},
                            }
                        ],
                        "responses": {
                            "200": {
                                "content": {"application/json": {"schema": {}}},
                                "description": "Successful Response",
                            },
                            "422": {
                                "content": {
                                    "application/json": {
                                        "schema": {
                                            "$ref": "#/components/schemas/HTTPValidationError"
                                        }
                                    }
                                },
                                "description": "Validation Error",
                            },
                        },
                        "summary": "Get Deps",
                    }
                }
            },
        }
    )

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_repeated_dependency_schema.py do?
test_repeated_dependency_schema.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Routing subdomain.
What functions are defined in test_repeated_dependency_schema.py?
test_repeated_dependency_schema.py defines 5 function(s): get_deps, get_header, get_something_else, test_openapi_schema, test_response.
What does test_repeated_dependency_schema.py depend on?
test_repeated_dependency_schema.py imports 3 module(s): __init__.py, inline_snapshot, testclient.py.
Where is test_repeated_dependency_schema.py in the architecture?
test_repeated_dependency_schema.py is located at tests/test_repeated_dependency_schema.py (domain: FastAPI, subdomain: Routing, directory: tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free