diff options
| author | Fabien Meghazi <fme@openerp.com> | 2014-04-28 20:24:51 +0200 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2014-04-28 20:24:51 +0200 |
| commit | dde0c9324bda2aff24a832ace320f23379d1ad07 (patch) | |
| tree | f201f625886fa5216d53a447effc78a69c253e61 /addons/web/controllers/testing.py | |
| parent | d60af567ad24bc4b83d916ec1834bbcd294c63e9 (diff) | |
[IMP] Convered qunit test suite to template
bzr revid: fme@openerp.com-20140428182451-u4mgen9669gnldva
Diffstat (limited to 'addons/web/controllers/testing.py')
| -rw-r--r-- | addons/web/controllers/testing.py | 172 |
1 files changed, 0 insertions, 172 deletions
diff --git a/addons/web/controllers/testing.py b/addons/web/controllers/testing.py deleted file mode 100644 index 34a0a15427f..00000000000 --- a/addons/web/controllers/testing.py +++ /dev/null @@ -1,172 +0,0 @@ -# coding=utf-8 -# -*- encoding: utf-8 -*- - -import glob -import itertools -import json -import operator -import os - -import openerp -from mako.template import Template -from openerp.modules import module -from openerp import http -from openerp.addons.web.controllers.main import ensure_db -from openerp.http import request - -from .main import module_topological_sort - -NOMODULE_TEMPLATE = Template(u"""<!DOCTYPE html> -<html> - <head> - <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> - <meta http-equiv="content-type" content="text/html; charset=utf-8" /> - <title>OpenERP Testing</title> - </head> - <body> - <form action="/web/tests" method="GET"> - <button name="mod" value="*">Run all tests</button> - <ul> - % for name, module in modules: - <li>${name} <button name="mod" value="${module}"> - Run Tests</button></li> - % endfor - </ul> - </form> - </body> -</html> -""", default_filters=['h']) -NOTFOUND = Template(u""" -<p>Unable to find the module [${module}], please check that the module - name is correct and the module is on OpenERP's path.</p> -<a href="/web/tests"><< Back to tests</a> -""", default_filters=['h']) -TESTING = Template(u"""<!DOCTYPE html> -<html style="height: 100%"> -<%def name="to_path(module, p)">/${module}/${p}</%def> -<head> - <meta http-equiv="X-UA-Compatible" content="IE=edge"/> - <meta http-equiv="content-type" content="text/html; charset=utf-8" /> - <title>OpenERP Web Tests</title> - <link rel="shortcut icon" href="/web/static/src/img/favicon.ico" type="image/x-icon"/> - - <link rel="stylesheet" href="/web/static/lib/qunit/qunit.css"> - <script src="/web/static/lib/qunit/qunit.js"></script> - - <script type="text/javascript"> - // List of modules, each module is preceded by its dependencies - var oe_all_dependencies = ${dependencies | n}; - QUnit.config.testTimeout = 5 * 60 * 1000; - </script> -</head> -<body id="oe" class="openerp"> - <div id="qunit"></div> - <div id="qunit-fixture"></div> -</body> -<!-- TODO fme: Remove manifest usage for js and css --> -${bundle('web.assets_backend') | n} -% for module, jss, tests, templates in files: - % for js in jss: - % if not js.endswith('/apps.js'): - <script src="${to_path(module, js)}"></script> - % endif - % endfor - % if tests or templates: - <script> - openerp.testing.current_module = "${module}"; - % for template in templates: - openerp.testing.add_template("${to_path(module, template)}"); - % endfor - </script> - % endif - % if tests: - % for test in tests: - <script type="text/javascript" src="${to_path(module, test)}"></script> - % endfor - % endif -% endfor -</html> -""", default_filters=['h']) - -class TestRunnerController(http.Controller): - - @http.route('/web/tests', type='http', auth="none") - def index(self, 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 request.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) - ] - - def bundle(xmlid): - dbname = request.params['source'] - registry = openerp.registry(dbname) - view_obj = registry["ir.ui.view"] - uid = openerp.SUPERUSER_ID - return view_obj.render(registry.cursor(), uid, xmlid, context=request.context) - - return TESTING.render(bundle=bundle, files=files, dependencies=json.dumps( - [name for name in sorted_mods - if module.get_module_resource(name, 'static') - # TODO fme: find a way to detect modules with js bundles - # 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, '/') - |
