Merge lp:~openerp-dev/openobject-server/trunk-r9215-fix-chm into lp:openobject-server

Proposed by Christophe Simonis (OpenERP)
Status: Merged
Merged at revision: 5148
Proposed branch: lp:~openerp-dev/openobject-server/trunk-r9215-fix-chm
Merge into: lp:openobject-server
Diff against target: 181 lines (+40/-32)
4 files modified
openerp/http.py (+1/-1)
openerp/modules/loading.py (+7/-1)
openerp/modules/module.py (+18/-18)
openerp/tests/phantomtest.js (+14/-12)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-r9215-fix-chm
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+212615@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/http.py'
2--- openerp/http.py 2014-03-24 16:12:57 +0000
3+++ openerp/http.py 2014-03-25 13:51:01 +0000
4@@ -287,7 +287,7 @@
5 def checked_call(___dbname, *a, **kw):
6 # The decorator can call us more than once if there is an database error. In this
7 # case, the request cursor is unusable. Rollback transaction to create a new one.
8- if self._cr:
9+ if self._cr and not openerp.tools.config['test_enable']:
10 self._cr.rollback()
11 return self.endpoint(*a, **kw)
12
13
14=== modified file 'openerp/modules/loading.py'
15--- openerp/modules/loading.py 2014-03-17 15:18:10 +0000
16+++ openerp/modules/loading.py 2014-03-25 13:51:01 +0000
17@@ -42,6 +42,7 @@
18 from openerp.tools.translate import _
19 from openerp.modules.module import initialize_sys_path, \
20 load_openerp_module, init_module_models, adapt_version
21+from module import runs_post_install
22
23 _logger = logging.getLogger(__name__)
24 _test_logger = logging.getLogger('openerp.tests')
25@@ -425,8 +426,13 @@
26 for model in registry.models.values():
27 model._register_hook(cr)
28
29+ # STEP 9: Run the post-install tests
30+ cr.commit()
31+ if openerp.tools.config['test_enable']:
32+ cr.execute("SELECT name FROM ir_module_module WHERE state='installed'")
33+ for module_name in cr.fetchall():
34+ report.record_result(openerp.modules.module.run_unit_tests(module_name[0], cr.dbname, position=runs_post_install))
35 finally:
36 cr.close()
37
38-
39 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
40
41=== modified file 'openerp/modules/module.py'
42--- openerp/modules/module.py 2014-03-17 02:13:17 +0000
43+++ openerp/modules/module.py 2014-03-25 13:51:01 +0000
44@@ -356,7 +356,23 @@
45
46 current_test = None
47
48-def run_unit_tests(module_name, dbname):
49+def runs_at(test, hook, default):
50+ # by default, tests do not run post install
51+ test_runs = getattr(test, hook, default)
52+
53+ # for a test suite, we're done
54+ if not isinstance(test, unittest.TestCase):
55+ return test_runs
56+
57+ # otherwise check the current test method to see it's been set to a
58+ # different state
59+ method = getattr(test, test._testMethodName)
60+ return getattr(method, hook, test_runs)
61+
62+runs_at_install = functools.partial(runs_at, hook='at_install', default=True)
63+runs_post_install = functools.partial(runs_at, hook='post_install', default=False)
64+
65+def run_unit_tests(module_name, dbname, position=runs_at_install):
66 """
67 :returns: ``True`` if all of ``module_name``'s tests succeeded, ``False``
68 if any of them failed.
69@@ -368,7 +384,7 @@
70 r = True
71 for m in mods:
72 tests = unwrap_suite(unittest2.TestLoader().loadTestsFromModule(m))
73- suite = unittest2.TestSuite(itertools.ifilter(runs_at_install, tests))
74+ suite = unittest2.TestSuite(itertools.ifilter(position, tests))
75 _logger.info('running %s tests.', m.__name__)
76
77 result = unittest2.TextTestRunner(verbosity=2, stream=TestStream(m.__name__)).run(suite)
78@@ -380,22 +396,6 @@
79 current_test = None
80 return r
81
82-def runs_at(test, hook, default):
83- # by default, tests do not run post install
84- test_runs = getattr(test, hook, default)
85-
86- # for a test suite, we're done
87- if not isinstance(test, unittest.TestCase):
88- return test_runs
89-
90- # otherwise check the current test method to see it's been set to a
91- # different state
92- method = getattr(test, test._testMethodName)
93- return getattr(method, hook, test_runs)
94-
95-runs_at_install = functools.partial(runs_at, hook='at_install', default=True)
96-runs_post_install = functools.partial(runs_at, hook='post_install', default=False)
97-
98 def unwrap_suite(test):
99 """
100 Attempts to unpack testsuites (holding suites or cases) in order to
101
102=== modified file 'openerp/tests/phantomtest.js'
103--- openerp/tests/phantomtest.js 2014-03-16 16:06:34 +0000
104+++ openerp/tests/phantomtest.js 2014-03-25 13:51:01 +0000
105@@ -6,7 +6,8 @@
106
107 (function waitLoop() {
108 if(new Date - start > timeout) {
109- error(timeoutMessageCallback ? timeoutMessageCallback() : "Timeout after "+timeout+" ms");
110+ console.log('error', timeoutMessageCallback ? timeoutMessageCallback() : "Timeout after "+timeout+" ms");
111+ phantom.exit(1);
112 } else if (ready()) {
113 callback();
114 } else {
115@@ -15,10 +16,6 @@
116 }());
117 }
118
119-function error(message) {
120- console.log('error', message);
121- phantom.exit(1);
122-}
123 function PhantomTest() {
124 var self = this;
125 this.options = JSON.parse(phantom.args[phantom.args.length-1]);
126@@ -49,10 +46,12 @@
127 }));
128 msg.push('(leaf frame on top)')
129 }
130- error(JSON.stringify(msg.join('\n')));
131+ console.log('error', JSON.stringify(msg.join('\n')));
132+ phantom.exit(1);
133 };
134 this.page.onAlert = function(message) {
135- error(message);
136+ console.log('error', message);
137+ phantom.exit(1);
138 };
139 this.page.onConsoleMessage = function(message) {
140 console.log(message);
141@@ -78,7 +77,8 @@
142 if(!found) {
143 console.log('Injecting', src, 'needed for', need);
144 if(!self.page.injectJs(src)) {
145- error("Cannot inject " + src);
146+ console.log('error', "Cannot inject " + src);
147+ phantom.exit(1);
148 }
149 }
150 }
151@@ -88,8 +88,9 @@
152 self.page.evaluate(function () {
153 var message = ("Timeout\nhref: " + window.location.href
154 + "\nreferrer: " + document.referrer
155- + "\n\n" + document.body.innerHTML).replace(/[^a-z0-9\s~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "*");
156- error(message);
157+ + "\n\n" + (document.body && document.body.innerHTML)).replace(/[^a-z0-9\s~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "*");
158+ console.log('error', message);
159+ phantom.exit(1);
160 });
161 }, self.timeout);
162
163@@ -108,7 +109,8 @@
164 var url = self.origin + url_path;
165 self.page.open(url, function(status) {
166 if (status !== 'success') {
167- error("failed to load " + url)
168+ console.log('error', "failed to load " + url);
169+ phantom.exit(1);
170 } else {
171 console.log('loaded', url, status);
172 // process ready
173@@ -119,7 +121,7 @@
174 try {
175 console.log("page.evaluate eval expr:", ready);
176 r = !!eval(ready);
177- } catch(ex) {
178+ } catch(ex) {
179 }
180 console.log("page.evaluate eval result:", r);
181 return r;