Home / File/ test_tutorial003.py — fastapi Source File

test_tutorial003.py — fastapi Source File

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

File python FastAPI Responses 5 imports 10 functions

Entity Profile

Dependency Diagram

graph LR
  9ba0315d_cf11_da38_8176_486317d0cd54["test_tutorial003.py"]
  808d2248_38ab_f087_eb52_830ec135cadf["utils"]
  9ba0315d_cf11_da38_8176_486317d0cd54 --> 808d2248_38ab_f087_eb52_830ec135cadf
  83e01a9c_50a9_bec9_6f86_8e729106de01["importlib"]
  9ba0315d_cf11_da38_8176_486317d0cd54 --> 83e01a9c_50a9_bec9_6f86_8e729106de01
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  9ba0315d_cf11_da38_8176_486317d0cd54 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  9ba0315d_cf11_da38_8176_486317d0cd54 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  9ba0315d_cf11_da38_8176_486317d0cd54 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  style 9ba0315d_cf11_da38_8176_486317d0cd54 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import importlib

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

from ...utils import needs_py310


@pytest.fixture(
    name="client",
    params=[
        pytest.param("tutorial003_py39"),
        pytest.param("tutorial003_py310", marks=needs_py310),
        pytest.param("tutorial003_an_py39"),
        pytest.param("tutorial003_an_py310", marks=needs_py310),
    ],
)
def get_client(request: pytest.FixtureRequest):
    mod = importlib.import_module(f"docs_src.security.{request.param}")

    client = TestClient(mod.app)
    return client


def test_login(client: TestClient):
    response = client.post("/token", data={"username": "johndoe", "password": "secret"})
    assert response.status_code == 200, response.text
    assert response.json() == {"access_token": "johndoe", "token_type": "bearer"}


def test_login_incorrect_password(client: TestClient):
    response = client.post(
        "/token", data={"username": "johndoe", "password": "incorrect"}
    )
    assert response.status_code == 400, response.text
    assert response.json() == {"detail": "Incorrect username or password"}


def test_login_incorrect_username(client: TestClient):
    response = client.post("/token", data={"username": "foo", "password": "secret"})
    assert response.status_code == 400, response.text
    assert response.json() == {"detail": "Incorrect username or password"}


def test_no_token(client: TestClient):
    response = client.get("/users/me")
    assert response.status_code == 401, response.text
    assert response.json() == {"detail": "Not authenticated"}
    assert response.headers["WWW-Authenticate"] == "Bearer"


def test_token(client: TestClient):
    response = client.get("/users/me", headers={"Authorization": "Bearer johndoe"})
    assert response.status_code == 200, response.text
    assert response.json() == {
        "username": "johndoe",
        "full_name": "John Doe",
        "email": "johndoe@example.com",
        "hashed_password": "fakehashedsecret",
// ... (158 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_tutorial003.py do?
test_tutorial003.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_tutorial003.py?
test_tutorial003.py defines 10 function(s): get_client, test_inactive_user, test_incorrect_token, test_incorrect_token_type, test_login, test_login_incorrect_password, test_login_incorrect_username, test_no_token, test_openapi_schema, test_token.
What does test_tutorial003.py depend on?
test_tutorial003.py imports 5 module(s): importlib, inline_snapshot, pytest, testclient.py, utils.
Where is test_tutorial003.py in the architecture?
test_tutorial003.py is located at tests/test_tutorial/test_security/test_tutorial003.py (domain: FastAPI, subdomain: Responses, directory: tests/test_tutorial/test_security).

Analyze Your Own Codebase

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

Try Supermodel Free