The following issues were found
fastapi/responses.py
31 issues
Line: 3
Column: 1
from typing import Any
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
Reported by Pylint.
Line: 4
Column: 1
from typing import Any
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
Reported by Pylint.
Line: 5
Column: 1
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
Reported by Pylint.
Line: 6
Column: 1
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
try:
Reported by Pylint.
Line: 7
Column: 1
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
try:
import ujson
Reported by Pylint.
Line: 8
Column: 1
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
try:
import ujson
except ImportError: # pragma: nocover
Reported by Pylint.
Line: 9
Column: 1
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
try:
import ujson
except ImportError: # pragma: nocover
ujson = None # type: ignore
Reported by Pylint.
Line: 3
Column: 1
from typing import Any
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
Reported by Pylint.
Line: 4
Column: 1
from typing import Any
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
Reported by Pylint.
Line: 6
Column: 1
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
try:
Reported by Pylint.
tests/test_tutorial/test_security/test_tutorial003.py
31 issues
Line: 1
Column: 1
from fastapi.testclient import TestClient
from docs_src.security.tutorial003 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
Reported by Pylint.
Line: 112
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.
Line: 114
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_login():
response = client.post("/token", data={"username": "johndoe", "password": "secret"})
Reported by Bandit.
Line: 115
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_login():
response = client.post("/token", data={"username": "johndoe", "password": "secret"})
assert response.status_code == 200, response.text
Reported by Bandit.
Line: 118
Column: 1
assert response.json() == openapi_schema
def test_login():
response = client.post("/token", data={"username": "johndoe", "password": "secret"})
assert response.status_code == 200, response.text
assert response.json() == {"access_token": "johndoe", "token_type": "bearer"}
Reported by Pylint.
Line: 120
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_login():
response = client.post("/token", data={"username": "johndoe", "password": "secret"})
assert response.status_code == 200, response.text
assert response.json() == {"access_token": "johndoe", "token_type": "bearer"}
def test_login_incorrect_password():
response = client.post(
Reported by Bandit.
Line: 121
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_login():
response = client.post("/token", data={"username": "johndoe", "password": "secret"})
assert response.status_code == 200, response.text
assert response.json() == {"access_token": "johndoe", "token_type": "bearer"}
def test_login_incorrect_password():
response = client.post(
"/token", data={"username": "johndoe", "password": "incorrect"}
Reported by Bandit.
Line: 124
Column: 1
assert response.json() == {"access_token": "johndoe", "token_type": "bearer"}
def test_login_incorrect_password():
response = client.post(
"/token", data={"username": "johndoe", "password": "incorrect"}
)
assert response.status_code == 400, response.text
assert response.json() == {"detail": "Incorrect username or password"}
Reported by Pylint.
Line: 128
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
response = client.post(
"/token", data={"username": "johndoe", "password": "incorrect"}
)
assert response.status_code == 400, response.text
assert response.json() == {"detail": "Incorrect username or password"}
def test_login_incorrect_username():
response = client.post("/token", data={"username": "foo", "password": "secret"})
Reported by Bandit.
Line: 129
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
"/token", data={"username": "johndoe", "password": "incorrect"}
)
assert response.status_code == 400, response.text
assert response.json() == {"detail": "Incorrect username or password"}
def test_login_incorrect_username():
response = client.post("/token", data={"username": "foo", "password": "secret"})
assert response.status_code == 400, response.text
Reported by Bandit.
fastapi/security/__init__.py
31 issues
Line: 1
Column: 1
from .api_key import APIKeyCookie as APIKeyCookie
from .api_key import APIKeyHeader as APIKeyHeader
from .api_key import APIKeyQuery as APIKeyQuery
from .http import HTTPAuthorizationCredentials as HTTPAuthorizationCredentials
from .http import HTTPBasic as HTTPBasic
from .http import HTTPBasicCredentials as HTTPBasicCredentials
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
Reported by Pylint.
Line: 2
Column: 1
from .api_key import APIKeyCookie as APIKeyCookie
from .api_key import APIKeyHeader as APIKeyHeader
from .api_key import APIKeyQuery as APIKeyQuery
from .http import HTTPAuthorizationCredentials as HTTPAuthorizationCredentials
from .http import HTTPBasic as HTTPBasic
from .http import HTTPBasicCredentials as HTTPBasicCredentials
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
Reported by Pylint.
Line: 3
Column: 1
from .api_key import APIKeyCookie as APIKeyCookie
from .api_key import APIKeyHeader as APIKeyHeader
from .api_key import APIKeyQuery as APIKeyQuery
from .http import HTTPAuthorizationCredentials as HTTPAuthorizationCredentials
from .http import HTTPBasic as HTTPBasic
from .http import HTTPBasicCredentials as HTTPBasicCredentials
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
Reported by Pylint.
Line: 4
Column: 1
from .api_key import APIKeyCookie as APIKeyCookie
from .api_key import APIKeyHeader as APIKeyHeader
from .api_key import APIKeyQuery as APIKeyQuery
from .http import HTTPAuthorizationCredentials as HTTPAuthorizationCredentials
from .http import HTTPBasic as HTTPBasic
from .http import HTTPBasicCredentials as HTTPBasicCredentials
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
Reported by Pylint.
Line: 5
Column: 1
from .api_key import APIKeyHeader as APIKeyHeader
from .api_key import APIKeyQuery as APIKeyQuery
from .http import HTTPAuthorizationCredentials as HTTPAuthorizationCredentials
from .http import HTTPBasic as HTTPBasic
from .http import HTTPBasicCredentials as HTTPBasicCredentials
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
from .oauth2 import OAuth2AuthorizationCodeBearer as OAuth2AuthorizationCodeBearer
Reported by Pylint.
Line: 6
Column: 1
from .api_key import APIKeyQuery as APIKeyQuery
from .http import HTTPAuthorizationCredentials as HTTPAuthorizationCredentials
from .http import HTTPBasic as HTTPBasic
from .http import HTTPBasicCredentials as HTTPBasicCredentials
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
from .oauth2 import OAuth2AuthorizationCodeBearer as OAuth2AuthorizationCodeBearer
from .oauth2 import OAuth2PasswordBearer as OAuth2PasswordBearer
Reported by Pylint.
Line: 7
Column: 1
from .http import HTTPAuthorizationCredentials as HTTPAuthorizationCredentials
from .http import HTTPBasic as HTTPBasic
from .http import HTTPBasicCredentials as HTTPBasicCredentials
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
from .oauth2 import OAuth2AuthorizationCodeBearer as OAuth2AuthorizationCodeBearer
from .oauth2 import OAuth2PasswordBearer as OAuth2PasswordBearer
from .oauth2 import OAuth2PasswordRequestForm as OAuth2PasswordRequestForm
Reported by Pylint.
Line: 8
Column: 1
from .http import HTTPBasic as HTTPBasic
from .http import HTTPBasicCredentials as HTTPBasicCredentials
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
from .oauth2 import OAuth2AuthorizationCodeBearer as OAuth2AuthorizationCodeBearer
from .oauth2 import OAuth2PasswordBearer as OAuth2PasswordBearer
from .oauth2 import OAuth2PasswordRequestForm as OAuth2PasswordRequestForm
from .oauth2 import OAuth2PasswordRequestFormStrict as OAuth2PasswordRequestFormStrict
Reported by Pylint.
Line: 9
Column: 1
from .http import HTTPBasicCredentials as HTTPBasicCredentials
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
from .oauth2 import OAuth2AuthorizationCodeBearer as OAuth2AuthorizationCodeBearer
from .oauth2 import OAuth2PasswordBearer as OAuth2PasswordBearer
from .oauth2 import OAuth2PasswordRequestForm as OAuth2PasswordRequestForm
from .oauth2 import OAuth2PasswordRequestFormStrict as OAuth2PasswordRequestFormStrict
from .oauth2 import SecurityScopes as SecurityScopes
Reported by Pylint.
Line: 10
Column: 1
from .http import HTTPBearer as HTTPBearer
from .http import HTTPDigest as HTTPDigest
from .oauth2 import OAuth2 as OAuth2
from .oauth2 import OAuth2AuthorizationCodeBearer as OAuth2AuthorizationCodeBearer
from .oauth2 import OAuth2PasswordBearer as OAuth2PasswordBearer
from .oauth2 import OAuth2PasswordRequestForm as OAuth2PasswordRequestForm
from .oauth2 import OAuth2PasswordRequestFormStrict as OAuth2PasswordRequestFormStrict
from .oauth2 import SecurityScopes as SecurityScopes
from .open_id_connect_url import OpenIdConnect as OpenIdConnect
Reported by Pylint.
tests/test_tutorial/test_body/test_tutorial001.py
31 issues
Line: 3
Column: 1
from unittest.mock import patch
import pytest
from fastapi.testclient import TestClient
from docs_src.body.tutorial001 import app
client = TestClient(app)
Reported by Pylint.
Line: 1
Column: 1
from unittest.mock import patch
import pytest
from fastapi.testclient import TestClient
from docs_src.body.tutorial001 import app
client = TestClient(app)
Reported by Pylint.
Line: 88
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.
Line: 90
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
price_missing = {
"detail": [
Reported by Bandit.
Line: 91
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
price_missing = {
"detail": [
{
Reported by Bandit.
Line: 167
Column: 1
("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float),
("/items/", {}, 422, name_price_missing),
("/items/", None, 422, body_missing),
],
)
def test_post_body(path, body, expected_status, expected_response):
response = client.post(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Pylint.
Line: 171
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test_post_body(path, body, expected_status, expected_response):
response = client.post(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
def test_post_broken_body():
response = client.post(
Reported by Bandit.
Line: 172
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_post_body(path, body, expected_status, expected_response):
response = client.post(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
def test_post_broken_body():
response = client.post(
"/items/",
Reported by Bandit.
Line: 175
Column: 1
assert response.json() == expected_response
def test_post_broken_body():
response = client.post(
"/items/",
headers={"content-type": "application/json"},
data="{some broken json}",
)
Reported by Pylint.
Line: 181
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
headers={"content-type": "application/json"},
data="{some broken json}",
)
assert response.status_code == 422, response.text
assert response.json() == {
"detail": [
{
"loc": ["body", 1],
"msg": "Expecting property name enclosed in double quotes: line 1 column 2 (char 1)",
Reported by Bandit.
docs_src/security/tutorial004.py
29 issues
Line: 4
Column: 1
from datetime import datetime, timedelta
from typing import Optional
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from jose import JWTError, jwt
from passlib.context import CryptContext
from pydantic import BaseModel
Reported by Pylint.
Line: 5
Column: 1
from typing import Optional
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from jose import JWTError, jwt
from passlib.context import CryptContext
from pydantic import BaseModel
# to get a string like this run:
Reported by Pylint.
Line: 6
Column: 1
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from jose import JWTError, jwt
from passlib.context import CryptContext
from pydantic import BaseModel
# to get a string like this run:
# openssl rand -hex 32
Reported by Pylint.
Line: 7
Column: 1
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from jose import JWTError, jwt
from passlib.context import CryptContext
from pydantic import BaseModel
# to get a string like this run:
# openssl rand -hex 32
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
Reported by Pylint.
Line: 8
Column: 1
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from jose import JWTError, jwt
from passlib.context import CryptContext
from pydantic import BaseModel
# to get a string like this run:
# openssl rand -hex 32
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
ALGORITHM = "HS256"
Reported by Pylint.
Line: 126
Column: 22
)
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
return {"access_token": access_token, "token_type": "bearer"}
@app.get("/users/me/", response_model=User)
Reported by Pylint.
Line: 102
Column: 9
raise credentials_exception
token_data = TokenData(username=username)
except JWTError:
raise credentials_exception
user = get_user(fake_users_db, username=token_data.username)
if user is None:
raise credentials_exception
return user
Reported by Pylint.
Line: 1
Column: 1
from datetime import datetime, timedelta
from typing import Optional
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from jose import JWTError, jwt
from passlib.context import CryptContext
from pydantic import BaseModel
Reported by Pylint.
Line: 12
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b105_hardcoded_password_string.html
# to get a string like this run:
# openssl rand -hex 32
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30
fake_users_db = {
Reported by Bandit.
Line: 28
Column: 1
}
class Token(BaseModel):
access_token: str
token_type: str
class TokenData(BaseModel):
Reported by Pylint.
tests/test_serialize_response_model.py
29 issues
Line: 4
Column: 1
from typing import Dict, List, Optional
from fastapi import FastAPI
from pydantic import BaseModel, Field
from starlette.testclient import TestClient
app = FastAPI()
Reported by Pylint.
Line: 5
Column: 1
from fastapi import FastAPI
from pydantic import BaseModel, Field
from starlette.testclient import TestClient
app = FastAPI()
class Item(BaseModel):
Reported by Pylint.
Line: 1
Column: 1
from typing import Dict, List, Optional
from fastapi import FastAPI
from pydantic import BaseModel, Field
from starlette.testclient import TestClient
app = FastAPI()
Reported by Pylint.
Line: 10
Column: 1
app = FastAPI()
class Item(BaseModel):
name: str = Field(..., alias="aliased_name")
price: Optional[float] = None
owner_ids: Optional[List[int]] = None
Reported by Pylint.
Line: 10
Column: 1
app = FastAPI()
class Item(BaseModel):
name: str = Field(..., alias="aliased_name")
price: Optional[float] = None
owner_ids: Optional[List[int]] = None
Reported by Pylint.
Line: 17
Column: 1
@app.get("/items/valid", response_model=Item)
def get_valid():
return Item(aliased_name="valid", price=1.0)
@app.get("/items/coerce", response_model=Item)
def get_coerce():
Reported by Pylint.
Line: 22
Column: 1
@app.get("/items/coerce", response_model=Item)
def get_coerce():
return Item(aliased_name="coerce", price="1.0")
@app.get("/items/validlist", response_model=List[Item])
def get_validlist():
Reported by Pylint.
Line: 27
Column: 1
@app.get("/items/validlist", response_model=List[Item])
def get_validlist():
return [
Item(aliased_name="foo"),
Item(aliased_name="bar", price=1.0),
Item(aliased_name="baz", price=2.0, owner_ids=[1, 2, 3]),
]
Reported by Pylint.
Line: 36
Column: 1
@app.get("/items/validdict", response_model=Dict[str, Item])
def get_validdict():
return {
"k1": Item(aliased_name="foo"),
"k2": Item(aliased_name="bar", price=1.0),
"k3": Item(aliased_name="baz", price=2.0, owner_ids=[1, 2, 3]),
}
Reported by Pylint.
Line: 46
Column: 1
@app.get(
"/items/valid-exclude-unset", response_model=Item, response_model_exclude_unset=True
)
def get_valid_exclude_unset():
return Item(aliased_name="valid", price=1.0)
@app.get(
Reported by Pylint.
tests/test_tutorial/test_dependencies/test_tutorial012.py
28 issues
Line: 1
Column: 1
from fastapi.testclient import TestClient
from docs_src.dependencies.tutorial012 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
Reported by Pylint.
Line: 116
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.
Line: 118
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_items():
response = client.get("/items/")
Reported by Bandit.
Line: 119
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_items():
response = client.get("/items/")
assert response.status_code == 422, response.text
Reported by Bandit.
Line: 122
Column: 1
assert response.json() == openapi_schema
def test_get_no_headers_items():
response = client.get("/items/")
assert response.status_code == 422, response.text
assert response.json() == {
"detail": [
{
Reported by Pylint.
Line: 124
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_get_no_headers_items():
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.
Line: 125
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_get_no_headers_items():
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.
Line: 141
Column: 1
}
def test_get_no_headers_users():
response = client.get("/users/")
assert response.status_code == 422, response.text
assert response.json() == {
"detail": [
{
Reported by Pylint.
Line: 143
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_get_no_headers_users():
response = client.get("/users/")
assert response.status_code == 422, response.text
assert response.json() == {
"detail": [
{
"loc": ["header", "x-token"],
"msg": "field required",
Reported by Bandit.
Line: 144
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_get_no_headers_users():
response = client.get("/users/")
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.
tests/test_dependency_class.py
28 issues
Line: 3
Column: 1
from typing import AsyncGenerator, Generator
import pytest
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
app = FastAPI()
Reported by Pylint.
Line: 1
Column: 1
from typing import AsyncGenerator, Generator
import pytest
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
app = FastAPI()
Reported by Pylint.
Line: 10
Column: 1
app = FastAPI()
class CallableDependency:
def __call__(self, value: str) -> str:
return value
class CallableGenDependency:
Reported by Pylint.
Line: 10
Column: 1
app = FastAPI()
class CallableDependency:
def __call__(self, value: str) -> str:
return value
class CallableGenDependency:
Reported by Pylint.
Line: 15
Column: 1
return value
class CallableGenDependency:
def __call__(self, value: str) -> Generator[str, None, None]:
yield value
class AsyncCallableDependency:
Reported by Pylint.
Line: 15
Column: 1
return value
class CallableGenDependency:
def __call__(self, value: str) -> Generator[str, None, None]:
yield value
class AsyncCallableDependency:
Reported by Pylint.
Line: 20
Column: 1
yield value
class AsyncCallableDependency:
async def __call__(self, value: str) -> str:
return value
class AsyncCallableGenDependency:
Reported by Pylint.
Line: 20
Column: 1
yield value
class AsyncCallableDependency:
async def __call__(self, value: str) -> str:
return value
class AsyncCallableGenDependency:
Reported by Pylint.
Line: 25
Column: 1
return value
class AsyncCallableGenDependency:
async def __call__(self, value: str) -> AsyncGenerator[str, None]:
yield value
class MethodsDependency:
Reported by Pylint.
Line: 25
Column: 1
return value
class AsyncCallableGenDependency:
async def __call__(self, value: str) -> AsyncGenerator[str, None]:
yield value
class MethodsDependency:
Reported by Pylint.
tests/test_invalid_sequence_param.py
28 issues
Line: 3
Column: 1
from typing import Dict, List, Optional, Tuple
import pytest
from fastapi import FastAPI, Query
from pydantic import BaseModel
def test_invalid_sequence():
with pytest.raises(AssertionError):
Reported by Pylint.
Line: 5
Column: 1
import pytest
from fastapi import FastAPI, Query
from pydantic import BaseModel
def test_invalid_sequence():
with pytest.raises(AssertionError):
app = FastAPI()
Reported by Pylint.
Line: 16
Column: 24
title: str
@app.get("/items/")
def read_items(q: List[Item] = Query(None)):
pass # pragma: no cover
def test_invalid_tuple():
with pytest.raises(AssertionError):
Reported by Pylint.
Line: 16
Column: 9
title: str
@app.get("/items/")
def read_items(q: List[Item] = Query(None)):
pass # pragma: no cover
def test_invalid_tuple():
with pytest.raises(AssertionError):
Reported by Pylint.
Line: 28
Column: 9
title: str
@app.get("/items/")
def read_items(q: Tuple[Item, Item] = Query(None)):
pass # pragma: no cover
def test_invalid_dict():
with pytest.raises(AssertionError):
Reported by Pylint.
Line: 28
Column: 24
title: str
@app.get("/items/")
def read_items(q: Tuple[Item, Item] = Query(None)):
pass # pragma: no cover
def test_invalid_dict():
with pytest.raises(AssertionError):
Reported by Pylint.
Line: 40
Column: 24
title: str
@app.get("/items/")
def read_items(q: Dict[str, Item] = Query(None)):
pass # pragma: no cover
def test_invalid_simple_dict():
with pytest.raises(AssertionError):
Reported by Pylint.
Line: 40
Column: 9
title: str
@app.get("/items/")
def read_items(q: Dict[str, Item] = Query(None)):
pass # pragma: no cover
def test_invalid_simple_dict():
with pytest.raises(AssertionError):
Reported by Pylint.
Line: 48
Column: 9
with pytest.raises(AssertionError):
app = FastAPI()
class Item(BaseModel):
title: str
@app.get("/items/")
def read_items(q: Optional[dict] = Query(None)):
pass # pragma: no cover
Reported by Pylint.
Line: 52
Column: 9
title: str
@app.get("/items/")
def read_items(q: Optional[dict] = Query(None)):
pass # pragma: no cover
Reported by Pylint.
tests/test_sub_callbacks.py
27 issues
Line: 5
Column: 1
from fastapi import APIRouter, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, HttpUrl
app = FastAPI()
class Invoice(BaseModel):
Reported by Pylint.
Line: 32
Column: 26
@invoices_callback_router.post(
"{$callback_url}/invoices/{$request.body.id}", response_model=InvoiceEventReceived
)
def invoice_notification(body: InvoiceEvent):
pass # pragma: nocover
class Event(BaseModel):
name: str
Reported by Pylint.
Line: 45
Column: 20
@events_callback_router.get("{$callback_url}/events/{$request.body.title}")
def event_callback(event: Event):
pass # pragma: nocover
subrouter = APIRouter()
Reported by Pylint.
Line: 53
Column: 38
@subrouter.post("/invoices/", callbacks=invoices_callback_router.routes)
def create_invoice(invoice: Invoice, callback_url: Optional[HttpUrl] = None):
"""
Create an invoice.
This will (let's imagine) let the API user (some external developer) create an
invoice.
Reported by Pylint.
Line: 53
Column: 20
@subrouter.post("/invoices/", callbacks=invoices_callback_router.routes)
def create_invoice(invoice: Invoice, callback_url: Optional[HttpUrl] = None):
"""
Create an invoice.
This will (let's imagine) let the API user (some external developer) create an
invoice.
Reported by Pylint.
Line: 1
Column: 1
from typing import Optional
from fastapi import APIRouter, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, HttpUrl
app = FastAPI()
Reported by Pylint.
Line: 10
Column: 1
app = FastAPI()
class Invoice(BaseModel):
id: str
title: Optional[str] = None
customer: str
total: float
Reported by Pylint.
Line: 10
Column: 1
app = FastAPI()
class Invoice(BaseModel):
id: str
title: Optional[str] = None
customer: str
total: float
Reported by Pylint.
Line: 17
Column: 1
total: float
class InvoiceEvent(BaseModel):
description: str
paid: bool
class InvoiceEventReceived(BaseModel):
Reported by Pylint.
Line: 17
Column: 1
total: float
class InvoiceEvent(BaseModel):
description: str
paid: bool
class InvoiceEventReceived(BaseModel):
Reported by Pylint.