add more filter tests
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 27 Dec 2010 12:13:09 +0000 (12:13 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 27 Dec 2010 12:13:09 +0000 (12:13 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@968 e071eeec-0327-468d-9b6a-08194a12b294

examples/tests.py

index bd47291b0fc55949a897973dcf49e8319625210c..60f2abc8f26cb2141742df5ccc4a426eccaca506 100644 (file)
@@ -32,6 +32,7 @@
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
+from django.db.models import Q
 from django.test import TestCase
 
 import ldap
@@ -98,18 +99,38 @@ class GroupTestCase(BaseTestCase):
         self.assertEquals(len(qs), 3)
 
     def test_ldap_filter(self):
+        # single filter
         qs = LdapGroup.objects.filter(name='foogroup')
         self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(cn=foogroup))')
 
-        qs = LdapGroup.objects.filter(name='foogroup', gid=1000)
+        qs = LdapGroup.objects.filter(Q(name='foogroup'))
+        self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(cn=foogroup))')
+
+        # AND filter
+        qs = LdapGroup.objects.filter(gid=1000, name='foogroup')
+        self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(&(gidNumber=1000)(cn=foogroup)))')
+
+        qs = LdapGroup.objects.filter(Q(gid=1000) & Q(name='foogroup'))
         self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(&(gidNumber=1000)(cn=foogroup)))')
 
+        # OR filter
+        qs = LdapGroup.objects.filter(Q(gid=1000) | Q(name='foogroup'))
+        self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(|(gidNumber=1000)(cn=foogroup)))')
+
+        # single exclusion
         qs = LdapGroup.objects.exclude(name='foogroup')
         self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(!(cn=foogroup)))')
         
+        qs = LdapGroup.objects.filter(~Q(name='foogroup'))
+        self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(!(cn=foogroup)))')
+
+        # multiple exclusion
         qs = LdapGroup.objects.exclude(name='foogroup', gid=1000)
         self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(!(&(gidNumber=1000)(cn=foogroup))))')
 
+        qs = LdapGroup.objects.filter(name='foogroup').exclude(gid=1000)
+        self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(&(cn=foogroup)(!(gidNumber=1000))))')
+
     def test_filter(self):
         qs = LdapGroup.objects.filter(name='foogroup')
         self.assertEquals(qs.count(), 1)