Home / File/ test_http_connection_injection.py — fastapi Source File

test_http_connection_injection.py — fastapi Source File

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

File python FastAPI Routing 4 imports 5 functions

Entity Profile

Dependency Diagram

graph LR
  6077da0e_d33a_92fd_81a7_99d65e744a07["test_http_connection_injection.py"]
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  6077da0e_d33a_92fd_81a7_99d65e744a07 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a805834a_0e5d_533a_2add_5e98b21fda92["requests.py"]
  6077da0e_d33a_92fd_81a7_99d65e744a07 --> a805834a_0e5d_533a_2add_5e98b21fda92
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  6077da0e_d33a_92fd_81a7_99d65e744a07 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  456d22db_6672_cc20_1dd4_ba4db2643a14["starlette.websockets"]
  6077da0e_d33a_92fd_81a7_99d65e744a07 --> 456d22db_6672_cc20_1dd4_ba4db2643a14
  style 6077da0e_d33a_92fd_81a7_99d65e744a07 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from fastapi import Depends, FastAPI
from fastapi.requests import HTTPConnection
from fastapi.testclient import TestClient
from starlette.websockets import WebSocket

app = FastAPI()
app.state.value = 42


async def extract_value_from_http_connection(conn: HTTPConnection):
    return conn.app.state.value


@app.get("/http")
async def get_value_by_http(value: int = Depends(extract_value_from_http_connection)):
    return value


@app.websocket("/ws")
async def get_value_by_ws(
    websocket: WebSocket, value: int = Depends(extract_value_from_http_connection)
):
    await websocket.accept()
    await websocket.send_json(value)
    await websocket.close()


client = TestClient(app)


def test_value_extracting_by_http():
    response = client.get("/http")
    assert response.status_code == 200
    assert response.json() == 42


def test_value_extracting_by_ws():
    with client.websocket_connect("/ws") as websocket:
        assert websocket.receive_json() == 42

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_http_connection_injection.py do?
test_http_connection_injection.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_http_connection_injection.py?
test_http_connection_injection.py defines 5 function(s): extract_value_from_http_connection, get_value_by_http, get_value_by_ws, test_value_extracting_by_http, test_value_extracting_by_ws.
What does test_http_connection_injection.py depend on?
test_http_connection_injection.py imports 4 module(s): __init__.py, requests.py, starlette.websockets, testclient.py.
Where is test_http_connection_injection.py in the architecture?
test_http_connection_injection.py is located at tests/test_http_connection_injection.py (domain: FastAPI, subdomain: Routing, directory: tests).

Analyze Your Own Codebase

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

Try Supermodel Free