A good way to compare the expected queryset with the results of the response #9550
-
I have a question when comparing the response(.data) and queryset object.
As an example, let's say there is a class called Dog and there is logic in View to get a list of hungry dogs.
The two values that I want to compare with assertEqual, response and expected_response, are of different types.
In the case of response.data, Serializer is applied, so when it's in dict form, I want to compare it with Queryset type expected_response.
number 2 example.
But I'm not sure if the two methods are good in comparison.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I think you can check cookiecutter-django repository. Personally, i prefer the raw data(python dict, list …) in tests, not using serializer to make dict in tests. |
Beta Was this translation helpful? Give feedback.
Make your test more focused, reducing its scope:
Personally, I like to create a single entry to test the retrieve part of my viewset, and check the full payload, status code, etc... But in case of list/filter endpoints, I would only check the ID / name attribute to make sure the ones I expect to see are present, n…