Home / File/ test_tutorial003.py — fastapi Source File

test_tutorial003.py — fastapi Source File

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

File python FastAPI Routing 4 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  32fe68d3_95d9_2e66_78d9_f6e43815ee26["test_tutorial003.py"]
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  32fe68d3_95d9_2e66_78d9_f6e43815ee26 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  32fe68d3_95d9_2e66_78d9_f6e43815ee26 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  71f2968e_1af1_02b0_6082_4ff2aceb8912["tutorial003_py39.py"]
  32fe68d3_95d9_2e66_78d9_f6e43815ee26 --> 71f2968e_1af1_02b0_6082_4ff2aceb8912
  4f6ccd91_d586_2cd0_2786_9662b95f5cae["fake_answer_to_everything_ml_model"]
  32fe68d3_95d9_2e66_78d9_f6e43815ee26 --> 4f6ccd91_d586_2cd0_2786_9662b95f5cae
  style 32fe68d3_95d9_2e66_78d9_f6e43815ee26 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from fastapi.testclient import TestClient
from inline_snapshot import snapshot

from docs_src.events.tutorial003_py39 import (
    app,
    fake_answer_to_everything_ml_model,
    ml_models,
)


def test_events():
    assert not ml_models, "ml_models should be empty"
    with TestClient(app) as client:
        assert ml_models["answer_to_everything"] == fake_answer_to_everything_ml_model
        response = client.get("/predict", params={"x": 2})
        assert response.status_code == 200, response.text
        assert response.json() == {"result": 84.0}
    assert not ml_models, "ml_models should be empty"


def test_openapi_schema():
    with TestClient(app) as client:
        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": {
                    "/predict": {
                        "get": {
                            "summary": "Predict",
                            "operationId": "predict_predict_get",
                            "parameters": [
                                {
                                    "required": True,
                                    "schema": {"title": "X", "type": "number"},
                                    "name": "x",
                                    "in": "query",
                                }
                            ],
                            "responses": {
                                "200": {
                                    "description": "Successful Response",
                                    "content": {"application/json": {"schema": {}}},
                                },
                                "422": {
                                    "description": "Validation Error",
                                    "content": {
                                        "application/json": {
                                            "schema": {
                                                "$ref": "#/components/schemas/HTTPValidationError"
                                            }
                                        }
                                    },
                                },
                            },
                        }
                    }
                },
                "components": {
                    "schemas": {
                        "HTTPValidationError": {
                            "title": "HTTPValidationError",
                            "type": "object",
                            "properties": {
                                "detail": {
                                    "title": "Detail",
                                    "type": "array",
                                    "items": {
                                        "$ref": "#/components/schemas/ValidationError"
                                    },
                                }
                            },
                        },
                        "ValidationError": {
                            "title": "ValidationError",
                            "required": ["loc", "msg", "type"],
                            "type": "object",
                            "properties": {
                                "ctx": {"title": "Context", "type": "object"},
                                "input": {"title": "Input"},
                                "loc": {
                                    "title": "Location",
                                    "type": "array",
                                    "items": {
                                        "anyOf": [
                                            {"type": "string"},
                                            {"type": "integer"},
                                        ]
                                    },
                                },
                                "msg": {"title": "Message", "type": "string"},
                                "type": {"title": "Error Type", "type": "string"},
                            },
                        },
                    }
                },
            }
        )

Domain

Subdomains

Frequently Asked Questions

What does test_tutorial003.py do?
test_tutorial003.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_tutorial003.py?
test_tutorial003.py defines 2 function(s): test_events, test_openapi_schema.
What does test_tutorial003.py depend on?
test_tutorial003.py imports 4 module(s): fake_answer_to_everything_ml_model, inline_snapshot, testclient.py, tutorial003_py39.py.
Where is test_tutorial003.py in the architecture?
test_tutorial003.py is located at tests/test_tutorial/test_events/test_tutorial003.py (domain: FastAPI, subdomain: Routing, directory: tests/test_tutorial/test_events).

Analyze Your Own Codebase

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

Try Supermodel Free