Home / File/ test_main.py — fastapi Source File

test_main.py — fastapi Source File

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

File python FastAPI Applications 2 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  4510050d_db23_2372_d56a_62f40b3284b9["test_main.py"]
  cefe3d74_93b2_43cd_ee6d_9488366d4d0e["main.py"]
  4510050d_db23_2372_d56a_62f40b3284b9 --> cefe3d74_93b2_43cd_ee6d_9488366d4d0e
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  4510050d_db23_2372_d56a_62f40b3284b9 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  style 4510050d_db23_2372_d56a_62f40b3284b9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from fastapi.testclient import TestClient

from .main import app

client = TestClient(app)


def test_read_item():
    response = client.get("/items/foo", headers={"X-Token": "coneofsilence"})
    assert response.status_code == 200
    assert response.json() == {
        "id": "foo",
        "title": "Foo",
        "description": "There goes my hero",
    }


def test_read_item_bad_token():
    response = client.get("/items/foo", headers={"X-Token": "hailhydra"})
    assert response.status_code == 400
    assert response.json() == {"detail": "Invalid X-Token header"}


def test_read_nonexistent_item():
    response = client.get("/items/baz", headers={"X-Token": "coneofsilence"})
    assert response.status_code == 404
    assert response.json() == {"detail": "Item not found"}


def test_create_item():
    response = client.post(
        "/items/",
        headers={"X-Token": "coneofsilence"},
        json={"id": "foobar", "title": "Foo Bar", "description": "The Foo Barters"},
    )
    assert response.status_code == 200
    assert response.json() == {
        "id": "foobar",
        "title": "Foo Bar",
        "description": "The Foo Barters",
    }


def test_create_item_bad_token():
    response = client.post(
        "/items/",
        headers={"X-Token": "hailhydra"},
        json={"id": "bazz", "title": "Bazz", "description": "Drop the bazz"},
    )
    assert response.status_code == 400
    assert response.json() == {"detail": "Invalid X-Token header"}


def test_create_existing_item():
    response = client.post(
        "/items/",
        headers={"X-Token": "coneofsilence"},
        json={
            "id": "foo",
            "title": "The Foo ID Stealers",
            "description": "There goes my stealer",
        },
    )
    assert response.status_code == 409
    assert response.json() == {"detail": "Item already exists"}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_main.py do?
test_main.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_main.py?
test_main.py defines 6 function(s): test_create_existing_item, test_create_item, test_create_item_bad_token, test_read_item, test_read_item_bad_token, test_read_nonexistent_item.
What does test_main.py depend on?
test_main.py imports 2 module(s): main.py, testclient.py.
Where is test_main.py in the architecture?
test_main.py is located at docs_src/app_testing/app_b_an_py310/test_main.py (domain: FastAPI, subdomain: Applications, directory: docs_src/app_testing/app_b_an_py310).

Analyze Your Own Codebase

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

Try Supermodel Free