# HG changeset patch # User Sylvain Thénault # Date 1299765561 -3600 # Node ID db7608cb32bc47e12266d6b3c302bd9821aaebd2 # Parent f239da8e7c396bb88aafc6c411d10870b6d7a131 [devtools] fix anonymous user handling in test classes diff -r f239da8e7c39 -r db7608cb32bc devtools/__init__.py --- a/devtools/__init__.py Thu Mar 10 11:56:35 2011 +0100 +++ b/devtools/__init__.py Thu Mar 10 14:59:21 2011 +0100 @@ -85,13 +85,6 @@ read_instance_schema = False init_repository = True db_require_setup = True - options = cwconfig.merge_options( - 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='data', apphome=None, log_threshold=logging.CRITICAL+10): # must be set before calling parent __init__ @@ -106,7 +99,20 @@ # need this, usually triggered by cubicweb-ctl self.load_cwctl_plugins() - anonymous_user = TwistedConfiguration.anonymous_user.im_func + # 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 anonymous_user(self): + if not self.anonymous_credential: + return None, None + return self.anonymous_credential + + def set_anonymous_allowed(self, allowed, anonuser='anon'): + if allowed: + self.anonymous_credential = (anonuser, anonuser) + else: + self.anonymous_credential = None @property def apphome(self): @@ -115,10 +121,6 @@ def load_configuration(self): super(TestServerConfiguration, self).load_configuration() - 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', '') diff -r f239da8e7c39 -r db7608cb32bc devtools/cwwindmill.py --- a/devtools/cwwindmill.py Thu Mar 10 11:56:35 2011 +0100 +++ b/devtools/cwwindmill.py Thu Mar 10 14:59:21 2011 +0100 @@ -91,7 +91,7 @@ browser = 'firefox' edit_test = "-i" in sys.argv # detection for pytest invocation # Windmill use case are written with no anonymous user - anonymous_logged = False + anonymous_allowed = False tags = CubicWebServerTC.tags & Tags(('windmill',)) diff -r f239da8e7c39 -r db7608cb32bc devtools/httptest.py --- a/devtools/httptest.py Thu Mar 10 11:56:35 2011 +0100 +++ b/devtools/httptest.py Thu Mar 10 14:59:21 2011 +0100 @@ -89,12 +89,11 @@ """Class for running test web server. See :class:`CubicWebServerConfig`. Class attributes: - * `anonymous_logged`: flag telling if anonymous user should be logged-in - by default (True by default) XXX (syt) s/logged-in/allowed/ ? + * `anonymous_allowed`: flag telling if anonymous browsing should be allowed """ configcls = CubicWebServerConfig # anonymous is logged by default in cubicweb test cases - anonymous_logged = True + anonymous_allowed = True def start_server(self): # use a semaphore to avoid starting test while the http server isn't @@ -189,6 +188,5 @@ @classmethod def init_config(cls, config): - if not cls.anonymous_logged: - config.anonymous_credential = None + config.set_anonymous_allowed(cls.anonymous_allowed) super(CubicWebServerTC, cls).init_config(config) diff -r f239da8e7c39 -r db7608cb32bc devtools/test/unittest_httptest.py --- a/devtools/test/unittest_httptest.py Thu Mar 10 11:56:35 2011 +0100 +++ b/devtools/test/unittest_httptest.py Thu Mar 10 14:59:21 2011 +0100 @@ -42,7 +42,7 @@ class TwistedCWIdentTC(CubicWebServerTC): - anonymous_logged = False + anonymous_allowed = False tags = CubicWebServerTC.tags | Tags(('auth',)) def test_response_denied(self): diff -r f239da8e7c39 -r db7608cb32bc devtools/testlib.py --- a/devtools/testlib.py Thu Mar 10 11:56:35 2011 +0100 +++ b/devtools/testlib.py Thu Mar 10 14:59:21 2011 +0100 @@ -659,6 +659,10 @@ def init_authentication(self, authmode, anonuser=None): self.set_option('auth-mode', authmode) self.set_option('anonymous-user', anonuser) + if anonuser is None: + self.config.anonymous_credential = None + else: + self.config.anonymous_credential = (anonuser, anonuser) req = self.request() origsession = req.session req.session = req.cnx = None diff -r f239da8e7c39 -r db7608cb32bc web/views/basetemplates.py --- a/web/views/basetemplates.py Thu Mar 10 11:56:35 2011 +0100 +++ b/web/views/basetemplates.py Thu Mar 10 14:59:21 2011 +0100 @@ -74,7 +74,7 @@ # FIXME Deprecated code ? msg = self._cw._('you have been logged out') w(u'

%s

\n' % msg) - if self._cw.vreg.config['anonymous-user']: + if self._cw.vreg.config.anonymous_user()[0]: indexurl = self._cw.build_url('view', vid='index', __message=msg) w(u'

%s

' % ( xml_escape(indexurl),