-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Closed
Labels
Description
from fastapi import APIRouter, File, Form, UploadFile
router = APIRouter()
@router.post("/upload", response_model=MyResponseModel, summary="user csv upload api")
async def upload(
user_id: int = Form(..., example=1),
csv_file: UploadFile = File(...),
):
"""
some code...
"""I checked on swagger(/docs). It was successful.
but, failed in test code
from myapp import app
class UploadTest(unittest.TestCase):
client = TestClient(app)
def test_upload(self):
with csv.open("rb") as f:
filebody = f.read()
res = self.client.post(
"/api/upload",
data={
"user_id": 1
},
files={
"csv_file": ("filename.csv", filebody),
},
headers={"Content-Type": "multipart/form-data"})
self.assertEqual(status.HTTP_200_OK, res.status_code)
MyResponseModel.parse_obj(res.json()["data"])Error getting request body: can't concat NoneType to bytes
{'detail': 'There was an error parsing the body'}