13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
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/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """this module contains base classes for windmill integration""" |
18 """this module contains base classes for windmill integration |
|
19 |
|
20 :todo: |
|
21 |
|
22 * import CubicWeb session object into windmill scope to be able to run RQL |
|
23 * manage command line option from pytest to run specific use tests only |
|
24 """ |
|
25 |
19 |
26 |
20 import os, os.path as osp |
27 import os, os.path as osp |
|
28 import sys |
|
29 import unittest |
21 |
30 |
22 # imported by default to simplify further import statements |
31 # imported by default to simplify further import statements |
23 from logilab.common.testlib import unittest_main |
32 from logilab.common.testlib import unittest_main |
24 |
33 |
25 from windmill.authoring import unit |
|
26 from windmill.dep import functest |
34 from windmill.dep import functest |
27 |
35 |
28 from cubicweb.devtools.httptest import CubicWebServerTC |
36 from cubicweb.devtools.httptest import CubicWebServerTC |
29 |
37 |
30 |
38 |
|
39 # Excerpt from :ref:`windmill.authoring.unit` |
31 class UnitTestReporter(functest.reports.FunctestReportInterface): |
40 class UnitTestReporter(functest.reports.FunctestReportInterface): |
32 def summary(self, test_list, totals_dict, stdout_capture): |
41 def summary(self, test_list, totals_dict, stdout_capture): |
33 self.test_list = test_list |
42 self.test_list = test_list |
34 |
43 |
35 unittestreporter = UnitTestReporter() |
44 unittestreporter = UnitTestReporter() |
36 functest.reports.register_reporter(unittestreporter) |
45 functest.reports.register_reporter(unittestreporter) |
37 |
46 |
38 class CubicWebWindmillUseCase(CubicWebServerTC, unit.WindmillUnitTestCase): |
47 class WindmillUnitTestCase(unittest.TestCase): |
|
48 def setUp(self): |
|
49 import windmill |
|
50 windmill.stdout, windmill.stdin = sys.stdout, sys.stdin |
|
51 from windmill.bin.admin_lib import configure_global_settings, setup |
|
52 configure_global_settings() |
|
53 windmill.settings['TEST_URL'] = self.test_url |
|
54 if hasattr(self,"windmill_settings"): |
|
55 for (setting,value) in self.windmill_settings.iteritems(): |
|
56 windmill.settings[setting] = value |
|
57 self.windmill_shell_objects = setup() |
|
58 |
|
59 def tearDown(self): |
|
60 from windmill.bin.admin_lib import teardown |
|
61 teardown(self.windmill_shell_objects) |
|
62 |
|
63 |
|
64 class CubicWebWindmillUseCase(CubicWebServerTC, WindmillUnitTestCase): |
39 """basic class for Windmill use case tests |
65 """basic class for Windmill use case tests |
40 |
66 |
41 :param browser: browser identification string (firefox|ie|safari|chrome) (firefox by default) |
67 :param browser: browser identification string (firefox|ie|safari|chrome) (firefox by default) |
42 :param test_dir: testing file path or directory (./windmill by default) |
68 :param test_dir: testing file path or directory (./windmill by default) |
|
69 :param edit_test: load and edit test for debugging (False by default) |
43 """ |
70 """ |
44 browser = 'firefox' |
71 browser = 'firefox' |
45 test_dir = osp.join(os.getcwd(), 'windmill') |
72 test_dir = osp.join(os.getcwd(), 'windmill') |
|
73 edit_test = "-i" in sys.argv # detection for pytest invocation |
46 |
74 |
47 def setUp(self): |
75 def setUp(self): |
48 # reduce log output |
76 # reduce log output |
49 from logging import getLogger, ERROR |
77 from logging import getLogger, ERROR |
50 getLogger('cubicweb').setLevel(ERROR) |
78 getLogger('cubicweb').setLevel(ERROR) |
51 getLogger('logilab').setLevel(ERROR) |
79 getLogger('logilab').setLevel(ERROR) |
52 getLogger('windmill').setLevel(ERROR) |
80 getLogger('windmill').setLevel(ERROR) |
53 # Start CubicWeb session before running the server to populate self.vreg |
81 # Start CubicWeb session before running the server to populate self.vreg |
54 CubicWebServerTC.setUp(self) |
82 CubicWebServerTC.setUp(self) |
55 assert os.path.exists(self.test_dir), "provide 'test_dir' as the given test file/dir" |
83 assert os.path.exists(self.test_dir), "provide 'test_dir' as the given test file/dir" |
56 unit.WindmillUnitTestCase.setUp(self) |
84 WindmillUnitTestCase.setUp(self) |
57 |
85 |
58 def tearDown(self): |
86 def tearDown(self): |
59 unit.WindmillUnitTestCase.tearDown(self) |
87 WindmillUnitTestCase.tearDown(self) |
60 CubicWebServerTC.tearDown(self) |
88 CubicWebServerTC.tearDown(self) |
61 |
89 |
62 def testWindmill(self): |
90 def testWindmill(self): |
|
91 if self.edit_test: |
|
92 # see windmill.bin.admin_options.Firebug |
|
93 import windmill |
|
94 windmill.settings['INSTALL_FIREBUG'] = 'firebug' |
|
95 |
63 self.windmill_shell_objects['start_' + self.browser]() |
96 self.windmill_shell_objects['start_' + self.browser]() |
64 self.windmill_shell_objects['do_test'](self.test_dir, threaded=False) |
97 self.windmill_shell_objects['do_test'](self.test_dir, |
|
98 load=self.edit_test, |
|
99 threaded=False) |
|
100 # set a breakpoint to be able to debug windmill test |
|
101 if self.edit_test: |
|
102 import pdb; pdb.set_trace() |
|
103 return |
|
104 |
65 for test in unittestreporter.test_list: |
105 for test in unittestreporter.test_list: |
|
106 msg = "" |
66 self._testMethodDoc = getattr(test, "__doc__", None) |
107 self._testMethodDoc = getattr(test, "__doc__", None) |
67 self._testMethodName = test.__name__ |
108 self._testMethodName = test.__name__ |
68 self.assertEquals(test.result, True) |
109 # try to display a better message in case of failure |
|
110 if hasattr(test, "tb"): |
|
111 msg = '\n'.join(test.tb) |
|
112 self.assertEquals(test.result, True, msg=msg) |
69 |
113 |
70 |
|