author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 14 Sep 2010 08:48:44 +0200 | |
changeset 6229 | c4a70a5dd144 |
parent 6036 | fe17d4bac785 |
child 6322 | 711e7e8c69e3 |
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 |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
29 |
import unittest |
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 |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
32 |
from logilab.common.testlib import unittest_main |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
33 |
|
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 |
|
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
47 |
class WindmillUnitTestCase(unittest.TestCase): |
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 |
import windmill |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
configure_global_settings() |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
windmill.settings[setting] = value |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
57 |
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
|
58 |
|
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
59 |
def tearDown(self): |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
|
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
63 |
|
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
64 |
class CubicWebWindmillUseCase(CubicWebServerTC, WindmillUnitTestCase): |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
65 |
"""basic class for Windmill use case tests |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
66 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
67 |
: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
|
68 |
: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
|
69 |
: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
|
70 |
""" |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
71 |
browser = 'firefox' |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
72 |
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
|
73 |
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
|
74 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
75 |
def setUp(self): |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
76 |
# reduce log output |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
77 |
from logging import getLogger, ERROR |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
78 |
getLogger('cubicweb').setLevel(ERROR) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
79 |
getLogger('logilab').setLevel(ERROR) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
80 |
getLogger('windmill').setLevel(ERROR) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
81 |
# 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
|
82 |
CubicWebServerTC.setUp(self) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
83 |
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
|
84 |
WindmillUnitTestCase.setUp(self) |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
85 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
86 |
def tearDown(self): |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
87 |
WindmillUnitTestCase.tearDown(self) |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
88 |
CubicWebServerTC.tearDown(self) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
89 |
|
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
90 |
def testWindmill(self): |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
91 |
if self.edit_test: |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
92 |
# 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
|
93 |
import windmill |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
94 |
windmill.settings['INSTALL_FIREBUG'] = 'firebug' |
6036
fe17d4bac785
[windmill] add xul-ext firefox plugin
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5995
diff
changeset
|
95 |
windmill.settings['MOZILLA_PLUGINS'].append('/usr/share/mozilla-extensions/') |
fe17d4bac785
[windmill] add xul-ext firefox plugin
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5995
diff
changeset
|
96 |
windmill.settings['MOZILLA_PLUGINS'].append('/usr/share/xul-ext/') |
5995
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
97 |
|
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
load=self.edit_test, |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
101 |
threaded=False) |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
102 |
# 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
|
103 |
if self.edit_test: |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
104 |
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
|
105 |
return |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
106 |
|
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
107 |
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
|
108 |
msg = "" |
5674
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
109 |
self._testMethodDoc = getattr(test, "__doc__", None) |
9378d13e9ac4
[web test] Add windmill functional testing capability.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
diff
changeset
|
110 |
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
|
111 |
# 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
|
112 |
if hasattr(test, "tb"): |
b9c612274af7
[test] improve windmill integration, new test on relation edition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5674
diff
changeset
|
113 |
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
|
114 |
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
|
115 |