add some tests for different field types
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 31 May 2010 13:19:14 +0000 (13:19 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 31 May 2010 13:19:14 +0000 (13:19 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@882 e071eeec-0327-468d-9b6a-08194a12b294

examples/tests.py
ldapdb/__init__.py
ldapdb/models/query.py

index 38a122ab05d2c95a0b3996efb957cf76673d179d..d0f179807f0a111ce411d4266d69a72ce9cbef9e 100644 (file)
@@ -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')
+
index 7f11e6739637925b8b48d7dcc42c434ec1cc1abb..d1dcc47d05012a4260431dcabc6b2b3ffe306068 100644 (file)
@@ -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
 
index 069c237916f515b8b51bd4c909b5a054bf8cf532..55576a6b4be1c44cb8427e49aff7c3eb29e4b42a 100644 (file)
@@ -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):