From: jlaine Date: Mon, 31 May 2010 13:19:14 +0000 (+0000) Subject: add some tests for different field types X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=6035af62fccb4c3f623fd5be0072281f953790f5;p=matthijs%2Fupstream%2Fdjango-ldapdb.git add some tests for different field types git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@882 e071eeec-0327-468d-9b6a-08194a12b294 --- diff --git a/examples/tests.py b/examples/tests.py index 38a122a..d0f1798 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -48,8 +48,16 @@ class GroupTestCase(BaseTestCase): g = LdapGroup() g.name = "foogroup" g.gid = 1000 - g.usernames = ['foouser'] + g.usernames = ['foouser', 'baruser'] g.save() + + def test_get(self): + self.test_create() + + g = LdapGroup.objects.get(name='foogroup') + self.assertEquals(g.name, 'foogroup') + self.assertEquals(g.gid, 1000) + self.assertEquals(g.usernames, ['foouser', 'baruser']) class UserTestCase(BaseTestCase): def test_create(self): @@ -63,4 +71,17 @@ class UserTestCase(BaseTestCase): u.uid = 1000 u.username = "foouser" u.save() + + def test_get(self): + self.test_create() + + u = LdapUser.objects.get(username='foouser') + self.assertEquals(u.first_name, 'Foo') + self.assertEquals(u.last_name, 'User') + self.assertEquals(u.full_name, 'Foo User') + self.assertEquals(u.group, 1000) + self.assertEquals(u.home_directory, '/home/foouser') + self.assertEquals(u.uid, 1000) + self.assertEquals(u.username, 'foouser') + diff --git a/ldapdb/__init__.py b/ldapdb/__init__.py index 7f11e67..d1dcc47 100644 --- a/ldapdb/__init__.py +++ b/ldapdb/__init__.py @@ -100,11 +100,7 @@ class LdapConnection(object): output = [] for dn, attrs in results: for field in attrs: - # FIXME : we should not reference the attribute name! - if field == "member" or field == "memberUid": - attrs[field] = convert(field, attrs[field], lambda x: x.decode(self.charset)) - else: - attrs[field] = convert(field, attrs[field][0], lambda x: x.decode(self.charset)) + attrs[field] = convert(field, attrs[field], lambda x: x.decode(self.charset)) output.append((dn.decode(self.charset), attrs)) return output diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index 069c237..55576a6 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -28,7 +28,7 @@ from django.db.models.sql.where import WhereNode as BaseWhereNode, Constraint as import ldapdb -from ldapdb.models.fields import CharField +from ldapdb.models.fields import CharField, Integer, ListField def get_lookup_operator(lookup_type): if lookup_type == 'gte': @@ -185,8 +185,12 @@ class Query(BaseQuery): for field in iter(self.model._meta.fields): if field.attname == 'dn': row.append(dn) + elif isinstance(field, IntegerField): + row.append(int(attrs.get(field.db_column, [0])[0])) + elif isinstance(field, ListField): + row.append(attrs.get(field.db_column, [])) else: - row.append(attrs.get(field.db_column, None)) + row.append(attrs.get(field.db_column, [''])[0]) yield row class QuerySet(BaseQuerySet):