From: jlaine Date: Mon, 24 May 2010 08:37:28 +0000 (+0000) Subject: rework tests X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=15ab751beb0021ef73455d55b96eddbf01bcfffb;p=matthijs%2Fupstream%2Fdjango-ldapdb.git rework tests git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@864 e071eeec-0327-468d-9b6a-08194a12b294 --- diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index a8c614f..b8e4897 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -81,15 +81,14 @@ class WhereNode(BaseWhereNode): if isinstance(item, WhereNode): bits.append(item.as_sql()) continue - constraint, x, y, values = item + constraint, lookup_type, y, values = item + comp = get_lookup_operator(lookup_type) if hasattr(constraint, "col"): # django 1.2 - comp = get_lookup_operator(constraint.lookup_type) clause = "(%s%s%s)" % (constraint.col, comp, values) else: # django 1.1 (table, column, db_type) = constraint - comp = get_lookup_operator(x) equal_bits = [ "(%s%s%s)" % (column, comp, value) for value in values ] if len(equal_bits) == 1: clause = equal_bits[0] diff --git a/ldapdb/tests.py b/ldapdb/tests.py index 10b7c5b..b102a3e 100644 --- a/ldapdb/tests.py +++ b/ldapdb/tests.py @@ -33,7 +33,7 @@ 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)") @@ -42,6 +42,7 @@ class WhereTestCase(TestCase): where.add((Constraint("cn", "cn", CharField()), 'exact', "(test)"), AND) 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))") @@ -50,6 +51,7 @@ class WhereTestCase(TestCase): where.add((Constraint("cn", "cn", CharField()), 'in', ["(foo)", "(bar)"]), AND) 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*)") @@ -58,10 +60,7 @@ class WhereTestCase(TestCase): where.add((Constraint("cn", "cn", CharField()), 'endswith', "test"), AND) 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))") - + def test_char_field_contains(self): where = WhereNode() where.add((Constraint("cn", "cn", CharField()), 'contains', "test"), AND) self.assertEquals(where.as_sql(), "(cn=*test*)")