The following issues were found

tests/test_tutorial/test_dependencies/test_tutorial006.py
16 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.dependencies.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: 80 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: 82
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_no_headers():
    response = client.get("/items/")

            

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_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


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

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 86 Column: 1

                  assert response.json() == openapi_schema


def test_get_no_headers():
    response = client.get("/items/")
    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: 88
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def test_get_no_headers():
    response = client.get("/items/")
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {
                "loc": ["header", "x-token"],
                "msg": "field required",

            

Reported by Bandit.

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

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

              def test_get_no_headers():
    response = client.get("/items/")
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {
                "loc": ["header", "x-token"],
                "msg": "field required",
                "type": "value_error.missing",

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 105 Column: 1

                  }


def test_get_invalid_one_header():
    response = client.get("/items/", headers={"X-Token": "invalid"})
    assert response.status_code == 400, response.text
    assert response.json() == {"detail": "X-Token header invalid"}



            

Reported by Pylint.

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

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

              
def test_get_invalid_one_header():
    response = client.get("/items/", headers={"X-Token": "invalid"})
    assert response.status_code == 400, response.text
    assert response.json() == {"detail": "X-Token header invalid"}


def test_get_invalid_second_header():
    response = client.get(

            

Reported by Bandit.

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

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

              def test_get_invalid_one_header():
    response = client.get("/items/", headers={"X-Token": "invalid"})
    assert response.status_code == 400, response.text
    assert response.json() == {"detail": "X-Token header invalid"}


def test_get_invalid_second_header():
    response = client.get(
        "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}

            

Reported by Bandit.

tests/test_tutorial/test_testing_dependencies/test_tutorial001.py
16 issues
Missing module docstring
Error

Line: 1 Column: 1

              from docs_src.dependency_testing.tutorial001 import (
    app,
    client,
    test_override_in_items,
    test_override_in_items_with_params,
    test_override_in_items_with_q,
)



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 1

              )


def test_override_in_items_run():
    test_override_in_items()


def test_override_in_items_with_q_run():
    test_override_in_items_with_q()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 1

                  test_override_in_items()


def test_override_in_items_with_q_run():
    test_override_in_items_with_q()


def test_override_in_items_with_params_run():
    test_override_in_items_with_params()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 18 Column: 1

                  test_override_in_items_with_q()


def test_override_in_items_with_params_run():
    test_override_in_items_with_params()


def test_override_in_users():
    response = client.get("/users/")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 1

                  test_override_in_items_with_params()


def test_override_in_users():
    response = client.get("/users/")
    assert response.status_code == 200, response.text
    assert response.json() == {
        "message": "Hello Users!",
        "params": {"q": None, "skip": 5, "limit": 10},

            

Reported by Pylint.

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

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

              
def test_override_in_users():
    response = client.get("/users/")
    assert response.status_code == 200, response.text
    assert response.json() == {
        "message": "Hello Users!",
        "params": {"q": None, "skip": 5, "limit": 10},
    }


            

Reported by Bandit.

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

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

              def test_override_in_users():
    response = client.get("/users/")
    assert response.status_code == 200, response.text
    assert response.json() == {
        "message": "Hello Users!",
        "params": {"q": None, "skip": 5, "limit": 10},
    }



            

Reported by Bandit.

Missing function or method docstring
Error

Line: 31 Column: 1

                  }


def test_override_in_users_with_q():
    response = client.get("/users/?q=foo")
    assert response.status_code == 200, response.text
    assert response.json() == {
        "message": "Hello Users!",
        "params": {"q": "foo", "skip": 5, "limit": 10},

            

Reported by Pylint.

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

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

              
def test_override_in_users_with_q():
    response = client.get("/users/?q=foo")
    assert response.status_code == 200, response.text
    assert response.json() == {
        "message": "Hello Users!",
        "params": {"q": "foo", "skip": 5, "limit": 10},
    }


            

Reported by Bandit.

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

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

              def test_override_in_users_with_q():
    response = client.get("/users/?q=foo")
    assert response.status_code == 200, response.text
    assert response.json() == {
        "message": "Hello Users!",
        "params": {"q": "foo", "skip": 5, "limit": 10},
    }



            

Reported by Bandit.

docs_src/sql_databases/sql_app/alt_main.py
16 issues
Unable to import 'fastapi'
Error

Line: 3 Column: 1

              from typing import List

from fastapi import Depends, FastAPI, HTTPException, Request, Response
from sqlalchemy.orm import Session

from . import crud, models, schemas
from .database import SessionLocal, engine

models.Base.metadata.create_all(bind=engine)

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 6 Column: 1

              from fastapi import Depends, FastAPI, HTTPException, Request, Response
from sqlalchemy.orm import Session

from . import crud, models, schemas
from .database import SessionLocal, engine

models.Base.metadata.create_all(bind=engine)

app = FastAPI()

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 7 Column: 1

              from sqlalchemy.orm import Session

from . import crud, models, schemas
from .database import SessionLocal, engine

models.Base.metadata.create_all(bind=engine)

app = FastAPI()


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import List

from fastapi import Depends, FastAPI, HTTPException, Request, Response
from sqlalchemy.orm import Session

from . import crud, models, schemas
from .database import SessionLocal, engine

models.Base.metadata.create_all(bind=engine)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

              

@app.middleware("http")
async def db_session_middleware(request: Request, call_next):
    response = Response("Internal server error", status_code=500)
    try:
        request.state.db = SessionLocal()
        response = await call_next(request)
    finally:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 1

              

# Dependency
def get_db(request: Request):
    return request.state.db


@app.post("/users/", response_model=schemas.User)
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 1

              

@app.post("/users/", response_model=schemas.User)
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
    db_user = crud.get_user_by_email(db, email=user.email)
    if db_user:
        raise HTTPException(status_code=400, detail="Email already registered")
    return crud.create_user(db=db, user=user)


            

Reported by Pylint.

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

Line: 31 Column: 1

              

@app.post("/users/", response_model=schemas.User)
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
    db_user = crud.get_user_by_email(db, email=user.email)
    if db_user:
        raise HTTPException(status_code=400, detail="Email already registered")
    return crud.create_user(db=db, user=user)


            

Reported by Pylint.

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

Line: 39 Column: 1

              

@app.get("/users/", response_model=List[schemas.User])
def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    users = crud.get_users(db, skip=skip, limit=limit)
    return users


@app.get("/users/{user_id}", response_model=schemas.User)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 39 Column: 1

              

@app.get("/users/", response_model=List[schemas.User])
def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    users = crud.get_users(db, skip=skip, limit=limit)
    return users


@app.get("/users/{user_id}", response_model=schemas.User)

            

Reported by Pylint.

tests/test_request_body_parameters_media_type.py
16 issues
Unable to import 'pydantic'
Error

Line: 5 Column: 1

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

app = FastAPI()

media_type = "application/vnd.api+json"


            

Reported by Pylint.

Unused argument 'data'
Error

Line: 24 Column: 26

              

@app.post("/products")
async def create_product(data: Product = Body(..., media_type=media_type, embed=True)):
    pass  # pragma: no cover


@app.post("/shops")
async def create_shop(

            

Reported by Pylint.

Unused argument 'data'
Error

Line: 30 Column: 5

              
@app.post("/shops")
async def create_shop(
    data: Shop = Body(..., media_type=media_type),
    included: typing.List[Product] = Body([], media_type=media_type),
):
    pass  # pragma: no cover



            

Reported by Pylint.

Unused argument 'included'
Error

Line: 31 Column: 5

              @app.post("/shops")
async def create_shop(
    data: Shop = Body(..., media_type=media_type),
    included: typing.List[Product] = Body([], media_type=media_type),
):
    pass  # pragma: no cover


create_product_request_body = {

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import typing

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

app = FastAPI()

media_type = "application/vnd.api+json"

            

Reported by Pylint.

Constant name "media_type" doesn't conform to UPPER_CASE naming style
Error

Line: 9 Column: 1

              
app = FastAPI()

media_type = "application/vnd.api+json"


# NOTE: These are not valid JSON:API resources
# but they are fine for testing requestBody with custom media_type
class Product(BaseModel):

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 14 Column: 1

              
# NOTE: These are not valid JSON:API resources
# but they are fine for testing requestBody with custom media_type
class Product(BaseModel):
    name: str
    price: float


class Shop(BaseModel):

            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              
# NOTE: These are not valid JSON:API resources
# but they are fine for testing requestBody with custom media_type
class Product(BaseModel):
    name: str
    price: float


class Shop(BaseModel):

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 19 Column: 1

                  price: float


class Shop(BaseModel):
    name: str


@app.post("/products")
async def create_product(data: Product = Body(..., media_type=media_type, embed=True)):

            

Reported by Pylint.

Missing class docstring
Error

Line: 19 Column: 1

                  price: float


class Shop(BaseModel):
    name: str


@app.post("/products")
async def create_product(data: Product = Body(..., media_type=media_type, embed=True)):

            

Reported by Pylint.

docs_src/sql_databases/sql_app/main.py
16 issues
Unable to import 'fastapi'
Error

Line: 3 Column: 1

              from typing import List

from fastapi import Depends, FastAPI, HTTPException
from sqlalchemy.orm import Session

from . import crud, models, schemas
from .database import SessionLocal, engine

models.Base.metadata.create_all(bind=engine)

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 6 Column: 1

              from fastapi import Depends, FastAPI, HTTPException
from sqlalchemy.orm import Session

from . import crud, models, schemas
from .database import SessionLocal, engine

models.Base.metadata.create_all(bind=engine)

app = FastAPI()

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 7 Column: 1

              from sqlalchemy.orm import Session

from . import crud, models, schemas
from .database import SessionLocal, engine

models.Base.metadata.create_all(bind=engine)

app = FastAPI()


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import List

from fastapi import Depends, FastAPI, HTTPException
from sqlalchemy.orm import Session

from . import crud, models, schemas
from .database import SessionLocal, engine

models.Base.metadata.create_all(bind=engine)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

              

# Dependency
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

            

Reported by Pylint.

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

Line: 16 Column: 5

              
# Dependency
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()


            

Reported by Pylint.

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

Line: 24 Column: 1

              

@app.post("/users/", response_model=schemas.User)
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
    db_user = crud.get_user_by_email(db, email=user.email)
    if db_user:
        raise HTTPException(status_code=400, detail="Email already registered")
    return crud.create_user(db=db, user=user)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 1

              

@app.post("/users/", response_model=schemas.User)
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
    db_user = crud.get_user_by_email(db, email=user.email)
    if db_user:
        raise HTTPException(status_code=400, detail="Email already registered")
    return crud.create_user(db=db, user=user)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 1

              

@app.get("/users/", response_model=List[schemas.User])
def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    users = crud.get_users(db, skip=skip, limit=limit)
    return users


@app.get("/users/{user_id}", response_model=schemas.User)

            

Reported by Pylint.

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

Line: 32 Column: 1

              

@app.get("/users/", response_model=List[schemas.User])
def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    users = crud.get_users(db, skip=skip, limit=limit)
    return users


@app.get("/users/{user_id}", response_model=schemas.User)

            

Reported by Pylint.

tests/test_additional_responses_custom_validationerror.py
16 issues
Unable to import 'pydantic'
Error

Line: 6 Column: 1

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

app = FastAPI()


class JsonApiResponse(JSONResponse):

            

Reported by Pylint.

Unused argument 'id'
Error

Line: 29 Column: 13

                  response_class=JsonApiResponse,
    responses={422: {"description": "Error", "model": JsonApiError}},
)
async def a(id):
    pass  # pragma: no cover


openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Redefining built-in 'id'
Error

Line: 29 Column: 13

                  response_class=JsonApiResponse,
    responses={422: {"description": "Error", "model": JsonApiError}},
)
async def a(id):
    pass  # pragma: no cover


openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import typing

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

app = FastAPI()


            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 11 Column: 1

              app = FastAPI()


class JsonApiResponse(JSONResponse):
    media_type = "application/vnd.api+json"


class Error(BaseModel):
    status: str

            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              app = FastAPI()


class JsonApiResponse(JSONResponse):
    media_type = "application/vnd.api+json"


class Error(BaseModel):
    status: str

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

                  media_type = "application/vnd.api+json"


class Error(BaseModel):
    status: str
    title: str


class JsonApiError(BaseModel):

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 15 Column: 1

                  media_type = "application/vnd.api+json"


class Error(BaseModel):
    status: str
    title: str


class JsonApiError(BaseModel):

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 20 Column: 1

                  title: str


class JsonApiError(BaseModel):
    errors: typing.List[Error]


@app.get(
    "/a/{id}",

            

Reported by Pylint.

Missing class docstring
Error

Line: 20 Column: 1

                  title: str


class JsonApiError(BaseModel):
    errors: typing.List[Error]


@app.get(
    "/a/{id}",

            

Reported by Pylint.

tests/test_duplicate_models_openapi.py
16 issues
Unable to import 'pydantic'
Error

Line: 3 Column: 1

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

app = FastAPI()


class Model(BaseModel):
    pass

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

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

app = FastAPI()


class Model(BaseModel):
    pass

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              app = FastAPI()


class Model(BaseModel):
    pass


class Model2(BaseModel):
    a: Model

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 8 Column: 1

              app = FastAPI()


class Model(BaseModel):
    pass


class Model2(BaseModel):
    a: Model

            

Reported by Pylint.

Missing class docstring
Error

Line: 12 Column: 1

                  pass


class Model2(BaseModel):
    a: Model


class Model3(BaseModel):
    c: Model

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 12 Column: 1

                  pass


class Model2(BaseModel):
    a: Model


class Model3(BaseModel):
    c: Model

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 16 Column: 1

                  a: Model


class Model3(BaseModel):
    c: Model
    d: Model2


@app.get("/", response_model=Model3)

            

Reported by Pylint.

Missing class docstring
Error

Line: 16 Column: 1

                  a: Model


class Model3(BaseModel):
    c: Model
    d: Model2


@app.get("/", response_model=Model3)

            

Reported by Pylint.

Function name "f" doesn't conform to snake_case naming style
Error

Line: 22 Column: 1

              

@app.get("/", response_model=Model3)
def f():
    return {"c": {}, "d": {"a": {}}}


openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 1

              

@app.get("/", response_model=Model3)
def f():
    return {"c": {}, "d": {"a": {}}}


openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

tests/test_response_model_sub_types.py
16 issues
Unable to import 'pydantic'
Error

Line: 5 Column: 1

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


class Model(BaseModel):
    name: str


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import List

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


class Model(BaseModel):
    name: str

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              from pydantic import BaseModel


class Model(BaseModel):
    name: str


app = FastAPI()


            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 8 Column: 1

              from pydantic import BaseModel


class Model(BaseModel):
    name: str


app = FastAPI()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

              

@app.get("/valid1", responses={"500": {"model": int}})
def valid1():
    pass


@app.get("/valid2", responses={"500": {"model": List[int]}})
def valid2():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 21 Column: 1

              

@app.get("/valid2", responses={"500": {"model": List[int]}})
def valid2():
    pass


@app.get("/valid3", responses={"500": {"model": Model}})
def valid3():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 1

              

@app.get("/valid3", responses={"500": {"model": Model}})
def valid3():
    pass


@app.get("/valid4", responses={"500": {"model": List[Model]}})
def valid4():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 1

              

@app.get("/valid4", responses={"500": {"model": List[Model]}})
def valid4():
    pass


openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 146 Column: 1

              client = TestClient(app)


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: 148
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_path_operations():
    response = client.get("/valid1")

            

Reported by Bandit.

tests/test_security_api_key_cookie.py
15 issues
Unable to import 'pydantic'
Error

Line: 4 Column: 1

              from fastapi import Depends, FastAPI, Security
from fastapi.security import APIKeyCookie
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()

api_key = APIKeyCookie(name="key")


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi import Depends, FastAPI, Security
from fastapi.security import APIKeyCookie
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()

api_key = APIKeyCookie(name="key")


            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 11 Column: 1

              api_key = APIKeyCookie(name="key")


class User(BaseModel):
    username: str


def get_current_user(oauth_header: str = Security(api_key)):
    user = User(username=oauth_header)

            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              api_key = APIKeyCookie(name="key")


class User(BaseModel):
    username: str


def get_current_user(oauth_header: str = Security(api_key)):
    user = User(username=oauth_header)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

                  username: str


def get_current_user(oauth_header: str = Security(api_key)):
    user = User(username=oauth_header)
    return user


@app.get("/users/me")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 21 Column: 1

              

@app.get("/users/me")
def read_current_user(current_user: User = Depends(get_current_user)):
    return current_user


client = TestClient(app)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 53 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: 55
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_security_api_key():
    response = client.get("/users/me", cookies={"key": "secret"})

            

Reported by Bandit.

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

Line: 56
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_security_api_key():
    response = client.get("/users/me", cookies={"key": "secret"})
    assert response.status_code == 200, response.text

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 59 Column: 1

                  assert response.json() == openapi_schema


def test_security_api_key():
    response = client.get("/users/me", cookies={"key": "secret"})
    assert response.status_code == 200, response.text
    assert response.json() == {"username": "secret"}



            

Reported by Pylint.

tests/test_response_class_no_mediatype.py
15 issues
Unable to import 'pydantic'
Error

Line: 6 Column: 1

              from fastapi import FastAPI, Response
from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()


class JsonApiResponse(JSONResponse):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import typing

from fastapi import FastAPI, Response
from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()


            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 11 Column: 1

              app = FastAPI()


class JsonApiResponse(JSONResponse):
    media_type = "application/vnd.api+json"


class Error(BaseModel):
    status: str

            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              app = FastAPI()


class JsonApiResponse(JSONResponse):
    media_type = "application/vnd.api+json"


class Error(BaseModel):
    status: str

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

                  media_type = "application/vnd.api+json"


class Error(BaseModel):
    status: str
    title: str


class JsonApiError(BaseModel):

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 15 Column: 1

                  media_type = "application/vnd.api+json"


class Error(BaseModel):
    status: str
    title: str


class JsonApiError(BaseModel):

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 20 Column: 1

                  title: str


class JsonApiError(BaseModel):
    errors: typing.List[Error]


@app.get(
    "/a",

            

Reported by Pylint.

Missing class docstring
Error

Line: 20 Column: 1

                  title: str


class JsonApiError(BaseModel):
    errors: typing.List[Error]


@app.get(
    "/a",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 1

                  "/a",
    response_class=Response,
    responses={500: {"description": "Error", "model": JsonApiError}},
)
async def a():
    pass  # pragma: no cover


@app.get("/b", responses={500: {"description": "Error", "model": Error}})

            

Reported by Pylint.

Function name "a" doesn't conform to snake_case naming style
Error

Line: 28 Column: 1

                  "/a",
    response_class=Response,
    responses={500: {"description": "Error", "model": JsonApiError}},
)
async def a():
    pass  # pragma: no cover


@app.get("/b", responses={500: {"description": "Error", "model": Error}})

            

Reported by Pylint.