Files
odoo_source/odoo/addons/base/tests/test_http_case.py
T
Xavier Morel 07ecd396b0 [ADD] core: error if a test finishes with a form being edited
Since 54ea956490 the form view has an
"urgentSave" fallback when the page is unloaded (tab closed, page
navigated away from, ...).

In tours, this translates to new network requests being performed
during the browser cleanup, possibly chaining further into more
network events.

Flag these tours as incorrect (by making them fail if we find a form
in edition mode after receiving `"test successful"`).

Adjust testing of http cases because I've added an empty line between
the signal and the actual message for better readability on complex
error messages.

Also provide opt-out, as for some tours it's difficult to impossible to
truly fix them: the `allow_end_on_form` class attribute can be set to
`True` in order to disable the new behaviour.

To implement this, update the browser runner receive the test class
directly (rather than just the test class' name) for more
introspection flexibility.

Part-of: odoo/odoo#96517
2022-08-04 09:14:09 +02:00

52 lines
2.5 KiB
Python

# -*- 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, logging
from unittest.mock import patch
@tagged('-at_install', 'post_install')
class TestHttpCase(HttpCase):
def test_console_error_string(self):
with self.assertLogs(level='ERROR') as log_catcher:
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].splitlines()[-1], "test error message")
self.assertEqual(len(log_catcher.output), 1)
self.assertIn('test error message', log_catcher.output[0])
def test_console_error_object(self):
with self.assertLogs(level='ERROR') as log_catcher:
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].splitlines()[-2:],
['TypeError: test error message', ' at <anonymous>:1:15'])
self.assertEqual(len(log_catcher.output), 1)
self.assertIn('TypeError: test error message\n at <anonymous>:1:15', log_catcher.output[0])
def test_console_log_object(self):
logger = logging.getLogger('odoo')
level = logger.level
logger.setLevel(logging.INFO)
self.addCleanup(logger.setLevel, level)
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 '.browser:' in log:
text = log.split('.browser:', 1)[1]
if text == 'test successful':
continue
self.assertEqual(text, "Object(custom=Object, value=1, description='dummy')")
console_log_count +=1
self.assertEqual(console_log_count, 1)