Home / File/ test_tutorial008c.py — fastapi Source File

test_tutorial008c.py — fastapi Source File

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

File python FastAPI Applications 6 imports 5 functions

Entity Profile

Dependency Diagram

graph LR
  b119ece4_9002_e2cb_3632_ecf7d8451053["test_tutorial008c.py"]
  83e01a9c_50a9_bec9_6f86_8e729106de01["importlib"]
  b119ece4_9002_e2cb_3632_ecf7d8451053 --> 83e01a9c_50a9_bec9_6f86_8e729106de01
  fb2d9376_ca24_f2b2_f130_cc10e9f2e732["types"]
  b119ece4_9002_e2cb_3632_ecf7d8451053 --> fb2d9376_ca24_f2b2_f130_cc10e9f2e732
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  b119ece4_9002_e2cb_3632_ecf7d8451053 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  01c652c5_d85c_f45e_848e_412c94ea4172["exceptions.py"]
  b119ece4_9002_e2cb_3632_ecf7d8451053 --> 01c652c5_d85c_f45e_848e_412c94ea4172
  2d54c1ec_3e75_6f8e_face_5433598e4278["FastAPIError"]
  b119ece4_9002_e2cb_3632_ecf7d8451053 --> 2d54c1ec_3e75_6f8e_face_5433598e4278
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  b119ece4_9002_e2cb_3632_ecf7d8451053 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  style b119ece4_9002_e2cb_3632_ecf7d8451053 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import importlib
from types import ModuleType

import pytest
from fastapi.exceptions import FastAPIError
from fastapi.testclient import TestClient


@pytest.fixture(
    name="mod",
    params=[
        pytest.param("tutorial008c_py39"),
        pytest.param("tutorial008c_an_py39"),
    ],
)
def get_mod(request: pytest.FixtureRequest):
    mod = importlib.import_module(f"docs_src.dependencies.{request.param}")

    return mod


def test_get_no_item(mod: ModuleType):
    client = TestClient(mod.app)
    response = client.get("/items/foo")
    assert response.status_code == 404, response.text
    assert response.json() == {"detail": "Item not found, there's only a plumbus here"}


def test_get(mod: ModuleType):
    client = TestClient(mod.app)
    response = client.get("/items/plumbus")
    assert response.status_code == 200, response.text
    assert response.json() == "plumbus"


def test_fastapi_error(mod: ModuleType):
    client = TestClient(mod.app)
    with pytest.raises(FastAPIError) as exc_info:
        client.get("/items/portal-gun")
    assert "raising an exception and a dependency with yield" in exc_info.value.args[0]


def test_internal_server_error(mod: ModuleType):
    client = TestClient(mod.app, raise_server_exceptions=False)
    response = client.get("/items/portal-gun")
    assert response.status_code == 500, response.text
    assert response.text == "Internal Server Error"

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_tutorial008c.py do?
test_tutorial008c.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Applications subdomain.
What functions are defined in test_tutorial008c.py?
test_tutorial008c.py defines 5 function(s): get_mod, test_fastapi_error, test_get, test_get_no_item, test_internal_server_error.
What does test_tutorial008c.py depend on?
test_tutorial008c.py imports 6 module(s): FastAPIError, exceptions.py, importlib, pytest, testclient.py, types.
Where is test_tutorial008c.py in the architecture?
test_tutorial008c.py is located at tests/test_tutorial/test_dependencies/test_tutorial008c.py (domain: FastAPI, subdomain: Applications, directory: tests/test_tutorial/test_dependencies).

Analyze Your Own Codebase

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

Try Supermodel Free