The following issues were found

tests/test_filter_pydantic_sub_model.py
24 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              from typing import Optional

import pytest
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, ValidationError, validator

app = FastAPI()


            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 6 Column: 1

              import pytest
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, ValidationError, validator

app = FastAPI()


class ModelB(BaseModel):

            

Reported by Pylint.

Method should have "self" as first argument
Error

Line: 25 Column: 5

                  model_b: ModelB

    @validator("name")
    def lower_username(cls, name: str, values):
        if not name.endswith("A"):
            raise ValueError("name must end in A")
        return name



            

Reported by Pylint.

Unused argument 'values'
Error

Line: 25 Column: 40

                  model_b: ModelB

    @validator("name")
    def lower_username(cls, name: str, values):
        if not name.endswith("A"):
            raise ValueError("name must end in A")
        return name



            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional

import pytest
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, ValidationError, validator

app = FastAPI()


            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 11 Column: 1

              app = FastAPI()


class ModelB(BaseModel):
    username: str


class ModelC(ModelB):
    password: str

            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              app = FastAPI()


class ModelB(BaseModel):
    username: str


class ModelC(ModelB):
    password: str

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 15 Column: 1

                  username: str


class ModelC(ModelB):
    password: str


class ModelA(BaseModel):
    name: str

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

                  username: str


class ModelC(ModelB):
    password: str


class ModelA(BaseModel):
    name: str

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 19 Column: 1

                  password: str


class ModelA(BaseModel):
    name: str
    description: Optional[str] = None
    model_b: ModelB

    @validator("name")

            

Reported by Pylint.

fastapi/security/oauth2.py
23 issues
Unable to import 'starlette.requests'
Error

Line: 9 Column: 1

              from fastapi.param_functions import Form
from fastapi.security.base import SecurityBase
from fastapi.security.utils import get_authorization_scheme_param
from starlette.requests import Request
from starlette.status import HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN


class OAuth2PasswordRequestForm:
    """

            

Reported by Pylint.

Unable to import 'starlette.status'
Error

Line: 10 Column: 1

              from fastapi.security.base import SecurityBase
from fastapi.security.utils import get_authorization_scheme_param
from starlette.requests import Request
from starlette.status import HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN


class OAuth2PasswordRequestForm:
    """
    This is a dependency class, use it like:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Any, Dict, List, Optional, Union

from fastapi.exceptions import HTTPException
from fastapi.openapi.models import OAuth2 as OAuth2Model
from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
from fastapi.param_functions import Form
from fastapi.security.base import SecurityBase
from fastapi.security.utils import get_authorization_scheme_param
from starlette.requests import Request

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 13 Column: 1

              from starlette.status import HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN


