X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=ldapdb%2Ftests.py;h=fdcba594b9e1a56ac18067c45a42b017006bc1fd;hb=c92a7be6f574fceac92e13b5805aebdbc31c281e;hp=d64ff4625a354ee00796591174db70cdb27b1ea9;hpb=2af7bbb69791fc49de3bb91c5ce77c846434b53e;p=matthijs%2Fupstream%2Fdjango-ldapdb.git diff --git a/ldapdb/tests.py b/ldapdb/tests.py index d64ff46..fdcba59 100644 --- a/ldapdb/tests.py +++ b/ldapdb/tests.py @@ -21,35 +21,58 @@ from django.test import TestCase from django.db.models.sql.where import Constraint, AND, OR +from ldapdb.models.query import escape_ldap_filter +from ldapdb.models.fields import CharField, IntegerField from ldapdb.models.query import WhereNode class WhereTestCase(TestCase): - def test_single(self): + def test_escape(self): + self.assertEquals(escape_ldap_filter('foo*bar'), 'foo\\2abar') + self.assertEquals(escape_ldap_filter('foo(bar'), 'foo\\28bar') + self.assertEquals(escape_ldap_filter('foo)bar'), 'foo\\29bar') + self.assertEquals(escape_ldap_filter('foo\\bar'), 'foo\\5cbar') + self.assertEquals(escape_ldap_filter('foo\\bar*wiz'), 'foo\\5cbar\\2awiz') + + def test_char_field(self): where = WhereNode() - where.add((Constraint("cn", "cn", None), 'exact', "test"), AND) + where.add((Constraint("cn", "cn", CharField()), 'exact', "test"), AND) self.assertEquals(where.as_sql(), "(cn=test)") where = WhereNode() - where.add((Constraint("cn", "cn", None), 'startswith', "test"), AND) + where.add((Constraint("cn", "cn", CharField()), 'startswith', "test"), AND) self.assertEquals(where.as_sql(), "(cn=test*)") where = WhereNode() - where.add((Constraint("cn", "cn", None), 'endswith', "test"), AND) + where.add((Constraint("cn", "cn", CharField()), 'endswith', "test"), AND) self.assertEquals(where.as_sql(), "(cn=*test)") where = WhereNode() - where.add((Constraint("cn", "cn", None), 'in', ["foo", "bar"]), AND) + where.add((Constraint("cn", "cn", CharField()), 'in', ["foo", "bar"]), AND) self.assertEquals(where.as_sql(), "(|(cn=foo)(cn=bar))") + where = WhereNode() + where.add((Constraint("cn", "cn", CharField()), 'contains', "test"), AND) + self.assertEquals(where.as_sql(), "(cn=*test*)") + + def test_integer_field(self): + where = WhereNode() + where.add((Constraint("uid", "uid", CharField()), 'exact', 1), AND) + self.assertEquals(where.as_sql(), "(uid=1)") + + def test_escaped(self): + where = WhereNode() + where.add((Constraint("cn", "cn", CharField()), 'exact', "(test)"), AND) + self.assertEquals(where.as_sql(), "(cn=\\28test\\29)") + def test_and(self): where = WhereNode() - where.add((Constraint("cn", "cn", None), 'exact', "foo"), AND) - where.add((Constraint("givenName", "givenName", None), 'exact', "bar"), AND) + where.add((Constraint("cn", "cn", CharField()), 'exact', "foo"), AND) + where.add((Constraint("givenName", "givenName", CharField()), 'exact', "bar"), AND) self.assertEquals(where.as_sql(), "(&(cn=foo)(givenName=bar))") def test_or(self): where = WhereNode() - where.add((Constraint("cn", "cn", None), 'exact', "foo"), AND) - where.add((Constraint("givenName", "givenName", None), 'exact', "bar"), OR) + where.add((Constraint("cn", "cn", CharField()), 'exact', "foo"), AND) + where.add((Constraint("givenName", "givenName", CharField()), 'exact', "bar"), OR) self.assertEquals(where.as_sql(), "(|(cn=foo)(givenName=bar))")