Author: mtredinnick
Date: 2011-08-22 20:38:18 -0700 (Mon, 22 Aug 2011)
New Revision: 16654

Modified:
   django/trunk/django/test/testcases.py
   django/trunk/docs/topics/testing.txt
Log:
Add the ability to do unordered comparisons in assertQuerysetEqual.

Modified: django/trunk/django/test/testcases.py
===================================================================
--- django/trunk/django/test/testcases.py       2011-08-23 02:32:37 UTC (rev 
16653)
+++ django/trunk/django/test/testcases.py       2011-08-23 03:38:18 UTC (rev 
16654)
@@ -597,7 +597,9 @@
             msg_prefix + "Template '%s' was used unexpectedly in rendering"
             " the response" % template_name)
 
-    def assertQuerysetEqual(self, qs, values, transform=repr):
+    def assertQuerysetEqual(self, qs, values, transform=repr, ordered=True):
+        if not ordered:
+            return self.assertEqual(set(map(transform, qs)), set(values))
         return self.assertEqual(map(transform, qs), values)
 
     def assertNumQueries(self, num, func=None, *args, **kwargs):

Modified: django/trunk/docs/topics/testing.txt
===================================================================
--- django/trunk/docs/topics/testing.txt        2011-08-23 02:32:37 UTC (rev 
16653)
+++ django/trunk/docs/topics/testing.txt        2011-08-23 03:38:18 UTC (rev 
16654)
@@ -1592,7 +1592,7 @@
     ``target_status_code`` will be the url and status code for the final
     point of the redirect chain.
 
-.. method:: TestCase.assertQuerysetEqual(qs, values, transform=repr)
+.. method:: TestCase.assertQuerysetEqual(qs, values, transform=repr, 
ordered=True)
 
     .. versionadded:: 1.3
 
@@ -1603,10 +1603,17 @@
     each value is compared. Any other callable can be used if ``repr()`` 
doesn't
     provide a unique or helpful comparison.
 
-    The comparison is also ordering dependent. If ``qs`` doesn't provide an
-    implicit ordering, you will need to apply a ``order_by()`` clause to your
-    queryset to ensure that the test will pass reliably.
+    By default, the comparison is also ordering dependent. If ``qs`` doesn't
+    provide an implicit ordering, you can set the ``ordered`` parameter to
+    ``False``, which turns the comparison into a Python set comparison.
 
+    .. versionchanged:: 1.4
+       The ``ordered`` parameter is new in version 1.4. In earlier versions,
+       you would need to ensure the queryset is ordered consistently, possibly
+       via an explicit ``order_by()`` call on the queryset prior to
+       comparison.
+
+
 .. method:: TestCase.assertNumQueries(num, func, *args, **kwargs)
 
     .. versionadded:: 1.3

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to