From 99a2dd3938c7d7d4b7e9c724ec8acbb5eeedf35f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 25 Oct 2012 17:47:45 +0200 Subject: [ADD] first 90% of non-sucky testing API, last 90% left also all existing tests shoud now be completely broken and need to be fixed bzr revid: xmo@openerp.com-20121025154745-rw2gktfd6tp68k2m --- addons/web/controllers/testing.py | 155 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 addons/web/controllers/testing.py (limited to 'addons/web/controllers/testing.py') diff --git a/addons/web/controllers/testing.py b/addons/web/controllers/testing.py new file mode 100644 index 00000000000..0cfc633a492 --- /dev/null +++ b/addons/web/controllers/testing.py @@ -0,0 +1,155 @@ +# coding=utf-8 +# -*- encoding: utf-8 -*- + +import glob +import itertools +import json +import operator +import os + +from mako.template import Template +from openerp.modules import module + +from .main import module_topological_sort +from ..http import Controller, httprequest + +NOMODULE_TEMPLATE = Template(u""" + + + + + OpenERP Testing + + +
+ + +
+ + +""") +NOTFOUND = Template(u""" +

Unable to find the module [${module}], please check that the module + name is correct and the module is on OpenERP's path.

+<< Back to tests +""") +TESTING = Template(u""" + +<%def name="to_path(module, p)">/${module}/${p} + + + + OpenERP Web Tests + + + + + + + + +
+
+ +% for module, jss, tests, templates in files: + % for js in jss: + + % endfor + % if tests or templates: + + % endif + % if tests: + % for test in tests: + + % endfor + % endif +% endfor + +""") + +class TestRunnerController(Controller): + _cp_path = '/web/tests' + + @httprequest + def index(self, req, mod=None, **kwargs): + ms = module.get_modules() + manifests = dict( + (name, desc) + for name, desc in zip(ms, map(self.load_manifest, ms)) + if desc # remove not-actually-openerp-modules + ) + + if not mod: + return NOMODULE_TEMPLATE.render(modules=( + (manifest['name'], name) + for name, manifest in manifests.iteritems() + if any(testfile.endswith('.js') + for testfile in manifest['test']) + )) + sorted_mods = module_topological_sort(dict( + (name, manifest.get('depends', [])) + for name, manifest in manifests.iteritems() + )) + # to_load and to_test should be zippable lists of the same length. + # A falsy value in to_test indicate nothing to test at that index (just + # load the corresponding part of to_load) + to_test = sorted_mods + if mod != '*': + if mod not in manifests: + return req.not_found(NOTFOUND.render(module=mod)) + idx = sorted_mods.index(mod) + to_test = [None] * len(sorted_mods) + to_test[idx] = mod + + tests_candicates = [ + filter(lambda path: path.endswith('.js'), + manifests[mod]['test'] if mod else []) + for mod in to_test] + # remove trailing test-less modules + tests = reversed(list( + itertools.dropwhile( + operator.not_, + reversed(tests_candicates)))) + + files = [ + (mod, manifests[mod]['js'], tests, manifests[mod]['qweb']) + for mod, tests in itertools.izip(sorted_mods, tests) + ] + + return TESTING.render(files=files, dependencies=json.dumps( + [name for name in sorted_mods + if module.get_module_resource(name, 'static') + if manifests[name]['js']])) + + def load_manifest(self, name): + manifest = module.load_information_from_description_file(name) + if manifest: + path = module.get_module_path(name) + manifest['js'] = list( + self.expand_patterns(path, manifest.get('js', []))) + manifest['test'] = list( + self.expand_patterns(path, manifest.get('test', []))) + manifest['qweb'] = list( + self.expand_patterns(path, manifest.get('qweb', []))) + return manifest + + def expand_patterns(self, root, patterns): + for pattern in patterns: + normalized_pattern = os.path.normpath(os.path.join(root, pattern)) + for path in glob.glob(normalized_pattern): + # replace OS path separators (from join & normpath) by URI ones + yield path[len(root):].replace(os.path.sep, '/') -- cgit v1.2.3 From bf4a26d3e8613c24b3a360013525cfef28458176 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 29 Oct 2012 12:01:54 +0100 Subject: [ADD] actual-RPC tests, with UI. Bump QUnit timeout to 10s so RPC can run at all bzr revid: xmo@openerp.com-20121029110154-5927gaix8k0ijl0c --- addons/web/controllers/testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/controllers/testing.py') diff --git a/addons/web/controllers/testing.py b/addons/web/controllers/testing.py index 0cfc633a492..9947f1e1ed5 100644 --- a/addons/web/controllers/testing.py +++ b/addons/web/controllers/testing.py @@ -53,7 +53,7 @@ TESTING = Template(u""" -- cgit v1.2.3 From d2cf844e7b2e447ce0c1502aa3a514056a6d7fb1 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 30 Oct 2012 08:46:15 +0100 Subject: [IMP] allow providing db-cloning info directly in URL for test runner bzr revid: xmo@openerp.com-20121030074615-lt517w5t9fd9ppvh --- addons/web/controllers/testing.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'addons/web/controllers/testing.py') diff --git a/addons/web/controllers/testing.py b/addons/web/controllers/testing.py index 9947f1e1ed5..95121f5b192 100644 --- a/addons/web/controllers/testing.py +++ b/addons/web/controllers/testing.py @@ -51,6 +51,7 @@ TESTING = Template(u""" -- cgit v1.2.3