Commits

Waldemar Kornewald committed f4435ff

moved unit tests for IN with order_by

Comments (0)

Files changed (2)

         self.assertEqual(A.objects.all()[0].value, 3)
         self.assertRaises(DatabaseError, B.objects.count)
         self.assertRaises(DatabaseError, lambda: B.objects.all()[0])
-
-    def test_in_sort(self):
-        class Post(models.Model):
-            writer = models.IntegerField()
-            order = models.IntegerField()
-        Post(writer=1, order=1).save()
-        Post(writer=1, order=2).save()
-        Post(writer=1, order=3).save()
-        Post(writer=2, order=4).save()
-        Post(writer=2, order=5).save()
-        import logging
-        posts = Post.objects.filter(writer__in= [1,2]).order_by('order')
-        logging.warn('posts %s' % (list(i.order for i in posts)))
-        self.assertEqual(posts[0].order, 1)
-        self.assertEqual(posts[1].order, 2)
-        self.assertEqual(posts[2].order, 3)
-        self.assertEqual(posts[3].order, 4)
-        self.assertEqual(posts[4].order, 5)
-        posts = Post.objects.filter(writer__in= [1,2]).order_by('-order')
-        logging.warn('posts %s' % (list(i.order for i in posts)))
-        self.assertEqual(posts[0].order, 5)
-        self.assertEqual(posts[1].order, 4)
-        self.assertEqual(posts[2].order, 3)
-        self.assertEqual(posts[3].order, 2)
-        self.assertEqual(posts[4].order, 1)
-
 from ..db.utils import get_cursor, set_cursor
 from .testmodels import FieldsWithOptionsModel, EmailModel, DateTimeModel, \
     OrderedModel, BlobModel
+from django.db import models
 from django.db.models import Q
 from django.db.utils import DatabaseError
 from django.test import TestCase
                                       'rasengan@naruto.com'])],
                           ['app-engine@scholardocs.com', 'rasengan@naruto.com'])
 
+    def test_in_with_order_by(self):
+        class Post(models.Model):
+            writer = models.IntegerField()
+            order = models.IntegerField()
+        Post(writer=1, order=1).save()
+        Post(writer=1, order=2).save()
+        Post(writer=1, order=3).save()
+        Post(writer=2, order=4).save()
+        Post(writer=2, order=5).save()
+        posts = Post.objects.filter(writer__in= [1,2]).order_by('order')
+        orders = [post.order for post in posts]
+        self.assertEqual(orders, range(1, 6))
+        posts = Post.objects.filter(writer__in= [1,2]).order_by('-order')
+        orders = [post.order for post in posts]
+        self.assertEqual(orders, range(5, 0, -1))
+
     def test_inequality(self):
         self.assertEquals([entity.email for entity in
                            FieldsWithOptionsModel.objects.exclude(
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.