class OAuth2PasswordRequestForm:
    """
    This is a dependency class, use it like:

        @app.post("/login")
        def login(form_data: OAuth2PasswordRequestForm = Depends()):

            

Reported by Pylint.

Line too long (111/100)
Error

Line: 34 Column: 1

                  It creates the following Form request parameters in your endpoint:

    grant_type: the OAuth2 spec says it is required and MUST be the fixed string "password".
        Nevertheless, this dependency class is permissive and allows not passing it. If you want to enforce it,
        use instead the OAuth2PasswordRequestFormStrict dependency.
    username: username string. The OAuth2 spec requires the exact field name "username".
    password: password string. The OAuth2 spec requires the exact field name "password".
    scope: Optional string. Several scopes (each one a string) separated by spaces. E.g.
        "items:read items:write users:read profile openid"

            

Reported by Pylint.

Line too long (102/100)
Error

Line: 42 Column: 1

                      "items:read items:write users:read profile openid"
    client_id: optional string. OAuth2 recommends sending the client_id and client_secret (if any)
        using HTTP Basic auth, as: client_id:client_secret
    client_secret: optional string. OAuth2 recommends sending the client_id and client_secret (if any)
        using HTTP Basic auth, as: client_id:client_secret
    """

    def __init__(
        self,

            

Reported by Pylint.

Too many arguments (7/5)
Error

Line: 46 Column: 5

                      using HTTP Basic auth, as: client_id:client_secret
    """

    def __init__(
        self,
        grant_type: str = Form(None, regex="password"),
        username: str = Form(...),
        password: str = Form(...),
        scope: str = Form(""),

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 63 Column: 1

                      self.client_secret = client_secret


class OAuth2PasswordRequestFormStrict(OAuth2PasswordRequestForm):
    """
    This is a dependency class, use it like:

        @app.post("/login")
        def login(form_data: OAuth2PasswordRequestFormStrict = Depends()):

            

Reported by Pylint.

Line too long (102/100)
Error

Line: 92 Column: 1

                      "items:read items:write users:read profile openid"
    client_id: optional string. OAuth2 recommends sending the client_id and client_secret (if any)
        using HTTP Basic auth, as: client_id:client_secret
    client_secret: optional string. OAuth2 recommends sending the client_id and client_secret (if any)
        using HTTP Basic auth, as: client_id:client_secret
    """

    def __init__(
        self,

            

Reported by Pylint.

Too many arguments (7/5)
Error

Line: 96 Column: 5

                      using HTTP Basic auth, as: client_id:client_secret
    """

    def __init__(
        self,
        grant_type: str = Form(..., regex="password"),
        username: str = Form(...),
        password: str = Form(...),
        scope: str = Form(""),

            

Reported by Pylint.

docs_src/sql_databases_peewee/sql_app/schemas.py
23 issues
Unable to import 'peewee'
Error

Line: 3 Column: 1

              from typing import Any, List, Optional

import peewee
from pydantic import BaseModel
from pydantic.utils import GetterDict


class PeeweeGetterDict(GetterDict):
    def get(self, key: Any, default: Any = None):

            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 4 Column: 1

              from typing import Any, List, Optional

import peewee
from pydantic import BaseModel
from pydantic.utils import GetterDict


class PeeweeGetterDict(GetterDict):
    def get(self, key: Any, default: Any = None):

            

Reported by Pylint.

Unable to import 'pydantic.utils'
Error

Line: 5 Column: 1

              
import peewee
from pydantic import BaseModel
from pydantic.utils import GetterDict


class PeeweeGetterDict(GetterDict):
    def get(self, key: Any, default: Any = None):
        res = getattr(self._obj, key, default)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Any, List, Optional

import peewee
from pydantic import BaseModel
from pydantic.utils import GetterDict


class PeeweeGetterDict(GetterDict):
    def get(self, key: Any, default: Any = None):

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              from pydantic.utils import GetterDict


class PeeweeGetterDict(GetterDict):
    def get(self, key: Any, default: Any = None):
        res = getattr(self._obj, key, default)
        if isinstance(res, peewee.ModelSelect):
            return list(res)
        return res

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 8 Column: 1

              from pydantic.utils import GetterDict


class PeeweeGetterDict(GetterDict):
    def get(self, key: Any, default: Any = None):
        res = getattr(self._obj, key, default)
        if isinstance(res, peewee.ModelSelect):
            return list(res)
        return res

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 5

              

class PeeweeGetterDict(GetterDict):
    def get(self, key: Any, default: Any = None):
        res = getattr(self._obj, key, default)
        if isinstance(res, peewee.ModelSelect):
            return list(res)
        return res


            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 16 Column: 1

                      return res


class ItemBase(BaseModel):
    title: str
    description: Optional[str] = None


class ItemCreate(ItemBase):

            

Reported by Pylint.

Missing class docstring
Error

Line: 16 Column: 1

                      return res


class ItemBase(BaseModel):
    title: str
    description: Optional[str] = None


class ItemCreate(ItemBase):

            

Reported by Pylint.

Missing class docstring
Error

Line: 21 Column: 1

                  description: Optional[str] = None


class ItemCreate(ItemBase):
    pass


class Item(ItemBase):
    id: int

            

Reported by Pylint.

tests/test_tutorial/test_bigger_applications/test_main.py
23 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest
from fastapi.testclient import TestClient

from docs_src.bigger_applications.app.main import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest
from fastapi.testclient import TestClient

from docs_src.bigger_applications.app.main import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 431 Column: 1

                      ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}),
        ("/", 422, no_jessica, {}),
        ("/openapi.json", 200, openapi_schema, {}),
    ],
)
def test_get_path(path, expected_status, expected_response, headers):
    response = client.get(path, headers=headers)
    assert response.status_code == expected_status
    assert response.json() == expected_response

            

Reported by Pylint.

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

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

              )
