Home / File/ test_tutorial002.py — fastapi Source File

test_tutorial002.py — fastapi Source File

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

File python FastAPI Routing 10 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  24c45a29_accd_8258_a7da_ddf6ea0170f4["test_tutorial002.py"]
  83e01a9c_50a9_bec9_6f86_8e729106de01["importlib"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> 83e01a9c_50a9_bec9_6f86_8e729106de01
  9c2c9cad_dfd2_7d1a_1c6d_b8a448285db4["warnings"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> 9c2c9cad_dfd2_7d1a_1c6d_b8a448285db4
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  752ca3d8_e45b_84ed_d1a1_588cbc236b65["dirty_equals"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> 752ca3d8_e45b_84ed_d1a1_588cbc236b65
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  66098adb_f423_c165_4fdd_f162b4f94613["sqlalchemy"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> 66098adb_f423_c165_4fdd_f162b4f94613
  bf11c16a_04e7_1fd0_b317_a1196fc34aad["sqlmodel"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> bf11c16a_04e7_1fd0_b317_a1196fc34aad
  e2d877c5_ba6d_83fd_271c_fa7fee12665a["sqlmodel.main"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> e2d877c5_ba6d_83fd_271c_fa7fee12665a
  8fd7072e_05b0_6622_0f14_e1e357032855["utils.py"]
  24c45a29_accd_8258_a7da_ddf6ea0170f4 --> 8fd7072e_05b0_6622_0f14_e1e357032855
  style 24c45a29_accd_8258_a7da_ddf6ea0170f4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import importlib
import warnings

import pytest
from dirty_equals import IsInt
from fastapi.testclient import TestClient
from inline_snapshot import Is, snapshot
from sqlalchemy import StaticPool
from sqlmodel import SQLModel, create_engine
from sqlmodel.main import default_registry

from tests.utils import needs_py310


def clear_sqlmodel():
    # Clear the tables in the metadata for the default base model
    SQLModel.metadata.clear()
    # Clear the Models associated with the registry, to avoid warnings
    default_registry.dispose()


@pytest.fixture(
    name="client",
    params=[
        pytest.param("tutorial002_py39"),
        pytest.param("tutorial002_py310", marks=needs_py310),
        pytest.param("tutorial002_an_py39"),
        pytest.param("tutorial002_an_py310", marks=needs_py310),
    ],
)
def get_client(request: pytest.FixtureRequest):
    clear_sqlmodel()
    # TODO: remove when updating SQL tutorial to use new lifespan API
    with warnings.catch_warnings(record=True):
        warnings.simplefilter("always")
        mod = importlib.import_module(f"docs_src.sql_databases.{request.param}")
        clear_sqlmodel()
        importlib.reload(mod)
    mod.sqlite_url = "sqlite://"
    mod.engine = create_engine(
        mod.sqlite_url, connect_args={"check_same_thread": False}, poolclass=StaticPool
    )

    with TestClient(mod.app) as c:
        yield c
    # Clean up connection explicitly to avoid resource warning
    mod.engine.dispose()


def test_crud_app(client: TestClient):
    # TODO: this warns that SQLModel.from_orm is deprecated in Pydantic v1, refactor
    # this if using obj.model_validate becomes independent of Pydantic v2
    with warnings.catch_warnings(record=True):
        warnings.simplefilter("always")
        # No heroes before creating
        response = client.get("heroes/")
        assert response.status_code == 200, response.text
        assert response.json() == []

        # Create a hero
// ... (379 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_tutorial002.py do?
test_tutorial002.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_tutorial002.py?
test_tutorial002.py defines 4 function(s): clear_sqlmodel, get_client, test_crud_app, test_openapi_schema.
What does test_tutorial002.py depend on?
test_tutorial002.py imports 10 module(s): dirty_equals, importlib, inline_snapshot, pytest, sqlalchemy, sqlmodel, sqlmodel.main, testclient.py, and 2 more.
Where is test_tutorial002.py in the architecture?
test_tutorial002.py is located at tests/test_tutorial/test_sql_databases/test_tutorial002.py (domain: FastAPI, subdomain: Routing, directory: tests/test_tutorial/test_sql_databases).

Analyze Your Own Codebase

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

Try Supermodel Free