I have this function in my viewset to upload a pdf file to A
@api_view(['POST', 'DELETE'])
@permission_classes((AllowAny,))
def upload_file_pdf(request):
# Uploading and saving the file if the request is a POST - Validating the extension of the file as well
if request.method == 'POST':
try:
upload = Upload(file_pdf=request.FILES["filepond"])
upload.full_clean()
except ValidationError as e:
return Response(e, status=status.HTTP_400_BAD_REQUEST)
upload.save()
return Response(upload.pk, status=status.HTTP_200_OK)
# Deleting the file if the request is DELETE
if request.method == 'DELETE':
file_pk = str(json.loads(request.body))
return Response(file_pk, status=status.HTTP_200_OK)
When I want to test it, I don`t know how to create a sample pdf file in unit tests
def test_create(self):
self.pdf_file = ....
self.client.post('/api/v1/file/pdf/', data={"filepond": self.pdf_file})
self.assertEqual(response.status_code, 200)
What should I put in front of self.pdf_file