[server/test] Extract a "ldapsource" function in unittest_ldapsource.py 3.25
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 05 Apr 2017 14:42:30 +0200
branch3.25
changeset 12136 6069ee7d4824
parent 12135 e814ba7e51dc
child 12137 4db0f2251960
[server/test] Extract a "ldapsource" function in unittest_ldapsource.py We will add more use of this pattern in forthcoming changesets, so avoid repetition.
cubicweb/server/test/unittest_ldapsource.py
--- a/cubicweb/server/test/unittest_ldapsource.py	Tue Apr 04 16:07:52 2017 +0200
+++ b/cubicweb/server/test/unittest_ldapsource.py	Wed Apr 05 14:42:30 2017 +0200
@@ -111,6 +111,10 @@
         pass
 
 
+def ldapsource(cnx):
+    return cnx.find('CWSource', type=u'ldapfeed').one()
+
+
 class LDAPFeedTestBase(CubicWebTC):
     test_db_id = 'ldap-feed'
     loglevel = 'ERROR'
@@ -217,7 +221,7 @@
 
     def test_wrong_group(self):
         with self.admin_access.repo_cnx() as cnx:
-            source = cnx.execute('CWSource S WHERE S type="ldapfeed"').get_entity(0, 0)
+            source = ldapsource(cnx)
             config = source.repo_source.check_config(source)
             # inject a bogus group here, along with at least a valid one
             config['user-default-group'] = ('thisgroupdoesnotexists', 'users')
@@ -327,7 +331,7 @@
         """ filtered out people should be deactivated, unable to authenticate """
         repo_source = self.repo.sources_by_uri['ldap']
         with self.admin_access.repo_cnx() as cnx:
-            source = cnx.execute('CWSource S WHERE S type="ldapfeed"').get_entity(0, 0)
+            source = ldapsource(cnx)
             config = repo_source.check_config(source)
             # filter with adim's phone number
             config['user-filter'] = u'(%s=%s)' % ('telephoneNumber', '109')