From 089876639ebce60a85a285d7ab076797fa96c20c Mon Sep 17 00:00:00 2001 From: jlaine Date: Mon, 24 May 2010 10:07:58 +0000 Subject: [PATCH] test list field git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@870 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/models/fields.py | 20 ++++++++++++++++++-- ldapdb/tests.py | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ldapdb/models/fields.py b/ldapdb/models/fields.py index 921923c..5e85062 100644 --- a/ldapdb/models/fields.py +++ b/ldapdb/models/fields.py @@ -59,19 +59,35 @@ class CharField(fields.CharField): class ImageField(fields.Field): def get_db_prep_lookup(self, lookup_type, value): + "Returns field's value prepared for database lookup." + return [self.get_prep_lookup(lookup_type, value)] + + def get_prep_lookup(self, lookup_type, value): + "Perform preliminary non-db specific lookup checks and conversions" raise TypeError("ImageField has invalid lookup: %s" % lookup_type) class IntegerField(fields.IntegerField): def get_db_prep_lookup(self, lookup_type, value): - if lookup_type in ('exact', 'gte', 'lte'): - return [value] + "Returns field's value prepared for database lookup." + return [self.get_prep_lookup(lookup_type, value)] + def get_prep_lookup(self, lookup_type, value): + "Perform preliminary non-db specific lookup checks and conversions" + if lookup_type in ('exact', 'gte', 'lte'): + return value raise TypeError("IntegerField has invalid lookup: %s" % lookup_type) class ListField(fields.Field): __metaclass__ = SubfieldBase def get_db_prep_lookup(self, lookup_type, value): + "Returns field's value prepared for database lookup." + return [self.get_prep_lookup(lookup_type, value)] + + def get_prep_lookup(self, lookup_type, value): + "Perform preliminary non-db specific lookup checks and conversions" + if lookup_type == 'contains': + return escape_ldap_filter(value) raise TypeError("ListField has invalid lookup: %s" % lookup_type) def to_python(self, value): diff --git a/ldapdb/tests.py b/ldapdb/tests.py index f9c4b16..6d5c8b5 100644 --- a/ldapdb/tests.py +++ b/ldapdb/tests.py @@ -91,6 +91,11 @@ class WhereTestCase(TestCase): where.add((Constraint("uid", "uid", IntegerField()), 'lte', 1), AND) 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)") + def test_and(self): where = WhereNode() where.add((Constraint("cn", "cn", CharField()), 'exact', "foo"), AND) -- 2.30.2