test_tutorial004.py — fastapi Source File
Architecture documentation for test_tutorial004.py, a python file in the fastapi codebase. 7 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 99a6e52c_39c3_5825_2899_8b0fa980bff4["test_tutorial004.py"] 808d2248_38ab_f087_eb52_830ec135cadf["utils"] 99a6e52c_39c3_5825_2899_8b0fa980bff4 --> 808d2248_38ab_f087_eb52_830ec135cadf 83e01a9c_50a9_bec9_6f86_8e729106de01["importlib"] 99a6e52c_39c3_5825_2899_8b0fa980bff4 --> 83e01a9c_50a9_bec9_6f86_8e729106de01 fb2d9376_ca24_f2b2_f130_cc10e9f2e732["types"] 99a6e52c_39c3_5825_2899_8b0fa980bff4 --> fb2d9376_ca24_f2b2_f130_cc10e9f2e732 d1bf66df_8a92_7a7c_dab4_0865060effa4["unittest.mock"] 99a6e52c_39c3_5825_2899_8b0fa980bff4 --> d1bf66df_8a92_7a7c_dab4_0865060effa4 5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"] 99a6e52c_39c3_5825_2899_8b0fa980bff4 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9 a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] 99a6e52c_39c3_5825_2899_8b0fa980bff4 --> a7c04dee_ee23_5891_b185_47ff6bed036d a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"] 99a6e52c_39c3_5825_2899_8b0fa980bff4 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a style 99a6e52c_39c3_5825_2899_8b0fa980bff4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import importlib
from types import ModuleType
from unittest.mock import patch
import pytest
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310
@pytest.fixture(
name="mod",
params=[
pytest.param("tutorial004_py39"),
pytest.param("tutorial004_py310", marks=needs_py310),
pytest.param("tutorial004_an_py39"),
pytest.param("tutorial004_an_py310", marks=needs_py310),
],
)
def get_mod(request: pytest.FixtureRequest):
mod = importlib.import_module(f"docs_src.security.{request.param}")
return mod
def get_access_token(*, username="johndoe", password="secret", client: TestClient):
data = {"username": username, "password": password}
response = client.post("/token", data=data)
content = response.json()
access_token = content.get("access_token")
return access_token
def test_login(mod: ModuleType):
client = TestClient(mod.app)
response = client.post("/token", data={"username": "johndoe", "password": "secret"})
assert response.status_code == 200, response.text
content = response.json()
assert "access_token" in content
assert content["token_type"] == "bearer"
def test_login_incorrect_password(mod: ModuleType):
client = TestClient(mod.app)
response = client.post(
"/token", data={"username": "johndoe", "password": "incorrect"}
)
assert response.status_code == 401, response.text
assert response.json() == {"detail": "Incorrect username or password"}
def test_login_incorrect_username(mod: ModuleType):
client = TestClient(mod.app)
response = client.post("/token", data={"username": "foo", "password": "secret"})
assert response.status_code == 401, response.text
assert response.json() == {"detail": "Incorrect username or password"}
def test_no_token(mod: ModuleType):
// ... (315 more lines)
Domain
Subdomains
Functions
- get_access_token()
- get_mod()
- test_create_access_token()
- test_get_password_hash()
- test_incorrect_token()
- test_incorrect_token_type()
- test_login()
- test_login_incorrect_password()
- test_login_incorrect_username()
- test_no_token()
- test_openapi_schema()
- test_read_items()
- test_token()
- test_token_inactive_user()
- test_token_no_sub()
- test_token_no_username()
- test_token_nonexistent_user()
- test_verify_password()
Dependencies
- importlib
- inline_snapshot
- pytest
- testclient.py
- types
- unittest.mock
- utils
Source
Frequently Asked Questions
What does test_tutorial004.py do?
test_tutorial004.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_tutorial004.py?
test_tutorial004.py defines 18 function(s): get_access_token, get_mod, test_create_access_token, test_get_password_hash, test_incorrect_token, test_incorrect_token_type, test_login, test_login_incorrect_password, test_login_incorrect_username, test_no_token, and 8 more.
What does test_tutorial004.py depend on?
test_tutorial004.py imports 7 module(s): importlib, inline_snapshot, pytest, testclient.py, types, unittest.mock, utils.
Where is test_tutorial004.py in the architecture?
test_tutorial004.py is located at tests/test_tutorial/test_security/test_tutorial004.py (domain: FastAPI, subdomain: Applications, 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