[testlib] simplify code by using a class attribute stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 07 Dec 2010 12:18:20 +0100
branchstable
changeset 7065 6a6ea9966931
parent 7064 b8ce2266d026
child 7066 7baf7515c3b9
[testlib] simplify code by using a class attribute
devtools/__init__.py
devtools/httptest.py
--- a/devtools/__init__.py	Wed Mar 09 13:42:55 2011 +0100
+++ b/devtools/__init__.py	Tue Dec 07 12:18:20 2010 +0100
@@ -89,8 +89,11 @@
         ServerConfiguration.options +
         tuple((opt, optdict) for opt, optdict in TwistedConfiguration.options
               if opt in ('anonymous-user', 'anonymous-password')))
+    # By default anonymous login are allow but some test need to deny of to
+    # change the default user. Set it to None to prevent anonymous login.
+    anonymous_credential = ('anon', 'anon')
 
-    def __init__(self, appid, apphome=None, log_threshold=logging.CRITICAL+10):
+    def __init__(self, appid='data', apphome=None, log_threshold=logging.CRITICAL+10):
         # must be set before calling parent __init__
         if apphome is None:
             if exists(appid):
@@ -112,8 +115,10 @@
 
     def load_configuration(self):
         super(TestServerConfiguration, self).load_configuration()
-        self.global_set_option('anonymous-user', 'anon')
-        self.global_set_option('anonymous-password', 'anon')
+        if self.anonymous_credential:
+            user, password = self.anonymous_credential
+            self.global_set_option('anonymous-user', user)
+            self.global_set_option('anonymous-password', password)
         # no undo support in tests
         self.global_set_option('undo-support', '')
 
--- a/devtools/httptest.py	Wed Mar 09 13:42:55 2011 +0100
+++ b/devtools/httptest.py	Tue Dec 07 12:18:20 2010 +0100
@@ -89,8 +89,8 @@
     """Class for running test web server. See :class:`CubicWebServerConfig`.
 
     Class attributes:
-    * ` anonymous_logged`: flag telling ifs anonymous user should be log logged
-      by default (True by default)
+    * `anonymous_logged`: flag telling if anonymous user should be logged-in
+      by default (True by default) XXX (syt) s/logged-in/allowed/ ?
     """
     configcls = CubicWebServerConfig
     # anonymous is logged by default in cubicweb test cases
@@ -176,7 +176,7 @@
         return response
 
     def setUp(self):
-        CubicWebTC.setUp(self)
+        super(CubicWebServerTC, self).setUp()
         self.start_server()
 
     def tearDown(self):
@@ -185,13 +185,10 @@
         except error.ReactorNotRunning, err:
             # Server could be launched manually
             print err
-        CubicWebTC.tearDown(self)
+        super(CubicWebServerTC, self).tearDown()
 
     @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')
+            config.anonymous_credential = None