author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Tue, 28 Sep 2010 12:22:17 +0200 | |
branch | stable |
changeset 6350 | 74575fb32a4d |
parent 6341 | ad5e08981153 |
child 6369 | a151453dc564 |
permissions | -rw-r--r-- |
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 |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
28 |
import sys |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
29 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
30 |
# imported by default to simplify further import statements |
6341
ad5e08981153
[tests] import TestSuite from lgc.testlib for further compatibility
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6322
diff
changeset
|
31 |
from logilab.common.testlib import TestCase, unittest_main |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
32 |
|
6322
711e7e8c69e3
[windmill] initialize windmill registry if not already existing (possible error case in dev)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6036
diff
changeset
|
33 |
import windmill |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
34 |
from windmill.dep import functest |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
35 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
36 |
from cubicweb.devtools.httptest import CubicWebServerTC |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
37 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
38 |
|
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
39 |
# Excerpt from :ref:`windmill.authoring.unit` |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
40 |
class UnitTestReporter(functest.reports.FunctestReportInterface): |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
41 |
def summary(self, test_list, totals_dict, stdout_capture): |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
42 |
self.test_list = test_list |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
43 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
44 |
unittestreporter = UnitTestReporter() |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
45 |
functest.reports.register_reporter(unittestreporter) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
46 |
|
6341
ad5e08981153
[tests] import TestSuite from lgc.testlib for further compatibility
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6322
diff
changeset
|
47 |
class WindmillUnitTestCase(TestCase): |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
48 |
def setUp(self): |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
49 |
windmill.stdout, windmill.stdin = sys.stdout, sys.stdin |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
50 |
from windmill.bin.admin_lib import configure_global_settings, setup |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
51 |
configure_global_settings() |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
52 |
windmill.settings['TEST_URL'] = self.test_url |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
53 |
if hasattr(self,"windmill_settings"): |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
54 |
for (setting,value) in self.windmill_settings.iteritems(): |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
55 |
windmill.settings[setting] = value |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
56 |
self.windmill_shell_objects = setup() |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
57 |
|
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
58 |
def tearDown(self): |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
59 |
from windmill.bin.admin_lib import teardown |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
60 |
teardown(self.windmill_shell_objects) |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
61 |
|
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
62 |
|
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
63 |
class CubicWebWindmillUseCase(CubicWebServerTC, WindmillUnitTestCase): |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
64 |
"""basic class for Windmill use case tests |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
65 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
66 |
:param browser: browser identification string (firefox|ie|safari|chrome) (firefox by default) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
67 |
:param test_dir: testing file path or directory (./windmill by default) |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
68 |
:param edit_test: load and edit test for debugging (False by default) |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
69 |
""" |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
70 |
browser = 'firefox' |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
71 |
test_dir = osp.join(os.getcwd(), 'windmill') |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
72 |
edit_test = "-i" in sys.argv # detection for pytest invocation |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
73 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
74 |
def setUp(self): |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
75 |
# reduce log output |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
76 |
from logging import getLogger, ERROR |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
77 |
getLogger('cubicweb').setLevel(ERROR) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
78 |
getLogger('logilab').setLevel(ERROR) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
79 |
getLogger('windmill').setLevel(ERROR) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
80 |
# Start CubicWeb session before running the server to populate self.vreg |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
81 |
CubicWebServerTC.setUp(self) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
82 |
assert os.path.exists(self.test_dir), "provide 'test_dir' as the given test file/dir" |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
83 |
WindmillUnitTestCase.setUp(self) |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
84 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
85 |
def tearDown(self): |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
86 |
WindmillUnitTestCase.tearDown(self) |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
87 |
CubicWebServerTC.tearDown(self) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
88 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
89 |
def testWindmill(self): |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
90 |
if self.edit_test: |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
91 |
# see windmill.bin.admin_options.Firebug |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
92 |
windmill.settings['INSTALL_FIREBUG'] = 'firebug' |
6322
711e7e8c69e3
[windmill] initialize windmill registry if not already existing (possible error case in dev)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6036
diff
changeset
|
93 |
windmill.settings.setdefault('MOZILLA_PLUGINS', []).extend( |
711e7e8c69e3
[windmill] initialize windmill registry if not already existing (possible error case in dev)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6036
diff
changeset
|
94 |
'/usr/share/mozilla-extensions/', |
711e7e8c69e3
[windmill] initialize windmill registry if not already existing (possible error case in dev)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6036
diff
changeset
|
95 |
'/usr/share/xul-ext/') |
711e7e8c69e3
[windmill] initialize windmill registry if not already existing (possible error case in dev)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6036
diff
changeset
|
96 |
controller = self.windmill_shell_objects['start_' + self.browser]() |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
97 |
self.windmill_shell_objects['do_test'](self.test_dir, |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
98 |
load=self.edit_test, |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
99 |
threaded=False) |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
100 |
# set a breakpoint to be able to debug windmill test |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
101 |
if self.edit_test: |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
102 |
import pdb; pdb.set_trace() |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
103 |
return |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
104 |
|
6322
711e7e8c69e3
[windmill] initialize windmill registry if not already existing (possible error case in dev)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6036
diff
changeset
|
105 |
# reporter |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
106 |
for test in unittestreporter.test_list: |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
107 |
msg = "" |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
108 |
self._testMethodDoc = getattr(test, "__doc__", None) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
109 |
self._testMethodName = test.__name__ |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
110 |
# try to display a better message in case of failure |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
111 |
if hasattr(test, "tb"): |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
112 |
msg = '\n'.join(test.tb) |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
113 |
self.assertEquals(test.result, True, msg=msg) |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
114 |