qs = LdapGroup.objects.all()
self.assertEquals(len(qs), 3)
+ def test_ldap_filter(self):
+ qs = LdapGroup.objects.filter(name='foogroup')
+ self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(cn=foogroup))')
+
+ qs = LdapGroup.objects.filter(name='foogroup', gid=1000)
+ self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(&(gidNumber=1000)(cn=foogroup)))')
+
+ qs = LdapGroup.objects.exclude(name='foogroup')
+ self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(!(cn=foogroup)))')
+
+ qs = LdapGroup.objects.exclude(name='foogroup', gid=1000)
+ self.assertEquals(qs.query._ldap_filter(), '(&(objectClass=posixGroup)(!(&(gidNumber=1000)(cn=foogroup))))')
+
def test_filter(self):
qs = LdapGroup.objects.filter(name='foogroup')
self.assertEquals(qs.count(), 1)
else:
clause = '(|%s)' % ''.join(equal_bits)
- if self.negated:
- bits.append('(!%s)' % clause)
- else:
- bits.append(clause)
+ bits.append(clause)
+
+ if not len(bits):
+ return '', []
+
if len(bits) == 1:
sql_string = bits[0]
elif self.connector == AND:
sql_string = '(|%s)' % ''.join(bits)
else:
raise Exception("Unhandled WHERE connector: %s" % self.connector)
+
+ if self.negated:
+ sql_string = ('(!%s)' % sql_string)
+
return sql_string, []
class Query(BaseQuery):