backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 11 Oct 2010 12:27:29 +0200
changeset 6440 9d85f11983b0
parent 6437 d88be69179b8 (current diff)
parent 6439 fe0fb6f95ff0 (diff)
child 6442 ac7126d2cd73
backport stable
devtools/testlib.py
--- a/devtools/cwwindmill.py	Mon Oct 11 12:03:12 2010 +0200
+++ b/devtools/cwwindmill.py	Mon Oct 11 12:27:29 2010 +0200
@@ -35,7 +35,7 @@
 from windmill.dep import functest
 from windmill.bin.admin_lib import configure_global_settings, setup, teardown
 
-from cubicweb.devtools.httptest import CubicWebServerTC
+from cubicweb.devtools.httptest import CubicWebServerTC, CubicWebServerConfig
 
 
 # Excerpt from :ref:`windmill.authoring.unit`
@@ -46,11 +46,6 @@
 unittestreporter = UnitTestReporter()
 functest.reports.register_reporter(unittestreporter)
 
-
-# Windmill use case are written with no anonymous user
-from cubicweb.devtools.httptest import CubicWebServerConfig
-CubicWebServerConfig.anonymous_logged = False
-
 class CubicWebWindmillUseCase(CubicWebServerTC):
     """basic class for Windmill use case tests
 
@@ -86,6 +81,8 @@
     """
     browser = 'firefox'
     edit_test = "-i" in sys.argv # detection for pytest invocation
+    # Windmill use case are written with no anonymous user
+    anonymous_logged = False
 
     def _test_dir(self):
         """access to class attribute if possible or make assumption
--- a/devtools/httptest.py	Mon Oct 11 12:03:12 2010 +0200
+++ b/devtools/httptest.py	Mon Oct 11 12:27:29 2010 +0200
@@ -63,18 +63,13 @@
 class CubicWebServerConfig(ApptestConfiguration):
     """basic configuration class for configuring test server
 
-    :param ports_range: range of http ports to test (range(7000, 8000) by default)
-    :type ports_range: iterable
-    :param anonymous_logged: is anonymous user logged by default ? (True by default)
-    :type anonymous_logged: bool
-    :param port: server port (optional, used to force value)
-    :type port: int
+    Class attributes:
 
-    The first port found as available in `ports_range` will be used to launch
-    the test server
+    * `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.
+
     """
-    # anonymous is logged by default in cubicweb test cases
-    anonymous_logged = True
     ports_range = range(7000, 8000)
 
     def default_base_url(self):
@@ -87,23 +82,19 @@
 
     def load_configuration(self):
         super(CubicWebServerConfig, self).load_configuration()
-        self.global_set_option('base-url', self.default_base_url())
-        if not self.anonymous_logged:
-            self.global_set_option('anonymous-user', None)
-        else:
-            self.global_set_option('anonymous-user', 'anon')
-            self.global_set_option('anonymous-password', 'anon')
         self.global_set_option('force-html-content-type', True)
-        # no undo support in tests
-        self.global_set_option('undo-support', '')
 
 
 class CubicWebServerTC(CubicWebTC):
-    """class for running test server
+    """Class for running test web server. See :class:`CubicWebServerConfig`.
 
-    :cvar: :ref:`CubicWebServerConfig` class
+    Class attributes:
+    * ` anonymous_logged`: flag telling ifs anonymous user should be log logged
+      by default (True by default)
     """
     configcls = CubicWebServerConfig
+    # anonymous is logged by default in cubicweb test cases
+    anonymous_logged = True
 
     def start_server(self):
         # use a semaphore to avoid starting test while the http server isn't
@@ -126,7 +117,7 @@
             raise RuntimeError('Could not start the web server')
         #pre init utils connection
         parseurl = urlparse(self.config['base-url'])
-        assert parseurl.port == self.config['port']
+        assert parseurl.port == self.config['port'], (self.config['base-url'], self.config['port'])
         self._web_test_cnx = httplib.HTTPConnection(parseurl.hostname,
                                                     parseurl.port)
         self._ident_cookie = None
@@ -195,3 +186,12 @@
             # Server could be launched manually
             print err
         CubicWebTC.tearDown(self)
+
+    @classmethod
+    def init_config(cls, config):
+        super(CubicWebServerTC, cls).init_config(config)
+        if not cls.anonymous_logged:
+            config.global_set_option('anonymous-user', None)
+        else:
+            config.global_set_option('anonymous-user', 'anon')
+            config.global_set_option('anonymous-password', 'anon')
--- a/devtools/test/unittest_httptest.py	Mon Oct 11 12:03:12 2010 +0200
+++ b/devtools/test/unittest_httptest.py	Mon Oct 11 12:27:29 2010 +0200
@@ -1,7 +1,25 @@
+# copyright 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""unittest for cubicweb.devtools.httptest module"""
+
 import httplib
 
-from cubicweb.devtools.httptest import CubicWebServerTC
-from cubicweb.devtools.httptest import CubicWebServerConfig
+from cubicweb.devtools.httptest import CubicWebServerTC, CubicWebServerConfig
 
 
 class TwistedCWAnonTC(CubicWebServerTC):
@@ -22,10 +40,7 @@
 
 
 class TwistedCWIdentTC(CubicWebServerTC):
-
-    def setUp(self):
-        CubicWebServerConfig.anonymous_logged = False
-        CubicWebServerTC.setUp(self)
+    anonymous_logged = False
 
     def test_response_denied(self):
         response = self.web_get()
--- a/devtools/testlib.py	Mon Oct 11 12:03:12 2010 +0200
+++ b/devtools/testlib.py	Mon Oct 11 12:27:29 2010 +0200
@@ -232,7 +232,7 @@
         config.global_set_option('sender-name', 'cubicweb-test')
         config.global_set_option('sender-addr', 'cubicweb-test@logilab.fr')
         # default_base_url on config class isn't enough for TestServerConfiguration
-        config.global_set_option('base-url', BASE_URL)
+        config.global_set_option('base-url', config.default_base_url())
         # web resources
         try:
             config.global_set_option('embed-allowed', re.compile('.*'))
--- a/server/test/unittest_fti.py	Mon Oct 11 12:03:12 2010 +0200
+++ b/server/test/unittest_fti.py	Mon Oct 11 12:27:29 2010 +0200
@@ -57,3 +57,7 @@
             self.commit()
             self.assertEqual(req.execute('Any X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
                               [[c1.eid], [c3.eid], [c2.eid]])
+
+if __name__ == '__main__':
+    from logilab.common.testlib import unittest_main
+    unittest_main()