The following issues were found

tests/test_tutorial/test_handling_errors/test_tutorial006.py
13 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.handling_errors.tutorial006 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",
    "info": {"title": "FastAPI", "version": "0.1.0"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 74 Column: 1

              }


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 76
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_get_validation_error():
    response = client.get("/items/foo")

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 77
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_get_validation_error():
    response = client.get("/items/foo")
    assert response.status_code == 422, response.text

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 80 Column: 1

                  assert response.json() == openapi_schema


def test_get_validation_error():
    response = client.get("/items/foo")
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 82
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_get_validation_error():
    response = client.get("/items/foo")
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {
                "loc": ["path", "item_id"],
                "msg": "value is not a valid integer",

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 83
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_get_validation_error():
    response = client.get("/items/foo")
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {
                "loc": ["path", "item_id"],
                "msg": "value is not a valid integer",
                "type": "type_error.integer",

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 94 Column: 1

                  }


def test_get_http_error():
    response = client.get("/items/3")
    assert response.status_code == 418, response.text
    assert response.json() == {"detail": "Nope! I don't like 3."}



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 96
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_get_http_error():
    response = client.get("/items/3")
    assert response.status_code == 418, response.text
    assert response.json() == {"detail": "Nope! I don't like 3."}


def test_get():
    response = client.get("/items/2")

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 97
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_get_http_error():
    response = client.get("/items/3")
    assert response.status_code == 418, response.text
    assert response.json() == {"detail": "Nope! I don't like 3."}


def test_get():
    response = client.get("/items/2")
    assert response.status_code == 200, response.text

            

Reported by Bandit.

tests/test_tutorial/test_handling_errors/test_tutorial004.py
13 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.handling_errors.tutorial004 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",
    "info": {"title": "FastAPI", "version": "0.1.0"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 74 Column: 1

              }


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 76
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_get_validation_error():
    response = client.get("/items/foo")

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 77
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_get_validation_error():
    response = client.get("/items/foo")
    assert response.status_code == 400, response.text

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 80 Column: 1

                  assert response.json() == openapi_schema


def test_get_validation_error():
    response = client.get("/items/foo")
    assert response.status_code == 400, response.text
    validation_error_str_lines = [
        b"1 validation error for Request",
        b"path -> item_id",

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 82
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_get_validation_error():
    response = client.get("/items/foo")
    assert response.status_code == 400, response.text
    validation_error_str_lines = [
        b"1 validation error for Request",
        b"path -> item_id",
        b"  value is not a valid integer (type=type_error.integer)",
    ]

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 88
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      b"path -> item_id",
        b"  value is not a valid integer (type=type_error.integer)",
    ]
    assert response.content == b"\n".join(validation_error_str_lines)


def test_get_http_error():
    response = client.get("/items/3")
    assert response.status_code == 418, response.text

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 91 Column: 1

                  assert response.content == b"\n".join(validation_error_str_lines)


def test_get_http_error():
    response = client.get("/items/3")
    assert response.status_code == 418, response.text
    assert response.content == b"Nope! I don't like 3."



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 93
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_get_http_error():
    response = client.get("/items/3")
    assert response.status_code == 418, response.text
    assert response.content == b"Nope! I don't like 3."


def test_get():
    response = client.get("/items/2")

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 94
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_get_http_error():
    response = client.get("/items/3")
    assert response.status_code == 418, response.text
    assert response.content == b"Nope! I don't like 3."


def test_get():
    response = client.get("/items/2")
    assert response.status_code == 200, response.text

            

Reported by Bandit.

tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial007.py
13 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.path_operation_advanced_configuration.tutorial007 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",
    "info": {"title": "FastAPI", "version": "0.1.0"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 47 Column: 1

              }


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 49
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_post():
    yaml_data = """

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 50
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_post():
    yaml_data = """
        name: Deadpoolio

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 53 Column: 1

                  assert response.json() == openapi_schema


def test_post():
    yaml_data = """
        name: Deadpoolio
        tags:
        - x-force
        - x-men

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 62
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      - x-avengers
        """
    response = client.post("/items/", data=yaml_data)
    assert response.status_code == 200, response.text
    assert response.json() == {
        "name": "Deadpoolio",
        "tags": ["x-force", "x-men", "x-avengers"],
    }


            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 63
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      """
    response = client.post("/items/", data=yaml_data)
    assert response.status_code == 200, response.text
    assert response.json() == {
        "name": "Deadpoolio",
        "tags": ["x-force", "x-men", "x-avengers"],
    }



            

Reported by Bandit.

Missing function or method docstring
Error

Line: 69 Column: 1

                  }


def test_post_broken_yaml():
    yaml_data = """
        name: Deadpoolio
        tags:
        x - x-force
        x - x-men

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 78
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      x - x-avengers
        """
    response = client.post("/items/", data=yaml_data)
    assert response.status_code == 422, response.text
    assert response.json() == {"detail": "Invalid YAML"}


def test_post_invalid():
    yaml_data = """

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 79
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      """
    response = client.post("/items/", data=yaml_data)
    assert response.status_code == 422, response.text
    assert response.json() == {"detail": "Invalid YAML"}


def test_post_invalid():
    yaml_data = """
        name: Deadpoolio

            

Reported by Bandit.

tests/test_forms_from_non_typing_sequences.py
13 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi import FastAPI, Form
from fastapi.testclient import TestClient

app = FastAPI()


@app.post("/form/python-list")
def post_form_param_list(items: list = Form(...)):
    return items

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              

@app.post("/form/python-list")
def post_form_param_list(items: list = Form(...)):
    return items


@app.post("/form/python-set")
def post_form_param_set(items: set = Form(...)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

              

@app.post("/form/python-set")
def post_form_param_set(items: set = Form(...)):
    return items


@app.post("/form/python-tuple")
def post_form_param_tuple(items: tuple = Form(...)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 18 Column: 1

              

@app.post("/form/python-tuple")
def post_form_param_tuple(items: tuple = Form(...)):
    return items


client = TestClient(app)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 25 Column: 1

              client = TestClient(app)


def test_python_list_param_as_form():
    response = client.post(
        "/form/python-list", data={"items": ["first", "second", "third"]}
    )
    assert response.status_code == 200, response.text
    assert response.json() == ["first", "second", "third"]

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 29
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  response = client.post(
        "/form/python-list", data={"items": ["first", "second", "third"]}
    )
    assert response.status_code == 200, response.text
    assert response.json() == ["first", "second", "third"]


def test_python_set_param_as_form():
    response = client.post(

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 30
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      "/form/python-list", data={"items": ["first", "second", "third"]}
    )
    assert response.status_code == 200, response.text
    assert response.json() == ["first", "second", "third"]


def test_python_set_param_as_form():
    response = client.post(
        "/form/python-set", data={"items": ["first", "second", "third"]}

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 33 Column: 1

                  assert response.json() == ["first", "second", "third"]


def test_python_set_param_as_form():
    response = client.post(
        "/form/python-set", data={"items": ["first", "second", "third"]}
    )
    assert response.status_code == 200, response.text
    assert set(response.json()) == {"first", "second", "third"}

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 37
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  response = client.post(
        "/form/python-set", data={"items": ["first", "second", "third"]}
    )
    assert response.status_code == 200, response.text
    assert set(response.json()) == {"first", "second", "third"}


def test_python_tuple_param_as_form():
    response = client.post(

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 38
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      "/form/python-set", data={"items": ["first", "second", "third"]}
    )
    assert response.status_code == 200, response.text
    assert set(response.json()) == {"first", "second", "third"}


def test_python_tuple_param_as_form():
    response = client.post(
        "/form/python-tuple", data={"items": ["first", "second", "third"]}

            

Reported by Bandit.

docs_src/sql_databases/sql_app/tests/test_sql_app.py
13 issues
Unable to import 'fastapi.testclient'
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from ..database import Base
from ..main import app, get_db

SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"


            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 5 Column: 1

              from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from ..database import Base
from ..main import app, get_db

SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"

engine = create_engine(

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 6 Column: 1

              from sqlalchemy.orm import sessionmaker

from ..database import Base
from ..main import app, get_db

SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"

engine = create_engine(
    SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from ..database import Base
from ..main import app, get_db

SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

              Base.metadata.create_all(bind=engine)


def override_get_db():
    try:
        db = TestingSessionLocal()
        yield db
    finally:
        db.close()

            

Reported by Pylint.

Variable name "db" doesn't conform to snake_case naming style
Error

Line: 21 Column: 9

              
def override_get_db():
    try:
        db = TestingSessionLocal()
        yield db
    finally:
        db.close()



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 1

              client = TestClient(app)


def test_create_user():
    response = client.post(
        "/users/",
        json={"email": "deadpool@example.com", "password": "chimichangas4life"},
    )
    assert response.status_code == 200, response.text

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 37
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      "/users/",
        json={"email": "deadpool@example.com", "password": "chimichangas4life"},
    )
    assert response.status_code == 200, response.text
    data = response.json()
    assert data["email"] == "deadpool@example.com"
    assert "id" in data
    user_id = data["id"]


            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 39
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  )
    assert response.status_code == 200, response.text
    data = response.json()
    assert data["email"] == "deadpool@example.com"
    assert "id" in data
    user_id = data["id"]

    response = client.get(f"/users/{user_id}")
    assert response.status_code == 200, response.text

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 40
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  assert response.status_code == 200, response.text
    data = response.json()
    assert data["email"] == "deadpool@example.com"
    assert "id" in data
    user_id = data["id"]

    response = client.get(f"/users/{user_id}")
    assert response.status_code == 200, response.text
    data = response.json()

            

Reported by Bandit.

docs_src/async_sql_databases/tutorial001.py
13 issues
Unable to import 'databases'
Error

Line: 3 Column: 1

              from typing import List

import databases
import sqlalchemy
from fastapi import FastAPI
from pydantic import BaseModel

# SQLAlchemy specific code, as with any other app
DATABASE_URL = "sqlite:///./test.db"

            

Reported by Pylint.

Unable to import 'fastapi'
Error

Line: 5 Column: 1

              
import databases
import sqlalchemy
from fastapi import FastAPI
from pydantic import BaseModel

# SQLAlchemy specific code, as with any other app
DATABASE_URL = "sqlite:///./test.db"
# DATABASE_URL = "postgresql://user:password@postgresserver/db"

            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 6 Column: 1

              import databases
import sqlalchemy
from fastapi import FastAPI
from pydantic import BaseModel

# SQLAlchemy specific code, as with any other app
DATABASE_URL = "sqlite:///./test.db"
# DATABASE_URL = "postgresql://user:password@postgresserver/db"


            

Reported by Pylint.

No value for argument 'dml' in method call
Error

Line: 63 Column: 13

              
@app.post("/notes/", response_model=Note)
async def create_note(note: NoteIn):
    query = notes.insert().values(text=note.text, completed=note.completed)
    last_record_id = await database.execute(query)
    return {**note.dict(), "id": last_record_id}

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import List

import databases
import sqlalchemy
from fastapi import FastAPI
from pydantic import BaseModel

# SQLAlchemy specific code, as with any other app
DATABASE_URL = "sqlite:///./test.db"

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 31 Column: 1

              metadata.create_all(engine)


class NoteIn(BaseModel):
    text: str
    completed: bool


class Note(BaseModel):

            

Reported by Pylint.

Missing class docstring
Error

Line: 31 Column: 1

              metadata.create_all(engine)


class NoteIn(BaseModel):
    text: str
    completed: bool


class Note(BaseModel):

            

Reported by Pylint.

Missing class docstring
Error

Line: 36 Column: 1

                  completed: bool


class Note(BaseModel):
    id: int
    text: str
    completed: bool



            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 36 Column: 1

                  completed: bool


class Note(BaseModel):
    id: int
    text: str
    completed: bool



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 46 Column: 1

              

@app.on_event("startup")
async def startup():
    await database.connect()


@app.on_event("shutdown")
async def shutdown():

            

Reported by Pylint.

tests/test_modules_same_name_body/test_main.py
13 issues
Attempted relative import beyond top-level package
Error

Line: 3 Column: 1

              from fastapi.testclient import TestClient

from .app.main import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",
    "info": {"title": "FastAPI", "version": "0.1.0"},

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from .app.main import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",
    "info": {"title": "FastAPI", "version": "0.1.0"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 126 Column: 1

              }


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 128
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_post_a():
    data = {"a": 2, "b": "foo"}

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 129
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_post_a():
    data = {"a": 2, "b": "foo"}
    response = client.post("/a/compute", json=data)

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 132 Column: 1

                  assert response.json() == openapi_schema


def test_post_a():
    data = {"a": 2, "b": "foo"}
    response = client.post("/a/compute", json=data)
    assert response.status_code == 200, response.text
    data = response.json()


            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 135
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_post_a():
    data = {"a": 2, "b": "foo"}
    response = client.post("/a/compute", json=data)
    assert response.status_code == 200, response.text
    data = response.json()


def test_post_a_invalid():
    data = {"a": "bar", "b": "foo"}

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 139 Column: 1

                  data = response.json()


def test_post_a_invalid():
    data = {"a": "bar", "b": "foo"}
    response = client.post("/a/compute", json=data)
    assert response.status_code == 422, response.text



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 142
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_post_a_invalid():
    data = {"a": "bar", "b": "foo"}
    response = client.post("/a/compute", json=data)
    assert response.status_code == 422, response.text


def test_post_b():
    data = {"a": 2, "b": "foo"}
    response = client.post("/b/compute/", json=data)

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 145 Column: 1

                  assert response.status_code == 422, response.text


def test_post_b():
    data = {"a": 2, "b": "foo"}
    response = client.post("/b/compute/", json=data)
    assert response.status_code == 200, response.text
    data = response.json()


            

Reported by Pylint.

docs_src/app_testing/tutorial002.py
13 issues
Unable to import 'fastapi'
Error

Line: 1 Column: 1

              from fastapi import FastAPI
from fastapi.testclient import TestClient
from fastapi.websockets import WebSocket

app = FastAPI()


@app.get("/")
async def read_main():

            

Reported by Pylint.

Unable to import 'fastapi.testclient'
Error

Line: 2 Column: 1

              from fastapi import FastAPI
from fastapi.testclient import TestClient
from fastapi.websockets import WebSocket

app = FastAPI()


@app.get("/")
async def read_main():

            

Reported by Pylint.

Unable to import 'fastapi.websockets'
Error

Line: 3 Column: 1

              from fastapi import FastAPI
from fastapi.testclient import TestClient
from fastapi.websockets import WebSocket

app = FastAPI()


@app.get("/")
async def read_main():

            

Reported by Pylint.

Redefining name 'websocket' from outer scope (line 14)
Error

Line: 14 Column: 21

              

@app.websocket_route("/ws")
async def websocket(websocket: WebSocket):
    await websocket.accept()
    await websocket.send_json({"msg": "Hello WebSocket"})
    await websocket.close()



            

Reported by Pylint.

Redefining name 'websocket' from outer scope (line 14)
Error

Line: 29 Column: 45

              
def test_websocket():
    client = TestClient(app)
    with client.websocket_connect("/ws") as websocket:
        data = websocket.receive_json()
        assert data == {"msg": "Hello WebSocket"}

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi import FastAPI
from fastapi.testclient import TestClient
from fastapi.websockets import WebSocket

app = FastAPI()


@app.get("/")
async def read_main():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              

@app.get("/")
async def read_main():
    return {"msg": "Hello World"}


@app.websocket_route("/ws")
async def websocket(websocket: WebSocket):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 1

              

@app.websocket_route("/ws")
async def websocket(websocket: WebSocket):
    await websocket.accept()
    await websocket.send_json({"msg": "Hello WebSocket"})
    await websocket.close()



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

                  await websocket.close()


def test_read_main():
    client = TestClient(app)
    response = client.get("/")
    assert response.status_code == 200
    assert response.json() == {"msg": "Hello World"}


            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 23
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_read_main():
    client = TestClient(app)
    response = client.get("/")
    assert response.status_code == 200
    assert response.json() == {"msg": "Hello World"}


def test_websocket():
    client = TestClient(app)

            

Reported by Bandit.

tests/test_serialize_response.py
13 issues
Unable to import 'pydantic'
Error

Line: 5 Column: 1

              
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import List, Optional

from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()



            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 10 Column: 1

              app = FastAPI()


class Item(BaseModel):
    name: str
    price: Optional[float] = None
    owner_ids: Optional[List[int]] = None



            

Reported by Pylint.

Missing class docstring
Error

Line: 10 Column: 1

              app = FastAPI()


class Item(BaseModel):
    name: str
    price: Optional[float] = None
    owner_ids: Optional[List[int]] = None



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 1

              

@app.get("/items/valid", response_model=Item)
def get_valid():
    return {"name": "valid", "price": 1.0}


@app.get("/items/coerce", response_model=Item)
def get_coerce():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 1

              

@app.get("/items/coerce", response_model=Item)
def get_coerce():
    return {"name": "coerce", "price": "1.0"}


@app.get("/items/validlist", response_model=List[Item])
def get_validlist():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 1

              

@app.get("/items/validlist", response_model=List[Item])
def get_validlist():
    return [
        {"name": "foo"},
        {"name": "bar", "price": 1.0},
        {"name": "baz", "price": 2.0, "owner_ids": [1, 2, 3]},
    ]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 38 Column: 1

              client = TestClient(app)


def test_valid():
    response = client.get("/items/valid")
    response.raise_for_status()
    assert response.json() == {"name": "valid", "price": 1.0, "owner_ids": None}



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 41
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_valid():
    response = client.get("/items/valid")
    response.raise_for_status()
    assert response.json() == {"name": "valid", "price": 1.0, "owner_ids": None}


def test_coerce():
    response = client.get("/items/coerce")
    response.raise_for_status()

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 44 Column: 1

                  assert response.json() == {"name": "valid", "price": 1.0, "owner_ids": None}


def test_coerce():
    response = client.get("/items/coerce")
    response.raise_for_status()
    assert response.json() == {"name": "coerce", "price": 1.0, "owner_ids": None}



            

Reported by Pylint.

tests/test_tutorial/test_sub_applications/test_tutorial001.py
13 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.sub_applications.tutorial001 import app

client = TestClient(app)

openapi_schema_main = {
    "openapi": "3.0.2",
    "info": {"title": "FastAPI", "version": "0.1.0"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 46 Column: 1

              }


def test_openapi_schema_main():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema_main



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 48
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_openapi_schema_main():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema_main


def test_main():
    response = client.get("/app")

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 49
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_openapi_schema_main():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema_main


def test_main():
    response = client.get("/app")
    assert response.status_code == 200, response.text

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 52 Column: 1

                  assert response.json() == openapi_schema_main


def test_main():
    response = client.get("/app")
    assert response.status_code == 200, response.text
    assert response.json() == {"message": "Hello World from main app"}



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 54
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_main():
    response = client.get("/app")
    assert response.status_code == 200, response.text
    assert response.json() == {"message": "Hello World from main app"}


def test_openapi_schema_sub():
    response = client.get("/subapi/openapi.json")

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 55
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_main():
    response = client.get("/app")
    assert response.status_code == 200, response.text
    assert response.json() == {"message": "Hello World from main app"}


def test_openapi_schema_sub():
    response = client.get("/subapi/openapi.json")
    assert response.status_code == 200, response.text

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 58 Column: 1

                  assert response.json() == {"message": "Hello World from main app"}


def test_openapi_schema_sub():
    response = client.get("/subapi/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema_sub



            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 60
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_openapi_schema_sub():
    response = client.get("/subapi/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema_sub


def test_sub():
    response = client.get("/subapi/sub")

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 61
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_openapi_schema_sub():
    response = client.get("/subapi/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema_sub


def test_sub():
    response = client.get("/subapi/sub")
    assert response.status_code == 200, response.text

            

Reported by Bandit.