I want to test the update function of a view set
from rest_framework.viewsets import ModelViewSet
@extend_schema(tags=['Customers'])
class CustomerViewSet(ModelViewSet):
""" This view can be used to see all the customers"""
serializer_class = CustomerSerializer
.....
def update(self, request, *args, **kwargs):
return self._update_customer(request, *args, **kwargs)
The route is mapped here (like the other view sets):
router.register(r'customers', CustomerViewSet, basename='customer')
Like for my other view sets where it works,
i test the update method by resolving it in my test case
from django.test import TestCase
from rest_framework.reverse import reverse
......
class CustomerUpdateViewTest(TestCase):
.....
def test_customer_missing(self):
url = reverse('customer-detail', [2])
token = create_access_token(self.my_user)
data = {
'customer': 'new name customer'
}
response = self.client.patch(url, data,
content_type="application/json",
HTTP_AUTHORIZATION=f'Bearer {token}')
I have created before in a setup method many customers
But the self.client.patch instruction give always a 404 error
In my running application,
the path is /api/customers/x (like in my test where x = a customer identifier)
and is an HTTP PATCH verb
For my similar views, i test in a very similar way and it works.
Do you have already encountered such a problem ?
If yes, what can i do to solve this problem ?
Thank you very much in advance,
Thomas