test ordering
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 31 May 2010 18:37:26 +0000 (18:37 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 31 May 2010 18:37:26 +0000 (18:37 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@904 e071eeec-0327-468d-9b6a-08194a12b294

examples/tests.py

index 70d53e3840a76f177475a994f5a785c1c740b0d6..533df5c04dbbda6bdec0b44de51f96085107d230 100644 (file)
@@ -78,6 +78,7 @@ class GroupTestCase(BaseTestCase):
         self.assertEquals(g.gid, 1000)
         self.assertEquals(g.usernames, ['foouser', 'baruser'])
 
+        # try to get non-existent entry
         qs = LdapGroup.objects.filter(name='does_not_exist')
         self.assertEquals(len(qs), 0)
 
@@ -90,6 +91,31 @@ class GroupTestCase(BaseTestCase):
 
         self.assertRaises(LdapGroup.DoesNotExist, LdapGroup.objects.get, name='does_not_exist')
 
+    def test_order_by(self):
+        # ascending name 
+        qs = LdapGroup.objects.order_by('name')
+        self.assertEquals(len(qs), 2)
+        self.assertEquals(qs[0].name, 'bargroup')
+        self.assertEquals(qs[1].name, 'foogroup')
+
+        # descending name 
+        qs = LdapGroup.objects.order_by('-name')
+        self.assertEquals(len(qs), 2)
+        self.assertEquals(qs[0].name, 'foogroup')
+        self.assertEquals(qs[1].name, 'bargroup')
+
+        # ascending gid
+        qs = LdapGroup.objects.order_by('gid')
+        self.assertEquals(len(qs), 2)
+        self.assertEquals(qs[0].gid, 1000)
+        self.assertEquals(qs[1].gid, 1001)
+
+        # descending gid
+        qs = LdapGroup.objects.order_by('-gid')
+        self.assertEquals(len(qs), 2)
+        self.assertEquals(qs[0].gid, 1001)
+        self.assertEquals(qs[1].gid, 1000)
+
     def test_update(self):
         g = LdapGroup.objects.get(name='foogroup')