devtools/cwwindmill.py
changeset 5674 9378d13e9ac4
child 5995 b9c612274af7
equal deleted inserted replaced
5664:2561b0e1c894 5674:9378d13e9ac4
       
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 """this module contains base classes for windmill integration"""
       
    19 
       
    20 import os, os.path as osp
       
    21 
       
    22 # imported by default to simplify further import statements
       
    23 from logilab.common.testlib import unittest_main
       
    24 
       
    25 from windmill.authoring import unit
       
    26 from windmill.dep import functest
       
    27 
       
    28 from cubicweb.devtools.httptest import CubicWebServerTC
       
    29 
       
    30 
       
    31 class UnitTestReporter(functest.reports.FunctestReportInterface):
       
    32     def summary(self, test_list, totals_dict, stdout_capture):
       
    33         self.test_list = test_list
       
    34 
       
    35 unittestreporter = UnitTestReporter()
       
    36 functest.reports.register_reporter(unittestreporter)
       
    37 
       
    38 class CubicWebWindmillUseCase(CubicWebServerTC, unit.WindmillUnitTestCase):
       
    39     """basic class for Windmill use case tests
       
    40 
       
    41     :param browser: browser identification string (firefox|ie|safari|chrome) (firefox by default)
       
    42     :param test_dir: testing file path or directory (./windmill by default)
       
    43     """
       
    44     browser = 'firefox'
       
    45     test_dir = osp.join(os.getcwd(), 'windmill')
       
    46 
       
    47     def setUp(self):
       
    48         # reduce log output
       
    49         from logging import getLogger, ERROR
       
    50         getLogger('cubicweb').setLevel(ERROR)
       
    51         getLogger('logilab').setLevel(ERROR)
       
    52         getLogger('windmill').setLevel(ERROR)
       
    53         # Start CubicWeb session before running the server to populate self.vreg
       
    54         CubicWebServerTC.setUp(self)
       
    55         assert os.path.exists(self.test_dir), "provide 'test_dir' as the given test file/dir"
       
    56         unit.WindmillUnitTestCase.setUp(self)
       
    57 
       
    58     def tearDown(self):
       
    59         unit.WindmillUnitTestCase.tearDown(self)
       
    60         CubicWebServerTC.tearDown(self)
       
    61 
       
    62     def testWindmill(self):
       
    63         self.windmill_shell_objects['start_' + self.browser]()
       
    64         self.windmill_shell_objects['do_test'](self.test_dir, threaded=False)
       
    65         for test in unittestreporter.test_list:
       
    66             self._testMethodDoc = getattr(test, "__doc__", None)
       
    67             self._testMethodName = test.__name__
       
    68             self.assertEquals(test.result, True)
       
    69 
       
    70