From: jlaine Date: Mon, 27 Dec 2010 12:13:09 +0000 (+0000) Subject: add more filter tests X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=1cbff9629c9af335cc485b0c2a5ef60ec20e87e9;p=matthijs%2Fupstream%2Fdjango-ldapdb.git add more filter tests git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@968 e071eeec-0327-468d-9b6a-08194a12b294 --- diff --git a/examples/tests.py b/examples/tests.py index bd47291..60f2abc 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -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)