Answer the question
In order to leave comments, you need to log in
Testing a POST method using unittest Client()?
I can't understand why when testing the POST method returns me a 404 error.
There is such a class
class CsvToDatabase(APIView):
permission_classes = (permissions.AllowAny,)
serializer_class = VendorsCsvSerializer
def post(self, request, format=None):
r_data = request.data
for data in r_data:
внутренняя логика
.....
serializer = VendorsCsvSerializer(data=data)
try:
serializer.is_valid(raise_exception=True)
serializer.save()
except ValidationError:
return Response({"errors": (serializer.errors,)},
status=status.HTTP_400_BAD_REQUEST)
else:
return Response(request.data, status=status.HTTP_200_OK)
class VendorCsvCreateTest(APITestCase):
def test_vendor_from_csv_create(self):
url = reverse('csv_vendor_create')
response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
urlpatterns = [
path('csv_upload/', FileUploadView.as_view(), name='csv_upload'),
path('from_csv_create/', CsvToDatabase.as_view(), name='csv_vendor_create'),
path('create/', VendorsCreateView.as_view(), name='vendor_create'),]
FAIL: test_vendor_from_csv_create (vendors.tests.VendorCsvCreateTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/y700/projects/solution/apps/vendors/tests.py", line 108, in test_vendor_from_csv_create
self.assertEqual(response.status_code, status.HTTP_200_OK)
AssertionError: 404 != 200
response = self.client.post(url, data, format='json')
format=json is written. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question