The following issues were found
docs_src/custom_response/tutorial004.py
5 issues
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
app = FastAPI()
def generate_html_response():
html_content = """
<html>
Reported by Pylint.
Line: 2
Column: 1
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
app = FastAPI()
def generate_html_response():
html_content = """
<html>
Reported by Pylint.
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
app = FastAPI()
def generate_html_response():
html_content = """
<html>
Reported by Pylint.
Line: 7
Column: 1
app = FastAPI()
def generate_html_response():
html_content = """
<html>
<head>
<title>Some HTML in here</title>
</head>
Reported by Pylint.
Line: 22
Column: 1
@app.get("/items/", response_class=HTMLResponse)
async def read_items():
return generate_html_response()
Reported by Pylint.
tests/test_tutorial/test_advanced_middleware/test_tutorial001.py
5 issues
Line: 1
Column: 1
from fastapi.testclient import TestClient
from docs_src.advanced_middleware.tutorial001 import app
def test_middleware():
client = TestClient(app, base_url="https://testserver")
response = client.get("/")
assert response.status_code == 200, response.text
Reported by Pylint.
Line: 6
Column: 1
from docs_src.advanced_middleware.tutorial001 import app
def test_middleware():
client = TestClient(app, base_url="https://testserver")
response = client.get("/")
assert response.status_code == 200, response.text
client = TestClient(app)
Reported by Pylint.
Line: 9
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_middleware():
client = TestClient(app, base_url="https://testserver")
response = client.get("/")
assert response.status_code == 200, response.text
client = TestClient(app)
response = client.get("/", allow_redirects=False)
assert response.status_code == 307, response.text
assert response.headers["location"] == "https://testserver/"
Reported by Bandit.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
client = TestClient(app)
response = client.get("/", allow_redirects=False)
assert response.status_code == 307, response.text
assert response.headers["location"] == "https://testserver/"
Reported by Bandit.
Line: 14
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
client = TestClient(app)
response = client.get("/", allow_redirects=False)
assert response.status_code == 307, response.text
assert response.headers["location"] == "https://testserver/"
Reported by Bandit.
tests/test_tutorial/test_advanced_middleware/test_tutorial002.py
5 issues
Line: 1
Column: 1
from fastapi.testclient import TestClient
from docs_src.advanced_middleware.tutorial002 import app
def test_middleware():
client = TestClient(app, base_url="http://example.com")
response = client.get("/")
assert response.status_code == 200, response.text
Reported by Pylint.
Line: 6
Column: 1
from docs_src.advanced_middleware.tutorial002 import app
def test_middleware():
client = TestClient(app, base_url="http://example.com")
response = client.get("/")
assert response.status_code == 200, response.text
client = TestClient(app, base_url="http://subdomain.example.com")
response = client.get("/")
Reported by Pylint.
Line: 9
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_middleware():
client = TestClient(app, base_url="http://example.com")
response = client.get("/")
assert response.status_code == 200, response.text
client = TestClient(app, base_url="http://subdomain.example.com")
response = client.get("/")
assert response.status_code == 200, response.text
client = TestClient(app, base_url="http://invalidhost")
response = client.get("/")
Reported by Bandit.
Line: 12
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
assert response.status_code == 200, response.text
client = TestClient(app, base_url="http://subdomain.example.com")
response = client.get("/")
assert response.status_code == 200, response.text
client = TestClient(app, base_url="http://invalidhost")
response = client.get("/")
assert response.status_code == 400, response.text
Reported by Bandit.
Line: 15
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
assert response.status_code == 200, response.text
client = TestClient(app, base_url="http://invalidhost")
response = client.get("/")
assert response.status_code == 400, response.text
Reported by Bandit.
tests/test_tutorial/test_header_params/test_tutorial001.py
5 issues
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.header_params.tutorial001 import app
client = TestClient(app)
openapi_schema = {
Reported by Pylint.
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.header_params.tutorial001 import app
client = TestClient(app)
openapi_schema = {
Reported by Pylint.
Line: 83
Column: 1
("/items", None, 200, {"User-Agent": "testclient"}),
("/items", {"X-Header": "notvalid"}, 200, {"User-Agent": "testclient"}),
("/items", {"User-Agent": "FastAPI test"}, 200, {"User-Agent": "FastAPI test"}),
],
)
def test(path, headers, expected_status, expected_response):
response = client.get(path, headers=headers)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Pylint.
Line: 87
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test(path, headers, expected_status, expected_response):
response = client.get(path, headers=headers)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
Line: 88
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test(path, headers, expected_status, expected_response):
response = client.get(path, headers=headers)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
docs_src/custom_response/tutorial008.py
5 issues
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/")
def main():
Reported by Pylint.
Line: 2
Column: 1
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/")
def main():
Reported by Pylint.
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/")
def main():
Reported by Pylint.
Line: 4
Column: 1
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/")
def main():
Reported by Pylint.
Line: 9
Column: 1
@app.get("/")
def main():
def iterfile(): # (1)
with open(some_file_path, mode="rb") as file_like: # (2)
yield from file_like # (3)
return StreamingResponse(iterfile(), media_type="video/mp4")
Reported by Pylint.
docs_src/custom_response/tutorial009.py
5 issues
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.responses import FileResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/")
async def main():
Reported by Pylint.
Line: 2
Column: 1
from fastapi import FastAPI
from fastapi.responses import FileResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/")
async def main():
Reported by Pylint.
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.responses import FileResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/")
async def main():
Reported by Pylint.
Line: 4
Column: 1
from fastapi import FastAPI
from fastapi.responses import FileResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/")
async def main():
Reported by Pylint.
Line: 9
Column: 1
@app.get("/")
async def main():
return FileResponse(some_file_path)
Reported by Pylint.
docs_src/custom_response/tutorial009b.py
5 issues
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.responses import FileResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/", response_class=FileResponse)
async def main():
Reported by Pylint.
Line: 2
Column: 1
from fastapi import FastAPI
from fastapi.responses import FileResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/", response_class=FileResponse)
async def main():
Reported by Pylint.
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.responses import FileResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/", response_class=FileResponse)
async def main():
Reported by Pylint.
Line: 4
Column: 1
from fastapi import FastAPI
from fastapi.responses import FileResponse
some_file_path = "large-video-file.mp4"
app = FastAPI()
@app.get("/", response_class=FileResponse)
async def main():
Reported by Pylint.
Line: 9
Column: 1
@app.get("/", response_class=FileResponse)
async def main():
return some_file_path
Reported by Pylint.
tests/test_tutorial/test_first_steps/test_tutorial001.py
5 issues
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.first_steps.tutorial001 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.first_steps.tutorial001 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 34
Column: 1
("/", 200, {"message": "Hello World"}),
("/nonexistent", 404, {"detail": "Not Found"}),
("/openapi.json", 200, openapi_schema),
],
)
def test_get_path(path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Pylint.
Line: 38
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test_get_path(path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
Line: 39
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_get_path(path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
tests/test_tutorial/test_cookie_params/test_tutorial001.py
5 issues
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.cookie_params.tutorial001 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.cookie_params.tutorial001 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 88
Column: 1
{"ads_id": "ads_track"},
),
("/items", {"session": "cookiesession"}, 200, {"ads_id": None}),
],
)
def test(path, cookies, expected_status, expected_response):
response = client.get(path, cookies=cookies)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Pylint.
Line: 92
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test(path, cookies, expected_status, expected_response):
response = client.get(path, cookies=cookies)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
Line: 93
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test(path, cookies, expected_status, expected_response):
response = client.get(path, cookies=cookies)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
docs_src/extending_openapi/tutorial001.py
5 issues
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
Reported by Pylint.
Line: 2
Column: 1
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
Reported by Pylint.
Line: 1
Column: 1
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
Reported by Pylint.
Line: 8
Column: 1
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
def custom_openapi():
if app.openapi_schema:
Reported by Pylint.
Line: 12
Column: 1
return [{"name": "Foo"}]
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Custom title",
version="2.5.0",
Reported by Pylint.