Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a
QuerySet.ordered
property to check if a queryset is already…
… ordered. Refs #10163. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10623 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
import unittest | |||
from models import Tag, Annotation | |||
from django.db.models import Count | |||
|
|||
class QuerysetOrderedTests(unittest.TestCase): | |||
""" | |||
Tests for the Queryset.ordered attribute. | |||
""" | |||
|
|||
def test_no_default_or_explicit_ordering(self): | |||
self.assertEqual(Annotation.objects.all().ordered, False) | |||
|
|||
def test_cleared_default_ordering(self): | |||
self.assertEqual(Tag.objects.all().ordered, True) | |||
self.assertEqual(Tag.objects.all().order_by().ordered, False) | |||
|
|||
def test_explicit_ordering(self): | |||
self.assertEqual(Annotation.objects.all().order_by('id').ordered, True) | |||
|
|||
def test_order_by_extra(self): | |||
self.assertEqual(Annotation.objects.all().extra(order_by=['id']).ordered, True) | |||
|
|||
def test_annotated_ordering(self): | |||
qs = Annotation.objects.annotate(num_notes=Count('notes')) | |||
self.assertEqual(qs.ordered, False) | |||
self.assertEqual(qs.order_by('num_notes').ordered, True) | |||
|