+ def test_escape(self):
+ self.assertEquals(escape_ldap_filter(u'fôöbàr'), u'fôöbàr')
+ 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_exact(self):
+ where = WhereNode()
+ where.add((Constraint("cn", "cn", CharField()), 'exact', "test"), AND)
+ self.assertEquals(where_as_ldap(where), ("(cn=test)", []))
+
+ where = WhereNode()
+ where.add((Constraint("cn", "cn", CharField()), 'exact', "(test)"), AND)
+ self.assertEquals(where_as_ldap(where), ("(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_ldap(where), ("(|(cn=foo)(cn=bar))", []))
+
+ where = WhereNode()
+ where.add((Constraint("cn", "cn", CharField()), 'in', ["(foo)", "(bar)"]), AND)
+ self.assertEquals(where_as_ldap(where), ("(|(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_ldap(where), ("(cn=test*)", []))
+
+ where = WhereNode()
+ where.add((Constraint("cn", "cn", CharField()), 'startswith', "te*st"), AND)
+ self.assertEquals(where_as_ldap(where), ("(cn=te\\2ast*)", []))
+
+ def test_char_field_endswith(self):
+ where = WhereNode()
+ where.add((Constraint("cn", "cn", CharField()), 'endswith', "test"), AND)
+ self.assertEquals(where_as_ldap(where), ("(cn=*test)", []))
+
+ where = WhereNode()
+ where.add((Constraint("cn", "cn", CharField()), 'endswith', "te*st"), AND)
+ self.assertEquals(where_as_ldap(where), ("(cn=*te\\2ast)", []))
+
+ def test_char_field_contains(self):
+ where = WhereNode()
+ where.add((Constraint("cn", "cn", CharField()), 'contains', "test"), AND)
+ self.assertEquals(where_as_ldap(where), ("(cn=*test*)", []))
+
+ where = WhereNode()
+ where.add((Constraint("cn", "cn", CharField()), 'contains', "te*st"), AND)
+ self.assertEquals(where_as_ldap(where), ("(cn=*te\\2ast*)", []))
+
+ def test_integer_field(self):
+ where = WhereNode()
+ where.add((Constraint("uid", "uid", IntegerField()), 'exact', 1), AND)
+ self.assertEquals(where_as_ldap(where), ("(uid=1)", []))
+
+ where = WhereNode()
+ where.add((Constraint("uid", "uid", IntegerField()), 'gte', 1), AND)
+ self.assertEquals(where_as_ldap(where), ("(uid>=1)", []))
+