Home / Function/ test_get_db() — fastapi Function Reference

test_get_db() — fastapi Function Reference

Architecture documentation for the test_get_db() function in test_tutorial008.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  cdf6421c_e752_acca_080e_8e4fe4826f53["test_get_db()"]
  006f9ea5_2d09_91c9_f69c_3b181f3aa010["test_tutorial008.py"]
  cdf6421c_e752_acca_080e_8e4fe4826f53 -->|defined in| 006f9ea5_2d09_91c9_f69c_3b181f3aa010
  style cdf6421c_e752_acca_080e_8e4fe4826f53 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/test_tutorial/test_dependencies/test_tutorial008.py lines 31–64

def test_get_db(module: ModuleType):
    app = FastAPI()

    @app.get("/")
    def read_root(c: Annotated[Any, Depends(module.dependency_c)]):
        return {"c": str(c)}

    client = TestClient(app)

    a_mock = Mock()
    b_mock = Mock()
    c_mock = Mock()

    with (
        patch(
            f"{module.__name__}.generate_dep_a",
            return_value=a_mock,
            create=True,
        ),
        patch(
            f"{module.__name__}.generate_dep_b",
            return_value=b_mock,
            create=True,
        ),
        patch(
            f"{module.__name__}.generate_dep_c",
            return_value=c_mock,
            create=True,
        ),
    ):
        response = client.get("/")

    assert response.status_code == 200
    assert response.json() == {"c": str(c_mock)}

Domain

Subdomains

Frequently Asked Questions

What does test_get_db() do?
test_get_db() is a function in the fastapi codebase, defined in tests/test_tutorial/test_dependencies/test_tutorial008.py.
Where is test_get_db() defined?
test_get_db() is defined in tests/test_tutorial/test_dependencies/test_tutorial008.py at line 31.

Analyze Your Own Codebase

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

Try Supermodel Free