X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=ldapdb%2Ftests.py;h=cf8bc8019beef9efbd9be597ad85ebc60038f975;hb=6035af62fccb4c3f623fd5be0072281f953790f5;hp=10b7c5bd347f02db01691a0789ce7e557b8987cb;hpb=c691191aa52b340fd060957aeaf3d53594074a00;p=matthijs%2Fupstream%2Fdjango-ldapdb.git diff --git a/ldapdb/tests.py b/ldapdb/tests.py index 10b7c5b..cf8bc80 100644 --- a/ldapdb/tests.py +++ b/ldapdb/tests.py @@ -33,61 +33,82 @@ class WhereTestCase(TestCase): 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): + def test_char_field_exact(self): where = WhereNode() where.add((Constraint("cn", "cn", CharField()), 'exact', "test"), AND) - self.assertEquals(where.as_sql(), "(cn=test)") + self.assertEquals(where.as_sql(), ("(cn=test)", [])) where = WhereNode() where.add((Constraint("cn", "cn", CharField()), 'exact', "(test)"), AND) - self.assertEquals(where.as_sql(), "(cn=\\28test\\29)") + self.assertEquals(where.as_sql(), ("(cn=\\28test\\29)", [])) + def test_char_field_in(self): where = WhereNode() where.add((Constraint("cn", "cn", CharField()), 'in', ["foo", "bar"]), AND) - self.assertEquals(where.as_sql(), "(|(cn=foo)(cn=bar))") + self.assertEquals(where.as_sql(), ("(|(cn=foo)(cn=bar))", [])) where = WhereNode() where.add((Constraint("cn", "cn", CharField()), 'in', ["(foo)", "(bar)"]), AND) - self.assertEquals(where.as_sql(), "(|(cn=\\28foo\\29)(cn=\\28bar\\29))") + self.assertEquals(where.as_sql(), ("(|(cn=\\28foo\\29)(cn=\\28bar\\29))", [])) + def test_char_field_startswith(self): where = WhereNode() where.add((Constraint("cn", "cn", CharField()), 'startswith', "test"), AND) - self.assertEquals(where.as_sql(), "(cn=test*)") + self.assertEquals(where.as_sql(), ("(cn=test*)", [])) + where = WhereNode() + where.add((Constraint("cn", "cn", CharField()), 'startswith', "te*st"), AND) + self.assertEquals(where.as_sql(), ("(cn=te\\2ast*)", [])) + + def test_char_field_endswith(self): where = WhereNode() where.add((Constraint("cn", "cn", CharField()), 'endswith', "test"), AND) - self.assertEquals(where.as_sql(), "(cn=*test)") + self.assertEquals(where.as_sql(), ("(cn=*test)", [])) where = WhereNode() - where.add((Constraint("cn", "cn", CharField()), 'in', ["foo", "bar"]), AND) - self.assertEquals(where.as_sql(), "(|(cn=foo)(cn=bar))") + where.add((Constraint("cn", "cn", CharField()), 'endswith', "te*st"), AND) + self.assertEquals(where.as_sql(), ("(cn=*te\\2ast)", [])) + def test_char_field_contains(self): where = WhereNode() where.add((Constraint("cn", "cn", CharField()), 'contains', "test"), AND) - self.assertEquals(where.as_sql(), "(cn=*test*)") + self.assertEquals(where.as_sql(), ("(cn=*test*)", [])) + + where = WhereNode() + where.add((Constraint("cn", "cn", CharField()), 'contains', "te*st"), AND) + self.assertEquals(where.as_sql(), ("(cn=*te\\2ast*)", [])) def test_integer_field(self): where = WhereNode() where.add((Constraint("uid", "uid", IntegerField()), 'exact', 1), AND) - self.assertEquals(where.as_sql(), "(uid=1)") + self.assertEquals(where.as_sql(), ("(uid=1)", [])) where = WhereNode() where.add((Constraint("uid", "uid", IntegerField()), 'gte', 1), AND) - self.assertEquals(where.as_sql(), "(uid>=1)") + self.assertEquals(where.as_sql(), ("(uid>=1)", [])) where = WhereNode() where.add((Constraint("uid", "uid", IntegerField()), 'lte', 1), AND) - self.assertEquals(where.as_sql(), "(uid<=1)") + self.assertEquals(where.as_sql(), ("(uid<=1)", [])) + + def test_list_field_contains(self): + where = WhereNode() + where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', 'foouser'), AND) + self.assertEquals(where.as_sql(), ("(memberUid=foouser)", [])) + + where = WhereNode() + where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', '(foouser)'), AND) + self.assertEquals(where.as_sql(), ("(memberUid=\\28foouser\\29)", [])) def test_and(self): where = WhereNode() 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))") + self.assertEquals(where.as_sql(), ("(&(cn=foo)(givenName=bar))", [])) def test_or(self): where = WhereNode() 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))") + self.assertEquals(where.as_sql(), ("(|(cn=foo)(givenName=bar))", []))