[devtools] Fix database creation issues for CubicWebServerTC tests
authorRémi Cardona <remi.cardona@logilab.fr>
Mon, 21 Dec 2015 09:55:14 +0100
changeset 11015 baf463175505
parent 11014 9c9f5e913f9c
child 11016 d04703f54510
[devtools] Fix database creation issues for CubicWebServerTC tests To reproduce (with a purged repo): * python web/test/unittest_web.py MiscOptionsTC * python web/test/unittest_views_xmlrss.py The core issue is that CubicWebServerConfig.default_base_url() is called inside init_config(), which is called during the equivalent of 'db-create'. The '__default_empty_db__' will contain the wrong 'base_url' configuration, thus breaking URLs in the xmlrss tests. Related to #9297611.
devtools/httptest.py
web/test/unittest_web.py
--- a/devtools/httptest.py	Mon Dec 21 09:59:45 2015 +0100
+++ b/devtools/httptest.py	Mon Dec 21 09:55:14 2015 +0100
@@ -62,30 +62,11 @@
     raise RuntimeError('get_available_port([ports_range]) cannot find an available port')
 
 
-class CubicWebServerConfig(ApptestConfiguration):
-    """basic configuration class for configuring test server
-
-    Class attributes:
-
-    * `ports_range`: list giving range of http ports to test (range(7000, 8000)
-      by default). The first port found as available in `ports_range` will be
-      used to launch the test web server.
-
+class CubicWebServerTC(CubicWebTC):
+    """Class for running a Twisted-based test web server.
     """
     ports_range = range(7000, 8000)
 
-    def default_base_url(self):
-        port = self['port'] or get_available_port(self.ports_range)
-        self.global_set_option('port', port) # force rewrite here
-        return 'http://127.0.0.1:%d/' % self['port']
-
-
-
-class CubicWebServerTC(CubicWebTC):
-    """Class for running test web server. See :class:`CubicWebServerConfig`.
-    """
-    configcls = CubicWebServerConfig
-
     def start_server(self):
         from twisted.internet import reactor
         from cubicweb.etwist.server import run
@@ -172,6 +153,11 @@
 
     def setUp(self):
         super(CubicWebServerTC, self).setUp()
+        port = self.config['port'] or get_available_port(self.ports_range)
+        self.config.global_set_option('port', port) # force rewrite here
+        self.config.global_set_option('base-url', 'http://127.0.0.1:%d/' % port)
+        # call load_configuration again to let the config reset its datadir_url
+        self.config.load_configuration()
         self.start_server()
 
     def tearDown(self):
--- a/web/test/unittest_web.py	Mon Dec 21 09:59:45 2015 +0100
+++ b/web/test/unittest_web.py	Mon Dec 21 09:55:14 2015 +0100
@@ -128,13 +128,16 @@
 
 class MiscOptionsTC(CubicWebServerTC):
     @classmethod
-    def init_config(cls, config):
-        super(MiscOptionsTC, cls).init_config(config)
+    def setUpClass(cls):
+        super(MiscOptionsTC, cls).setUpClass()
         cls.logfile = tempfile.NamedTemporaryFile()
-        config.global_set_option('query-log-file', cls.logfile.name)
-        config.global_set_option('datadir-url', '//static.testing.fr/')
+
+    def setUp(self):
+        super(MiscOptionsTC, self).setUp()
+        self.config.global_set_option('query-log-file', self.logfile.name)
+        self.config.global_set_option('datadir-url', '//static.testing.fr/')
         # call load_configuration again to let the config reset its datadir_url
-        config.load_configuration()
+        self.config.load_configuration()
 
     def test_log_queries(self):
         self.web_request()
@@ -146,6 +149,7 @@
 
     @classmethod
     def tearDownClass(cls):
+        super(MiscOptionsTC, cls).tearDownClass()
         cls.logfile.close()