adamv avatar adamv committed d258bd0

Updated slicing tests to try "distinct" variants.

Comments (0)

Files changed (2)

tests/test_main/regressiontests/tests.py

 from django.test import TestCase
 
 
-class Bug57Table(models.Model):
-    s = models.CharField(max_length=10)
-
-class Bug57TestCase(TestCase):
-    def testAllDistinctLimit(self):
-        Bug57Table(s='abc').save()
-        Bug57Table(s='abc').save()
-        Bug57Table(s='abc').save()
-        Bug57Table(s='def').save()
-        Bug57Table(s='def').save()
-        Bug57Table(s='fgh').save()
-        Bug57Table(s='fgh').save()
-        Bug57Table(s='fgh').save()
-        Bug57Table(s='fgh').save()
-        Bug57Table(s='ijk').save()
-        Bug57Table(s='ijk').save()
-        Bug57Table(s='xyz').save()
-        
-        stuff = list(Bug57Table.objects.all().distinct()[2:4])
-        self.assertEquals(len(stuff), 2)
-
-
-class Bug46Table(models.Model):
-    s = models.CharField(max_length=10)
-
-class Bug46TestCase(TestCase):
-    def testAllDistinctLimit(self):
-        Bug46Table(s='abc').save()
-        Bug46Table(s='abc').save()
-        Bug46Table(s='abc').save()
-        Bug46Table(s='def').save()
-        Bug46Table(s='fgh').save()
-        Bug46Table(s='fgh').save()
-        Bug46Table(s='fgh').save()
-        Bug46Table(s='fgh').save()
-        Bug46Table(s='xyz').save()
-        
-        stuff = list(Bug46Table.objects.all().distinct()[:2])
-        self.assertEquals(len(stuff), 2)
-        
-
 class Bug38Table(models.Model):
     d = models.DecimalField(max_digits=5, decimal_places=2)
 

tests/test_main/slicing/models.py

     def __repr__(self):
         return '<FirstTable %s: %s, %s>' % (self.pk, self.b, self.c)
 
+
 class SecondTable(models.Model):
     a = models.ForeignKey(FirstTable)
     b = models.CharField(max_length=100)
     def __repr__(self):
         return '<FirstTable %s: %s, %s>' % (self.pk, self.a_id, self.b)
 
-# Test slicing
+
 class Products(models.Model):
     """
     >>> names=['D', 'F', 'B', 'A', 'C', 'E', 'G']
         
     def __unicode__(self):
         return "<Product %u: %u>" % (self.productid, self.name)
+
         
 class PagingTestCase(TestCase):
     """The Paginator uses slicing internally."""
         
         for i in (1,2,3):
             self.try_page(i, q)
+
+
+class LimitDistinctTable(models.Model):
+    s = models.CharField(max_length=10)
+
+
+class LimitDistinctTestCase(TestCase):
+    def testLimitDistinct(self):
+        T = LimitDistinctTable
+        T(s='abc').save()
+        T(s='abc').save()
+        T(s='abc').save()
+        T(s='def').save()
+        T(s='def').save()
+        T(s='fgh').save()
+        T(s='fgh').save()
+        T(s='fgh').save()
+        T(s='fgh').save()
+        T(s='ijk').save()
+        T(s='ijk').save()
+        T(s='xyz').save()
+        
+        baseQ = T.objects.values_list('s', flat=True).distinct()
+        
+        stuff = list(baseQ)
+        self.assertEquals(len(stuff), 5)
+        
+        stuff = list(baseQ[:2])
+        self.assertEquals(stuff, [u'abc', u'def'])
+
+        stuff = list(baseQ[3:])
+        self.assertEquals(stuff, [u'ijk', u'xyz'])
+
+        stuff = list(baseQ[2:4])
+        self.assertEquals(stuff, [u'fgh', u'ijk'])
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.