summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2020-10-18 18:29:52 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-11-06 09:24:50 +0100
commit3f7b3275627385f8f7531fca01cdda50d4ec6b6e (patch)
treefb082d40e73f6c877911eab92229ac21cdfaa5bc /docs
parent13b6fff11703a694e155b84d41d02822bbc0aaa0 (diff)
Fixed #31235 -- Made assertQuerysetEqual() compare querysets directly.
This also replaces assertQuerysetEqual() to assertSequenceEqual()/assertCountEqual() where appropriate. Co-authored-by: Peter Inglesby <peter.inglesby@gmail.com> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/internals/deprecation.txt3
-rw-r--r--docs/intro/tutorial05.txt14
-rw-r--r--docs/releases/3.2.txt10
-rw-r--r--docs/topics/testing/tools.txt27
4 files changed, 40 insertions, 14 deletions
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
index 46a1aaaee6..06ea0fbbc0 100644
--- a/docs/internals/deprecation.txt
+++ b/docs/internals/deprecation.txt
@@ -26,6 +26,9 @@ details on these changes.
* The ``default_app_config`` module variable will be removed.
+* ``TransactionTestCase.assertQuerysetEqual()` will no longer automatically
+ call ``repr()`` on a queryset when compared to string values.
+
.. _deprecation-removed-in-4.0:
4.0
diff --git a/docs/intro/tutorial05.txt b/docs/intro/tutorial05.txt
index 046abb8124..1ff868b1cb 100644
--- a/docs/intro/tutorial05.txt
+++ b/docs/intro/tutorial05.txt
@@ -498,11 +498,11 @@ class:
Questions with a pub_date in the past are displayed on the
index page.
"""
- create_question(question_text="Past question.", days=-30)
+ question = create_question(question_text="Past question.", days=-30)
response = self.client.get(reverse('polls:index'))
self.assertQuerysetEqual(
response.context['latest_question_list'],
- ['<Question: Past question.>']
+ [question],
)
def test_future_question(self):
@@ -520,24 +520,24 @@ class:
Even if both past and future questions exist, only past questions
are displayed.
"""
- create_question(question_text="Past question.", days=-30)
+ question = create_question(question_text="Past question.", days=-30)
create_question(question_text="Future question.", days=30)
response = self.client.get(reverse('polls:index'))
self.assertQuerysetEqual(
response.context['latest_question_list'],
- ['<Question: Past question.>']
+ [question],
)
def test_two_past_questions(self):
"""
The questions index page may display multiple questions.
"""
- create_question(question_text="Past question 1.", days=-30)
- create_question(question_text="Past question 2.", days=-5)
+ question1 = create_question(question_text="Past question 1.", days=-30)
+ question2 = create_question(question_text="Past question 2.", days=-5)
response = self.client.get(reverse('polls:index'))
self.assertQuerysetEqual(
response.context['latest_question_list'],
- ['<Question: Past question 2.>', '<Question: Past question 1.>']
+ [question2, question1],
)
diff --git a/docs/releases/3.2.txt b/docs/releases/3.2.txt
index a460f96eef..f542a4fee9 100644
--- a/docs/releases/3.2.txt
+++ b/docs/releases/3.2.txt
@@ -422,6 +422,11 @@ Tests
<django.db.transaction.on_commit>` in a list. This allows you to test such
callbacks without using the slower :class:`.TransactionTestCase`.
+* :meth:`.TransactionTestCase.assertQuerysetEqual` now supports direct
+ comparison against another queryset rather than being restricted to
+ comparison against a list of string representations of objects when using the
+ default value for the ``transform`` argument.
+
URLs
~~~~
@@ -615,3 +620,8 @@ Miscellaneous
* The ``default_app_config`` application configuration variable is deprecated,
due to the now automatic ``AppConfig`` discovery. See :ref:`whats-new-3.2`
for more details.
+
+* Automatically calling ``repr()`` on a queryset in
+ ``TransactionTestCase.assertQuerysetEqual()``, when compared to string
+ values, is deprecated. If you need the previous behavior, explicitly set
+ ``transform`` to ``repr``.
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 2d10873611..678eb260aa 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -1683,15 +1683,13 @@ your test suite.
Output in case of error can be customized with the ``msg`` argument.
-.. method:: TransactionTestCase.assertQuerysetEqual(qs, values, transform=repr, ordered=True, msg=None)
+.. method:: TransactionTestCase.assertQuerysetEqual(qs, values, transform=None, ordered=True, msg=None)
- Asserts that a queryset ``qs`` returns a particular list of values ``values``.
+ Asserts that a queryset ``qs`` matches a particular iterable of values
+ ``values``.
- The comparison of the contents of ``qs`` and ``values`` is performed by
- applying ``transform`` to ``qs``. By default, this means that the
- ``repr()`` of each value in ``qs`` is compared to the ``values``. Any other
- callable can be used if ``repr()`` doesn't provide a unique or helpful
- comparison.
+ If ``transform`` is provided, ``values`` is compared to a list produced by
+ applying ``transform`` to each member of ``qs``.
By default, the comparison is also ordering dependent. If ``qs`` doesn't
provide an implicit ordering, you can set the ``ordered`` parameter to
@@ -1702,6 +1700,21 @@ your test suite.
Output in case of error can be customized with the ``msg`` argument.
+ .. versionchanged:: 3.2
+
+ The default value of ``transform`` argument was changed to ``None``.
+
+ .. versionadded:: 3.2
+
+ Support for direct comparison between querysets was added.
+
+ .. deprecated:: 3.2
+
+ If ``transform`` is not provided and ``values`` is a list of strings,
+ it's compared to a list produced by applying ``repr()`` to each member
+ of ``qs``. This behavior is deprecated and will be removed in Django
+ 4.1. If you need it, explicitly set ``transform`` to ``repr``.
+
.. method:: TransactionTestCase.assertNumQueries(num, func, *args, **kwargs)
Asserts that when ``func`` is called with ``*args`` and ``**kwargs`` that