def test_get_path(path, expected_status, expected_response, headers):
    response = client.get(path, headers=headers)
    assert response.status_code == expected_status
    assert response.json() == expected_response


def test_put_no_header():
    response = client.put("/items/foo")

            

Reported by Bandit.

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

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

              def test_get_path(path, expected_status, expected_response, headers):
    response = client.get(path, headers=headers)
    assert response.status_code == expected_status
    assert response.json() == expected_response


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

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 439 Column: 1

                  assert response.json() == expected_response


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

              
def test_put_no_header():
    response = client.put("/items/foo")
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {
                "loc": ["query", "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: 442
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_put_no_header():
    response = client.put("/items/foo")
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {
                "loc": ["query", "token"],
                "msg": "field required",
                "type": "value_error.missing",

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 458 Column: 1

                  }


def test_put_invalid_header():
    response = client.put("/items/foo", 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: 460
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

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


def test_put():
    response = client.put(

            

Reported by Bandit.

tests/test_security_oauth2_optional.py
23 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              from typing import Optional

import pytest
from fastapi import Depends, FastAPI, Security
from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()

            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 7 Column: 1

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

app = FastAPI()

reusable_oauth2 = OAuth2(
    flows={

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional

import pytest
from fastapi import Depends, FastAPI, Security
from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 22 Column: 1

              )


class User(BaseModel):
    username: str


def get_current_user(oauth_header: Optional[str] = Security(reusable_oauth2)):
    if oauth_header is None:

            

Reported by Pylint.

Missing class docstring
Error

Line: 22 Column: 1

              )


class User(BaseModel):
    username: str


def get_current_user(oauth_header: Optional[str] = Security(reusable_oauth2)):
    if oauth_header is None:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 1

                  username: str


def get_current_user(oauth_header: Optional[str] = Security(reusable_oauth2)):
    if oauth_header is None:
        return None
    user = User(username=oauth_header)
    return user


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 34 Column: 1

              

@app.post("/login")
def login(form_data: OAuth2PasswordRequestFormStrict = Depends()):
    return form_data


@app.get("/users/me")
def read_users_me(current_user: Optional[User] = Depends(get_current_user)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 39 Column: 1

              

@app.get("/users/me")
def read_users_me(current_user: Optional[User] = Depends(get_current_user)):
    if current_user is None:
        return {"msg": "Create an account first"}
    return current_user



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 160 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: 162
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_oauth2():
    response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"})

            

Reported by Bandit.

tests/test_tutorial/test_request_files/test_tutorial001.py
23 issues
Redefining name 'client' from outer scope (line 5)
Error

Line: 157 Column: 5

                  path = tmp_path / "test.txt"
    path.write_bytes(b"<file content>")

    client = TestClient(app)
    with path.open("rb") as file:
        response = client.post("/files/", files={"file": file})
    assert response.status_code == 200, response.text
    assert response.json() == {"file_size": 14}


            

Reported by Pylint.

Redefining name 'client' from outer scope (line 5)
Error

Line: 169 Column: 5

                  path = tmp_path / "test.txt"
    path.write_bytes(b"x" * (default_pydantic_max_size + 1))

    client = TestClient(app)
    with path.open("rb") as file:
        response = client.post("/files/", files={"file": file})
    assert response.status_code == 200, response.text
    assert response.json() == {"file_size": default_pydantic_max_size + 1}


            

Reported by Pylint.

Redefining name 'client' from outer scope (line 5)
Error

Line: 180 Column: 5

                  path = tmp_path / "test.txt"
    path.write_bytes(b"<file content>")

    client = TestClient(app)
    with path.open("rb") as file:
        response = client.post("/uploadfile/", files={"file": file})
    assert response.status_code == 200, response.text
    assert response.json() == {"filename": "test.txt"}

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.request_files.tutorial001 import app

client = TestClient(app)

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

            

Reported by Pylint.

Line too long (103/100)
Error

Line: 67 Column: 1

                                  "content": {
                        "multipart/form-data": {
                            "schema": {
                                "$ref": "#/components/schemas/Body_create_upload_file_uploadfile__post"
                            }
                        }
                    },
                    "required": True,
                },

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 124 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: 126
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


file_required = {
    "detail": [

            

Reported by Bandit.

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

Line: 127
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


file_required = {
    "detail": [
        {

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 141 Column: 1

              }


def test_post_form_no_body():
    response = client.post("/files/")
    assert response.status_code == 422, response.text
    assert response.json() == file_required



            

Reported by Pylint.

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

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

              
def test_post_form_no_body():
    response = client.post("/files/")
    assert response.status_code == 422, response.text
    assert response.json() == file_required


def test_post_body_json():
    response = client.post("/files/", json={"file": "Foo"})

            

Reported by Bandit.

tests/test_tutorial/test_request_files/test_tutorial002.py
23 issues
Redefining name 'client' from outer scope (line 5)
Error

Line: 179 Column: 5

                  path2 = tmp_path / "test2.txt"
    path2.write_bytes(b"<file content2>")

    client = TestClient(app)
    with path.open("rb") as file, path2.open("rb") as file2:
        response = client.post(
            "/files/",
            files=(
                ("files", ("test.txt", file)),

            

Reported by Pylint.

Redefining name 'client' from outer scope (line 5)
Error

Line: 198 Column: 5

                  path2 = tmp_path / "test2.txt"
    path2.write_bytes(b"<file content2>")

    client = TestClient(app)
    with path.open("rb") as file, path2.open("rb") as file2:
        response = client.post(
            "/uploadfiles/",
            files=(
                ("files", ("test.txt", file)),

            

Reported by Pylint.

Redefining name 'client' from outer scope (line 5)
Error

Line: 212 Column: 5

              

def test_get_root():
    client = TestClient(app)
    response = client.get("/")
    assert response.status_code == 200, response.text
    assert b"<form" in response.content

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.request_files.tutorial002 import app

client = TestClient(app)

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

            

Reported by Pylint.

Line too long (105/100)
Error

Line: 67 Column: 1

                                  "content": {
                        "multipart/form-data": {
                            "schema": {
                                "$ref": "#/components/schemas/Body_create_upload_files_uploadfiles__post"
                            }
                        }
                    },
                    "required": True,
                },

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 144 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: 146
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


file_required = {
    "detail": [

            

Reported by Bandit.

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

Line: 147
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


file_required = {
    "detail": [
        {

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 161 Column: 1

              }


def test_post_form_no_body():
    response = client.post("/files/")
    assert response.status_code == 422, response.text
    assert response.json() == file_required



            

Reported by Pylint.

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

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

              
def test_post_form_no_body():
    response = client.post("/files/")
    assert response.status_code == 422, response.text
    assert response.json() == file_required


def test_post_body_json():
    response = client.post("/files/", json={"file": "Foo"})

            

Reported by Bandit.

tests/test_security_oauth2_optional_description.py
23 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              from typing import Optional

import pytest
from fastapi import Depends, FastAPI, Security
from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()

            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 7 Column: 1

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

app = FastAPI()

reusable_oauth2 = OAuth2(
    flows={

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional

import pytest
from fastapi import Depends, FastAPI, Security
from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()

            

Reported by Pylint.

Missing class docstring
Error

Line: 23 Column: 1

              )


class User(BaseModel):
    username: str


def get_current_user(oauth_header: Optional[str] = Security(reusable_oauth2)):
    if oauth_header is None:

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 23 Column: 1

              )


class User(BaseModel):
    username: str


def get_current_user(oauth_header: Optional[str] = Security(reusable_oauth2)):
    if oauth_header is None:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 1

                  username: str


def get_current_user(oauth_header: Optional[str] = Security(reusable_oauth2)):
    if oauth_header is None:
        return None
    user = User(username=oauth_header)
    return user


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 35 Column: 1

              

@app.post("/login")
def login(form_data: OAuth2PasswordRequestFormStrict = Depends()):
    return form_data


@app.get("/users/me")
def read_users_me(current_user: Optional[User] = Depends(get_current_user)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 40 Column: 1

              

@app.get("/users/me")
def read_users_me(current_user: Optional[User] = Depends(get_current_user)):
    if current_user is None:
        return {"msg": "Create an account first"}
    return current_user



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 162 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: 164
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_oauth2():
    response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"})

            

Reported by Bandit.

tests/test_tutorial/test_extending_openapi/test_tutorial002.py
22 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              import os
from pathlib import Path

import pytest
from fastapi.testclient import TestClient


@pytest.fixture(scope="module")
def client():

            

Reported by Pylint.

Redefining name 'client' from outer scope (line 9)
Error

Line: 15 Column: 29

                  static_dir.mkdir(exist_ok=True)
    from docs_src.extending_openapi.tutorial002 import app

    with TestClient(app) as client:
        yield client
    static_dir.rmdir()


def test_swagger_ui_html(client: TestClient):

            

Reported by Pylint.

Redefining name 'client' from outer scope (line 9)
Error

Line: 20 Column: 26

                  static_dir.rmdir()


def test_swagger_ui_html(client: TestClient):
    response = client.get("/docs")
    assert response.status_code == 200, response.text
    assert "/static/swagger-ui-bundle.js" in response.text
    assert "/static/swagger-ui.css" in response.text


            

Reported by Pylint.

Redefining name 'client' from outer scope (line 9)
Error

Line: 27 Column: 42

                  assert "/static/swagger-ui.css" in response.text


def test_swagger_ui_oauth2_redirect_html(client: TestClient):
    response = client.get("/docs/oauth2-redirect")
    assert response.status_code == 200, response.text
    assert "window.opener.swaggerUIRedirectOauth2" in response.text



            

Reported by Pylint.

Redefining name 'client' from outer scope (line 9)
Error

Line: 33 Column: 21

                  assert "window.opener.swaggerUIRedirectOauth2" in response.text


def test_redoc_html(client: TestClient):
    response = client.get("/redoc")
    assert response.status_code == 200, response.text
    assert "/static/redoc.standalone.js" in response.text



            

Reported by Pylint.

Redefining name 'client' from outer scope (line 9)
Error

Line: 39 Column: 14

                  assert "/static/redoc.standalone.js" in response.text


def test_api(client: TestClient):
    response = client.get("/users/john")
    assert response.status_code == 200, response.text
    assert response.json()["message"] == "Hello john"

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import os
from pathlib import Path

import pytest
from fastapi.testclient import TestClient


@pytest.fixture(scope="module")
def client():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              

@pytest.fixture(scope="module")
def client():
    static_dir: Path = Path(os.getcwd()) / "static"
    print(static_dir)
    static_dir.mkdir(exist_ok=True)
    from docs_src.extending_openapi.tutorial002 import app


            

Reported by Pylint.

Import outside toplevel (docs_src.extending_openapi.tutorial002.app)
Error

Line: 13 Column: 5

                  static_dir: Path = Path(os.getcwd()) / "static"
    print(static_dir)
    static_dir.mkdir(exist_ok=True)
    from docs_src.extending_openapi.tutorial002 import app

    with TestClient(app) as client:
        yield client
    static_dir.rmdir()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

                  static_dir.rmdir()


def test_swagger_ui_html(client: TestClient):
    response = client.get("/docs")
    assert response.status_code == 200, response.text
    assert "/static/swagger-ui-bundle.js" in response.text
    assert "/static/swagger-ui.css" in response.text


            

Reported by Pylint.

docs_src/app_testing/test_main_b.py
21 issues
Unable to import 'fastapi.testclient'
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from .main_b import app

client = TestClient(app)


def test_read_item():
    response = client.get("/items/foo", headers={"X-Token": "coneofsilence"})

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 3 Column: 1

              from fastapi.testclient import TestClient

from .main_b import app

client = TestClient(app)


def test_read_item():
    response = client.get("/items/foo", headers={"X-Token": "coneofsilence"})

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from .main_b import app

client = TestClient(app)


def test_read_item():
    response = client.get("/items/foo", headers={"X-Token": "coneofsilence"})

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              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",

            

Reported by Pylint.

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

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

              
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",
    }

            

Reported by Bandit.

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

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

              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",
    }


            

Reported by Bandit.

Missing function or method docstring
Error

Line: 18 Column: 1

                  }


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"}



            

Reported by Pylint.

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

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

              
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_inexistent_item():
    response = client.get("/items/baz", headers={"X-Token": "coneofsilence"})

            

Reported by Bandit.

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

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

              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_inexistent_item():
    response = client.get("/items/baz", headers={"X-Token": "coneofsilence"})
    assert response.status_code == 404

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 24 Column: 1

                  assert response.json() == {"detail": "Invalid X-Token header"}


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



            

Reported by Pylint.