[server] Drop update_config method of source 3.25
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 05 Apr 2017 14:02:58 +0200
branch3.25
changeset 12143 a446124bcf3c
parent 12142 db2fc87348ab
child 12144 f54286c1cef5
[server] Drop update_config method of source It does not make sense anymore to update the config of a source instance (subclass of cubicweb.server.sources.AbstractSource) now that they are always built from database information (CWSource). In datafeed and ldapfeed, we move all code from "update_config" method in "init" method. This changeset fixes LDAPFeedUserDeletionTC.test_a_filter_inactivate() failure (unittest_ldapsource.py) introduces in previous changeset.
cubicweb/server/sources/__init__.py
cubicweb/server/sources/datafeed.py
cubicweb/server/sources/ldapfeed.py
cubicweb/server/test/unittest_ldapsource.py
--- a/cubicweb/server/sources/__init__.py	Tue Apr 04 16:28:50 2017 +0200
+++ b/cubicweb/server/sources/__init__.py	Wed Apr 05 14:02:58 2017 +0200
@@ -99,8 +99,8 @@
         # on logging
         set_log_methods(self, getLogger('cubicweb.sources.' + unormalize(text_type(self.uri))))
         source_config.pop('type')
-        self.update_config(None, self.check_conf_dict(eid, source_config,
-                                                      fail_if_unknown=False))
+        self.config = self.check_conf_dict(
+            eid, source_config, fail_if_unknown=False)
 
     def __repr__(self):
         return '<%s %s source %s @%#x>' % (self.uri, self.__class__.__name__,
@@ -176,14 +176,6 @@
         return cls.check_conf_dict(source_entity.eid, source_entity.host_config,
                                     _=source_entity._cw._)
 
-    def update_config(self, source_entity, typedconfig):
-        """update configuration from source entity. `typedconfig` is config
-        properly typed with defaults set
-        """
-        if source_entity is not None:
-            self._entity_update(source_entity)
-        self.config = typedconfig
-
     def _entity_update(self, source_entity):
         source_entity.complete()
         if source_entity.url:
--- a/cubicweb/server/sources/datafeed.py	Tue Apr 04 16:28:50 2017 +0200
+++ b/cubicweb/server/sources/datafeed.py	Wed Apr 05 14:02:58 2017 +0200
@@ -112,11 +112,10 @@
         self.parser_id = source_entity.parser
         self.latest_retrieval = source_entity.latest_retrieval
 
-    def update_config(self, source_entity, typed_config):
-        """update configuration from source entity. `typed_config` is config
-        properly typed with defaults set
-        """
-        super(DataFeedSource, self).update_config(source_entity, typed_config)
+    def init(self, activated, source_entity):
+        super(DataFeedSource, self).init(activated, source_entity)
+        self.parser_id = source_entity.parser
+        typed_config = self.config
         self.synchro_interval = timedelta(seconds=typed_config['synchronization-interval'])
         self.max_lock_lifetime = timedelta(seconds=typed_config['max-lock-lifetime'])
         self.http_timeout = typed_config['http-timeout']
@@ -127,10 +126,6 @@
             self.use_cwuri_as_url = typed_config['use-cwuri-as-url']
             self.public_config['use-cwuri-as-url'] = self.use_cwuri_as_url
 
-    def init(self, activated, source_entity):
-        super(DataFeedSource, self).init(activated, source_entity)
-        self.parser_id = source_entity.parser
-
     def _get_parser(self, cnx, **kwargs):
         if self.parser_id is None:
             self.warning('No parser defined on source %r', self)
--- a/cubicweb/server/sources/ldapfeed.py	Tue Apr 04 16:28:50 2017 +0200
+++ b/cubicweb/server/sources/ldapfeed.py	Wed Apr 05 14:02:58 2017 +0200
@@ -176,11 +176,9 @@
 
     _conn = None
 
-    def update_config(self, source_entity, typedconfig):
-        """update configuration from source entity. `typedconfig` is config
-        properly typed with defaults set
-        """
-        super(LDAPFeedSource, self).update_config(source_entity, typedconfig)
+    def init(self, activated, source_entity):
+        super(LDAPFeedSource, self).init(activated, source_entity)
+        typedconfig = self.config
         self.authmode = typedconfig['auth-mode']
         self._authenticate = getattr(self, '_auth_%s' % self.authmode)
         self.cnx_dn = typedconfig['data-cnx-dn']
--- a/cubicweb/server/test/unittest_ldapsource.py	Tue Apr 04 16:28:50 2017 +0200
+++ b/cubicweb/server/test/unittest_ldapsource.py	Wed Apr 05 14:02:58 2017 +0200
@@ -115,6 +115,12 @@
     return cnx.find('CWSource', type=u'ldapfeed').one()
 
 
+def update_source_config(source, options):
+    config = source.dictconfig
+    config.update(options)
+    source.cw_set(config=u'\n'.join('%s=%s' % x for x in config.items()))
+
+
 class LDAPFeedTestBase(CubicWebTC):
     test_db_id = 'ldap-feed'
     loglevel = 'ERROR'
@@ -222,10 +228,9 @@
     def test_wrong_group(self):
         with self.admin_access.repo_cnx() as cnx:
             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')
-            source.repo_source.update_config(source, config)
+            options = {'use-default-group': 'thisgroupdoesnotexists,users'}
+            update_source_config(source, options)
             cnx.commit()
             # here we emitted an error log entry
             source.repo_source.pull_data(cnx, force=True, raise_on_error=True)
@@ -329,16 +334,15 @@
 
     def test_a_filter_inactivate(self):
         """ 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 = ldapsource(cnx)
-            config = repo_source.check_config(source)
             # filter with adim's phone number
-            config['user-filter'] = u'(%s=%s)' % ('telephoneNumber', '109')
-            repo_source.update_config(source, config)
+            options = {'user-filter': '(%s=%s)' % ('telephonenumber', '109')}
+            update_source_config(source, options)
             cnx.commit()
         with self.repo.internal_cnx() as cnx:
             self.pull(cnx)
+            repo_source = self.repo.sources_by_uri['ldap']
             self.assertRaises(AuthenticationError,
                               repo_source.authenticate, cnx, 'syt', 'syt')
         with self.admin_access.repo_cnx() as cnx:
@@ -349,8 +353,9 @@
                                          'U in_state S, S name N').rows[0][0],
                              'activated')
             # unfilter, syt should be activated again
-            config['user-filter'] = u''
-            repo_source.update_config(source, config)
+            source = ldapsource(cnx)
+            options = {'user-filter': u''}
+            update_source_config(source, options)
             cnx.commit()
         with self.repo.internal_cnx() as cnx:
             self.pull(cnx)