# HG changeset patch # User Sylvain Thénault # Date 1286792810 -7200 # Node ID abae10f81a85527d4f2cbe60ed7e2e0f24788e8b # Parent 275e9f402ccce40501d02f1a2d20d5bdb26104ca [js test] cleanup, move anonymous_logged handling to the test class (easier to control there diff -r 275e9f402ccc -r abae10f81a85 devtools/cwwindmill.py --- a/devtools/cwwindmill.py Mon Oct 11 11:05:19 2010 +0200 +++ b/devtools/cwwindmill.py Mon Oct 11 12:26:50 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 diff -r 275e9f402ccc -r abae10f81a85 devtools/httptest.py --- a/devtools/httptest.py Mon Oct 11 11:05:19 2010 +0200 +++ b/devtools/httptest.py Mon Oct 11 12:26:50 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') diff -r 275e9f402ccc -r abae10f81a85 devtools/test/unittest_httptest.py --- a/devtools/test/unittest_httptest.py Mon Oct 11 11:05:19 2010 +0200 +++ b/devtools/test/unittest_httptest.py Mon Oct 11 12:26:50 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 . +"""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()