Home / File/ test_application.py — fastapi Source File

test_application.py — fastapi Source File

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

File python FastAPI Responses 4 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  9ddbfdd1_7392_6722_db09_7324223655a8["test_application.py"]
  224633e5_139d_dee9_c17b_aeac8a2f6027["main.py"]
  9ddbfdd1_7392_6722_db09_7324223655a8 --> 224633e5_139d_dee9_c17b_aeac8a2f6027
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  9ddbfdd1_7392_6722_db09_7324223655a8 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  9ddbfdd1_7392_6722_db09_7324223655a8 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  9ddbfdd1_7392_6722_db09_7324223655a8 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  style 9ddbfdd1_7392_6722_db09_7324223655a8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import pytest
from fastapi.testclient import TestClient
from inline_snapshot import snapshot

from .main import app

client = TestClient(app)


@pytest.mark.parametrize(
    "path,expected_status,expected_response",
    [
        ("/api_route", 200, {"message": "Hello World"}),
        ("/non_decorated_route", 200, {"message": "Hello World"}),
        ("/nonexistent", 404, {"detail": "Not Found"}),
    ],
)
def test_get_path(path, expected_status, expected_response):
    response = client.get(path)
    assert response.status_code == expected_status
    assert response.json() == expected_response


def test_swagger_ui():
    response = client.get("/docs")
    assert response.status_code == 200, response.text
    assert response.headers["content-type"] == "text/html; charset=utf-8"
    assert "swagger-ui-dist" in response.text
    assert (
        "oauth2RedirectUrl: window.location.origin + '/docs/oauth2-redirect'"
        in response.text
    )


def test_swagger_ui_oauth2_redirect():
    response = client.get("/docs/oauth2-redirect")
    assert response.status_code == 200, response.text
    assert response.headers["content-type"] == "text/html; charset=utf-8"
    assert "window.opener.swaggerUIRedirectOauth2" in response.text


def test_redoc():
    response = client.get("/redoc")
    assert response.status_code == 200, response.text
    assert response.headers["content-type"] == "text/html; charset=utf-8"
    assert "redoc@2" in response.text


def test_enum_status_code_response():
    response = client.get("/enum-status-code")
    assert response.status_code == 201, response.text
    assert response.json() == "foo bar"


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == snapshot(
        {
            "openapi": "3.1.0",
// ... (1226 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_application.py do?
test_application.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Responses subdomain.
What functions are defined in test_application.py?
test_application.py defines 6 function(s): test_enum_status_code_response, test_get_path, test_openapi_schema, test_redoc, test_swagger_ui, test_swagger_ui_oauth2_redirect.
What does test_application.py depend on?
test_application.py imports 4 module(s): inline_snapshot, main.py, pytest, testclient.py.
Where is test_application.py in the architecture?
test_application.py is located at tests/test_application.py (domain: FastAPI, subdomain: Responses, directory: tests).

Analyze Your Own Codebase

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

Try Supermodel Free