I am building django REST app with mixins:
ModelViewSet(mixins.RetrieveModelMixin, mixins.CreateModelMixin)
queryset = Model.objects.all()
(...)
and retrieve()
is visible in localhost:8000/model/<uuid>
Then I add a function for counting all Model instances:
@action(detail=False, methods=["GET"], url_path="count")
def get_model_count(self, request):
queryset = self.get_queryset()
data = {"count": queryset.count()}
return Response(status=status.HTTP_200_OK, data=data)
Then when I try to test it:
def test_model_count(self):
list_size = 10
for i in range(list_size):
response = self.create_model()
self.assertEqual(response.status_code, 200, response.content)
response = self.client.get(reverse("model-get-model-count"))
self.assertEqual(response.status_code, 200, response.content)
I get this error: AssertionError: 400 != 200 : b"Invalid parameter robot_id value: 'all' is not a 'uuid'"
Interesting part is that when I use web or curl, everything works fine, I can get count correctly, I can get model details, I can create new model. I tried changing the order, so count
is implemented first, before retrieve
but the error still exists. Hope I provided enough of information, thanks in advance
Aucun commentaire:
Enregistrer un commentaire