diff --git a/database_cleanup/tests/test_database_cleanup.py b/database_cleanup/tests/test_database_cleanup.py index f9aa51c54..df23e46de 100644 --- a/database_cleanup/tests/test_database_cleanup.py +++ b/database_cleanup/tests/test_database_cleanup.py @@ -4,6 +4,7 @@ from psycopg2 import ProgrammingError from openerp.modules.registry import RegistryManager from openerp.tools import config +from openerp.tools.misc import mute_logger from openerp.tests.common import TransactionCase @@ -16,8 +17,9 @@ class TestDatabaseCleanup(TransactionCase): purge_columns.purge_all() # must be removed by the wizard with self.assertRaises(ProgrammingError): - with self.registry.cursor() as cr: - cr.execute('select database_cleanup_test from res_users') + with mute_logger('openerp.sql_db'): + with self.registry.cursor() as cr: + cr.execute('select database_cleanup_test from res_users') # create a data entry pointing nowhere self.cr.execute('select max(id) + 1 from res_users') @@ -82,5 +84,6 @@ class TestDatabaseCleanup(TransactionCase): lambda x: x.name == 'database_cleanup_test' ).purge() with self.assertRaises(ProgrammingError): - with self.registry.cursor() as cr: - self.env.cr.execute('select * from database_cleanup_test') + with mute_logger('openerp.sql_db'): + with self.registry.cursor() as cr: + self.env.cr.execute('select * from database_cleanup_test') diff --git a/dead_mans_switch_client/tests/test_dead_mans_switch_client.py b/dead_mans_switch_client/tests/test_dead_mans_switch_client.py index e4d849f93..84a9200e2 100644 --- a/dead_mans_switch_client/tests/test_dead_mans_switch_client.py +++ b/dead_mans_switch_client/tests/test_dead_mans_switch_client.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # © 2015 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp.tools.misc import mute_logger from openerp.tests.common import TransactionCase @@ -9,7 +10,9 @@ class TestDeadMansSwitchClient(TransactionCase): # test unconfigured case self.env['ir.config_parameter'].search([ ('key', '=', 'dead_mans_switch_client.url')]).unlink() - self.env['dead.mans.switch.client'].alive() + with mute_logger('openerp.addons.dead_mans_switch_client.models' + '.dead_mans_switch_client'): + self.env['dead.mans.switch.client'].alive() # test configured case self.env['ir.config_parameter'].set_param( 'dead_mans_switch_client.url', 'fake_url') diff --git a/html_image_url_extractor/tests/test_extractor.py b/html_image_url_extractor/tests/test_extractor.py index c511aa5f8..674ab39be 100644 --- a/html_image_url_extractor/tests/test_extractor.py +++ b/html_image_url_extractor/tests/test_extractor.py @@ -3,6 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from lxml import etree +from openerp.tools.misc import mute_logger from openerp.tests.common import TransactionCase @@ -12,6 +13,8 @@ class ExtractorCase(TransactionCase): # Shortcut self.imgs_from_html = self.env["ir.fields.converter"].imgs_from_html + self.logger = ('openerp.addons.html_image_url_extractor' + '.models.ir_fields_converter') def test_mixed_images_found(self): """Images correctly found in elements and backgrounds.""" @@ -46,24 +49,35 @@ class ExtractorCase(TransactionCase): def test_empty_html(self): """Empty HTML handled correctly.""" - for laps, text in self.imgs_from_html(""): - self.assertTrue(False) # You should never get here + with mute_logger(self.logger): + for laps, text in self.imgs_from_html(""): + self.assertTrue(False) # You should never get here with self.assertRaises(etree.XMLSyntaxError): - list(self.imgs_from_html("", fail=True)) + with mute_logger(self.logger): + list(self.imgs_from_html("", fail=True)) def test_false_html(self): """``False`` HTML handled correctly.""" - for laps, text in self.imgs_from_html(False): - self.assertTrue(False) # You should never get here + with mute_logger(self.logger): + for laps, text in self.imgs_from_html(False): + self.assertTrue(False) # You should never get here with self.assertRaises(TypeError): list(self.imgs_from_html(False, fail=True)) def test_bad_html(self): """Bad HTML handled correctly.""" - for laps, text in self.imgs_from_html("<"): - self.assertTrue(False) # You should never get here + with mute_logger(self.logger): + for laps, text in self.imgs_from_html("<"): + self.assertTrue(False) # You should never get here - with self.assertRaises(etree.ParserError): - list(self.imgs_from_html("<", fail=True)) + try: + # Newer versions of lxml parse this as + # '

<

' + # so the exception is not guaranteed + with mute_logger(self.logger): + images = list(self.imgs_from_html("<", fail=True)) + self.assertFalse(images) + except etree.ParserError: + pass diff --git a/html_text/tests/test_extractor.py b/html_text/tests/test_extractor.py index 22443e32a..aa056203d 100644 --- a/html_text/tests/test_extractor.py +++ b/html_text/tests/test_extractor.py @@ -3,6 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from lxml import etree +from openerp.tools.misc import mute_logger from openerp.tests.common import TransactionCase @@ -12,6 +13,7 @@ class ExtractorCase(TransactionCase): # Shortcut self.text_from_html = self.env["ir.fields.converter"].text_from_html + self.logger = 'openerp.addons.html_text.models.ir_fields_converter' def test_excerpts(self): """Text gets correctly extracted.""" @@ -42,18 +44,31 @@ class ExtractorCase(TransactionCase): def test_empty_html(self): """Empty HTML handled correctly.""" - self.assertEqual(self.text_from_html(""), "") + with mute_logger(self.logger): + self.assertEqual(self.text_from_html(""), "") with self.assertRaises(etree.XMLSyntaxError): - self.text_from_html("", fail=True) + with mute_logger(self.logger): + self.text_from_html("", fail=True) def test_false_html(self): """``False`` HTML handled correctly.""" - self.assertEqual(self.text_from_html(False), "") + with mute_logger(self.logger): + self.assertEqual(self.text_from_html(False), "") with self.assertRaises(TypeError): - self.text_from_html(False, fail=True) + with mute_logger(self.logger): + self.text_from_html(False, fail=True) def test_bad_html(self): - """Bad HTML handled correctly.""" - self.assertEqual(self.text_from_html("<"), "") - with self.assertRaises(etree.ParserError): - self.text_from_html("<", fail=True) + """Bad HTML handled correctly. + Newer versions of lxml parse this as + '

<

' + so the exception is not guaranteed and the result may vary. """ + with mute_logger(self.logger): + self.assertIn(self.text_from_html("<"), ("<", "")) + + try: + with mute_logger(self.logger): + res = self.text_from_html("<", fail=True) + self.assertEqual(res, "<") + except etree.ParserError: + pass diff --git a/users_ldap_push/models/res_users.py b/users_ldap_push/models/res_users.py index b819488f0..bfb13a34e 100644 --- a/users_ldap_push/models/res_users.py +++ b/users_ldap_push/models/res_users.py @@ -67,7 +67,7 @@ class ResUsers(models.Model): field_name = mapping.field_id.name if field_name not in values or not values[field_name]: continue - result[mapping.attribute] = [str(values[field_name])] + result[str(mapping.attribute)] = [str(values[field_name])] if result: result['objectClass'] = conf.create_ldap_entry_objectclass\ .encode('utf-8').split(',')