#29308: Testing: assertQuerysetEqual's transform parameter not applied to the
values parameter
---------------------------------------------+------------------------
Reporter: Alexander Todorov | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
According to:
https://docs.djangoproject.com/en/2.0/topics/testing/tools/#django.test.TransactionTestCase.assertQuerysetEqual
> Asserts that a queryset `qs` returns a particular list of values
`values`.
>
> The comparison of the contents of `qs` and `values` is performed using
the function `transform`;
The way I read this is that this assert method receives a queryset and a
list parameters and compares their contents for equality. By default it
will use `repr` to do that but the user can change this. The way the docs
are written suggests that the `transform` function is applied to both the
queryset and the `values` list. In other words in my tests I can write:
``
self.assertQuerysetEqual(some_query_taken_from_request_context,
[test_object1, test_object2, etc])
``
The tutorial doesn't use the above but instead hard codes string
representations in the tests:
https://docs.djangoproject.com/en/2.0/intro/tutorial05/#testing-our-new-
view
IMO this is less optimal, makes test suites more fragile (dependent on
repr()) and less intuitive b/c the expected value isn't a list of the
actual objects but a list of their representation which may have been
obtained elsewhere.
Note: this may sounds like an RFE but if we trust the docs it's a bug.
Note2: I can contribute a PR for this and update the existing test suite &
docs. Just let me know how you feel about it.
--
Ticket URL: <https://code.djangoproject.com/ticket/29308>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.3f3aee62410d58bfa837b35b17f2aad8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.