devtools/cwwindmill.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 11 Mar 2011 09:47:09 +0100
branchstable
changeset 7075 4751d77394b1
parent 7071 db7608cb32bc
parent 7061 bb2080547722
child 7089 6c6e0fbd0605
permissions -rw-r--r--
default (3.11.X) is now stable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
     3
#
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
     4
# This file is part of CubicWeb.
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
     5
#
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
     9
# any later version.
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    10
#
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    14
# details.
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    15
#
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5995
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
    18
"""this module contains base classes for windmill integration
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
    19
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
    20
:todo:
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
    21
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
    22
    * import CubicWeb session object into windmill scope to be able to run RQL
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
    23
    * manage command line option from pytest to run specific use tests only
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
    24
"""
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
    25
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    26
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    27
import os, os.path as osp
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    28
from logging import getLogger, ERROR
5995
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
    29
import sys
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    30
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    31
# imported by default to simplify further import statements
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    32
from logilab.common.testlib import TestCase, unittest_main, Tags
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    33
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    34
try:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    35
    import windmill
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    36
    from windmill.dep import functest
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    37
    from windmill.bin.admin_lib import configure_global_settings, setup, teardown
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    38
except ImportError, ex:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    39
    windmill = None
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    40
6438
abae10f81a85 [js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6424
diff changeset
    41
from cubicweb.devtools.httptest import CubicWebServerTC, CubicWebServerConfig
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    42
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    43
if windmill is None:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    44
    class CubicWebWindmillUseCase(CubicWebServerTC):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    45
        tags = CubicWebServerTC.tags & Tags(('windmill',))
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    46
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    47
        def testWindmill(self):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    48
            self.skipTest("can't import windmill %s" % ex)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    49
else:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    50
    # Excerpt from :ref:`windmill.authoring.unit`
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    51
    class UnitTestReporter(functest.reports.FunctestReportInterface):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    52
        def summary(self, test_list, totals_dict, stdout_capture):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    53
            self.test_list = test_list
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
    54
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    55
    unittestreporter = UnitTestReporter()
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    56
    functest.reports.register_reporter(unittestreporter)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    57
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    58
    class CubicWebWindmillUseCase(CubicWebServerTC):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    59
        """basic class for Windmill use case tests
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    60
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    61
        If you want to change cubicweb test server parameters, define a new
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    62
        :class:`CubicWebServerConfig` and override the :var:`configcls`
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    63
        attribute:
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    64
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    65
            configcls = CubicWebServerConfig
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    66
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    67
        From Windmill configuration:
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    68
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    69
        .. attribute:: browser
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    70
            identification string (firefox|ie|safari|chrome) (firefox by default)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    71
        .. attribute :: edit_test
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    72
            load and edit test for debugging (False by default)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    73
        .. attribute:: test_dir (optional)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    74
            testing file path or directory (windmill directory under your unit case
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    75
            file by default)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    76
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    77
        Examples:
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    78
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    79
            browser = 'firefox'
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    80
            test_dir = osp.join(__file__, 'windmill')
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    81
            edit_test = False
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    82
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    83
        If you prefer, you can put here the use cases recorded by windmill GUI
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    84
        (services transformer) instead of the windmill sub-directory
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    85
        You can change `test_dir` as following:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    86
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    87
            test_dir = __file__
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    88
7061
bb2080547722 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7059 7052
diff changeset
    89
        Instead of toggle `edit_test` value, try `python <test script> -f`
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    90
        """
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    91
        browser = 'firefox'
7061
bb2080547722 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7059 7052
diff changeset
    92
<<<<<<< /home/syt/src/fcubicweb/cubicweb/devtools/cwwindmill.py
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    93
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    94
        edit_test = "-i" in sys.argv # detection for pytest invocation
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    95
        # Windmill use case are written with no anonymous user
7071
db7608cb32bc [devtools] fix anonymous user handling in test classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7052
diff changeset
    96
        anonymous_allowed = False
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    97
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
    98
        tags = CubicWebServerTC.tags & Tags(('windmill',))
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
    99
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   100
        def _test_dir(self):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   101
            """access to class attribute if possible or make assumption
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   102
            of expected directory"""
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   103
            try:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   104
                return getattr(self, 'test_dir')
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   105
            except AttributeError:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   106
                if os.path.basename(sys.argv[0]) == "pytest":
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   107
                    test_dir = os.getcwd()
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   108
                else:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   109
                    import inspect
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   110
                    test_dir = os.path.dirname(inspect.stack()[-1][1])
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   111
                return osp.join(test_dir, 'windmill')
6424
f443a2b8a5c7 [devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6369
diff changeset
   112
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   113
        def setUp(self):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   114
            # Start CubicWeb session before running the server to populate self.vreg
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   115
            CubicWebServerTC.setUp(self)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   116
            # XXX reduce log output (should be done in a cleaner way)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   117
            # windmill fu** up our logging configuration
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   118
            for logkey in ('windmill', 'logilab', 'cubicweb'):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   119
                getLogger(logkey).setLevel(ERROR)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   120
            self.test_dir = self._test_dir()
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   121
            msg = "provide a valid 'test_dir' as the given test file/dir (current: %s)"
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   122
            assert os.path.exists(self.test_dir), (msg % self.test_dir)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   123
            # windmill setup
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   124
            windmill.stdout, windmill.stdin = sys.stdout, sys.stdin
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   125
            configure_global_settings()
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   126
            windmill.settings['TEST_URL'] = self.config['base-url']
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   127
            if hasattr(self,"windmill_settings"):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   128
                for (setting,value) in self.windmill_settings.iteritems():
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   129
                    windmill.settings[setting] = value
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   130
            self.windmill_shell_objects = setup()
5995
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
   131
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   132
        def tearDown(self):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   133
            teardown(self.windmill_shell_objects)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   134
            CubicWebServerTC.tearDown(self)
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
   135
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   136
        def testWindmill(self):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   137
            if self.edit_test:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   138
                # see windmill.bin.admin_options.Firebug
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   139
                windmill.settings['INSTALL_FIREBUG'] = 'firebug'
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   140
                windmill.settings.setdefault('MOZILLA_PLUGINS', []).extend(
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   141
                    ['/usr/share/mozilla-extensions/',
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   142
                     '/usr/share/xul-ext/'])
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   143
            controller = self.windmill_shell_objects['start_' + self.browser]()
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   144
            self.windmill_shell_objects['do_test'](self.test_dir,
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   145
                                                   load=self.edit_test,
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   146
                                                   threaded=False)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   147
            # set a breakpoint to be able to debug windmill test
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   148
            if self.edit_test:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   149
                import pdb; pdb.set_trace()
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   150
                return
5995
b9c612274af7 [test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5674
diff changeset
   151
7052
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   152
            # reporter
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   153
            for test in unittestreporter.test_list:
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   154
                msg = ""
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   155
                self._testMethodDoc = getattr(test, "__doc__", None)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   156
                self._testMethodName = test.__name__
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   157
                # try to display a better message in case of failure
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   158
                if hasattr(test, "tb"):
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   159
                    msg = '\n'.join(test.tb)
9680cf108821 [test/windmill] Gracefully skip windmill test if windmill can't be imported.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6438
diff changeset
   160
                self.assertEqual(test.result, True, msg=msg)
5674
9378d13e9ac4 [web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff changeset
   161