--- a/server/test/unittest_ldapuser.py Sat Oct 09 00:05:50 2010 +0200
+++ b/server/test/unittest_ldapuser.py Sat Oct 09 00:05:52 2010 +0200
@@ -20,7 +20,6 @@
import socket
from logilab.common.testlib import TestCase, unittest_main, mock_object
-from cubicweb.devtools import TestServerConfiguration
from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.devtools.repotest import RQLGeneratorTC
@@ -53,25 +52,51 @@
# don't check upassword !
return self.extid2eid(user['dn'], 'CWUser', session)
+def setup_module(*args):
+ global repo
+ LDAPUserSourceTC._init_repo()
+ repo = LDAPUserSourceTC.repo
+ add_ldap_source(LDAPUserSourceTC.cnx)
+
+def teardown_module(*args):
+ global repo
+ repo.shutdown()
+ del repo
+
+def add_ldap_source(cnx):
+ cnx.request().create_entity('CWSource', name=u'ldapuser', type=u'ldapuser',
+ config=u'''
+# ldap host
+host=ldap1
+# base DN to lookup for usres
+user-base-dn=ou=People,dc=logilab,dc=fr
+# user search scope
+user-scope=ONELEVEL
+# classes of user
+user-classes=top,posixAccount
+# attribute used as login on authentication
+user-login-attr=uid
+# name of a group in which ldap users will be by default
+user-default-group=users
+# map from ldap user attributes to cubicweb attributes
+user-attrs-map=gecos:email,uid:login
+''')
+ cnx.commit()
+ # XXX: need this first query else we get 'database is locked' from
+ # sqlite since it doesn't support multiple connections on the same
+ # database
+ # so doing, ldap inserted users don't get removed between each test
+ rset = cnx.cursor().execute('CWUser X')
+ # check we get some users from ldap
+ assert len(rset) > 1
class LDAPUserSourceTC(CubicWebTC):
- config = TestServerConfiguration('data')
- config.sources_file = lambda : 'data/sourcesldap'
def patch_authenticate(self):
self._orig_authenticate = LDAPUserSource.authenticate
LDAPUserSource.authenticate = nopwd_authenticate
- def setup_database(self):
- # XXX: need this first query else we get 'database is locked' from
- # sqlite since it doesn't support multiple connections on the same
- # database
- # so doing, ldap inserted users don't get removed between each test
- rset = self.sexecute('CWUser X')
- # check we get some users from ldap
- self.assert_(len(rset) > 1)
-
def tearDown(self):
if hasattr(self, '_orig_authenticate'):
LDAPUserSource.authenticate = self._orig_authenticate
@@ -378,19 +403,10 @@
res = trfunc.apply([[1, 2], [2, 4], [3, 6], [1, 5]])
self.assertEqual(res, [[1, 5], [2, 4], [3, 6]])
-# XXX
-LDAPUserSourceTC._init_repo()
-repo = LDAPUserSourceTC.repo
-
-def teardown_module(*args):
- global repo
- del repo
- del RQL2LDAPFilterTC.schema
-
class RQL2LDAPFilterTC(RQLGeneratorTC):
- schema = repo.schema
def setUp(self):
+ self.schema = repo.schema
RQLGeneratorTC.setUp(self)
ldapsource = repo.sources[-1]
self.pool = repo._get_pool()