Home / File/ test_forms_single_param.py — fastapi Source File

test_forms_single_param.py — fastapi Source File

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

File python FastAPI Responses 4 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  9eed5ce0_eb37_cec8_53d3_c799539dd3c5["test_forms_single_param.py"]
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  9eed5ce0_eb37_cec8_53d3_c799539dd3c5 --> 0dda2280_3359_8460_301c_e98c77e78185
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  9eed5ce0_eb37_cec8_53d3_c799539dd3c5 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  9eed5ce0_eb37_cec8_53d3_c799539dd3c5 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  9eed5ce0_eb37_cec8_53d3_c799539dd3c5 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  style 9eed5ce0_eb37_cec8_53d3_c799539dd3c5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Annotated

from fastapi import FastAPI, Form
from fastapi.testclient import TestClient
from inline_snapshot import snapshot

app = FastAPI()


@app.post("/form/")
def post_form(username: Annotated[str, Form()]):
    return username


client = TestClient(app)


def test_single_form_field():
    response = client.post("/form/", data={"username": "Rick"})
    assert response.status_code == 200, response.text
    assert response.json() == "Rick"


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": {
                "/form/": {
                    "post": {
                        "summary": "Post Form",
                        "operationId": "post_form_form__post",
                        "requestBody": {
                            "content": {
                                "application/x-www-form-urlencoded": {
                                    "schema": {
                                        "$ref": "#/components/schemas/Body_post_form_form__post"
                                    }
                                }
                            },
                            "required": True,
                        },
                        "responses": {
                            "200": {
                                "description": "Successful Response",
                                "content": {"application/json": {"schema": {}}},
                            },
                            "422": {
                                "description": "Validation Error",
                                "content": {
                                    "application/json": {
                                        "schema": {
                                            "$ref": "#/components/schemas/HTTPValidationError"
                                        }
                                    }
                                },
                            },
                        },
                    }
                }
            },
            "components": {
                "schemas": {
                    "Body_post_form_form__post": {
                        "properties": {
                            "username": {"type": "string", "title": "Username"}
                        },
                        "type": "object",
                        "required": ["username"],
                        "title": "Body_post_form_form__post",
                    },
                    "HTTPValidationError": {
                        "properties": {
                            "detail": {
                                "items": {
                                    "$ref": "#/components/schemas/ValidationError"
                                },
                                "type": "array",
                                "title": "Detail",
                            }
                        },
                        "type": "object",
                        "title": "HTTPValidationError",
                    },
                    "ValidationError": {
                        "properties": {
                            "ctx": {"title": "Context", "type": "object"},
                            "input": {"title": "Input"},
                            "loc": {
                                "items": {
                                    "anyOf": [{"type": "string"}, {"type": "integer"}]
                                },
                                "type": "array",
                                "title": "Location",
                            },
                            "msg": {"type": "string", "title": "Message"},
                            "type": {"type": "string", "title": "Error Type"},
                        },
                        "type": "object",
                        "required": ["loc", "msg", "type"],
                        "title": "ValidationError",
                    },
                }
            },
        }
    )

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_forms_single_param.py do?
test_forms_single_param.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Responses subdomain.
What functions are defined in test_forms_single_param.py?
test_forms_single_param.py defines 3 function(s): post_form, test_openapi_schema, test_single_form_field.
What does test_forms_single_param.py depend on?
test_forms_single_param.py imports 4 module(s): __init__.py, inline_snapshot, testclient.py, typing.
Where is test_forms_single_param.py in the architecture?
test_forms_single_param.py is located at tests/test_forms_single_param.py (domain: FastAPI, subdomain: Responses, directory: tests).

Analyze Your Own Codebase

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

Try Supermodel Free