diff --git a/odoo/addons/base/tests/__init__.py b/odoo/addons/base/tests/__init__.py index 81a12552ff2..54a68834374 100644 --- a/odoo/addons/base/tests/__init__.py +++ b/odoo/addons/base/tests/__init__.py @@ -8,6 +8,7 @@ from . import test_db_cursor from . import test_expression from . import test_float from . import test_func +from . import test_http_case from . import test_image from . import test_ir_actions from . import test_ir_attachment diff --git a/odoo/addons/base/tests/test_http_case.py b/odoo/addons/base/tests/test_http_case.py new file mode 100644 index 00000000000..1ab44b901cb --- /dev/null +++ b/odoo/addons/base/tests/test_http_case.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests.common import HttpCase, tagged +from odoo.tools import mute_logger +from unittest.mock import patch + +@tagged('-at_install', 'post_install') +class TestHttpCase(HttpCase): + + def test_console_error_string(self): + with self.assertRaises(AssertionError) as error_catcher: + code = "console.error('test error','message')" + with patch('odoo.tests.common.ChromeBrowser.take_screenshot', return_value=None): + self.browser_js(url_path='about:blank', code=code) + # second line must contains error message + self.assertEqual(error_catcher.exception.args[0].split('\n', 1)[1], "test error message") + + def test_console_error_object(self): + with self.assertRaises(AssertionError) as error_catcher: + code = "console.error(TypeError('test error ' + 'message'))" + with patch('odoo.tests.common.ChromeBrowser.take_screenshot', return_value=None): + self.browser_js(url_path='about:blank', code=code) + # second line must contains error message + self.assertEqual(error_catcher.exception.args[0].split('\n', 1)[1], + 'TypeError: test error message\n at :1:15') + + def test_console_log_object(self): + with self.assertLogs() as log_catcher: + code = "console.log({custom:{1:'test', 2:'a'}, value:1, description:'dummy'});console.log('test successful');" + self.browser_js(url_path='about:blank', code=code) + console_log_count = 0 + for log in log_catcher.output: + if 'console log' in log: + text = log.split('console log: ', 1)[1] + if text == 'test successful': + continue + self.assertEqual(log.split('console log: ', 1)[1], "Object\n{custom:Object, value:1, description:'dummy'}") + console_log_count +=1 + self.assertEqual(console_log_count, 1) diff --git a/odoo/tests/common.py b/odoo/tests/common.py index 063f1d51e07..67cabbb4f10 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -834,7 +834,23 @@ class ChromeBrowser(): elif res and res.get('method') == 'Runtime.consoleAPICalled' and res.get('params', {}).get('type') in ('log', 'error', 'trace'): logs = res.get('params', {}).get('args') log_type = res.get('params', {}).get('type') - content = " ".join([str(log.get('value', '')) for log in logs]) + content = [] + for log in logs: + text = '' + if log.get('type') == 'string': + text = str(log.get('value', '`Empty string`')) + elif log.get('type') == 'object' and 'Error' in log.get('className', '') and log.get('description'): + text = str(log.get('description')) + else: + type_ = log.get('className') or log.get('type') + properties = log.get('preview', {}).get('properties') + if log.get('type') == 'object' and properties and all(p.get('name') is not None and p.get('value') is not None for p in properties): + elems = ['%s:%s' % (p.get('name'), "'%s'" % p.get('value') if p.get('type') == 'string' else p.get('value')) for p in properties] + text = "%s\n{%s}" % (type_, ", ".join(elems)) + else: + text = str(log) + content.append(text) + content = " ".join(content) if log_type == 'error': self.take_screenshot() self._save_screencast() @@ -1026,7 +1042,10 @@ class HttpCase(TransactionCase): # flush updates to the database before launching the client side, # otherwise they simply won't be visible ICP.flush() - url = "%s%s" % (base_url, url_path or '/') + if re.match('[a-z]*:', url_path or ''): # about:, http:, ... + url = url_path + else: + url = "%s%s" % (base_url, url_path or '/') self._logger.info('Open "%s" in browser', url) if self.browser.screencasts_dir: