Browse Source

[FIX] Adapt to newer versions of python-ldap and lxml

[IMP] Mute ERROR level log messages from false positives
pull/391/head
Stefan Rijnhart 7 years ago
committed by Holger Brunn
parent
commit
f86d4cad8e
  1. 11
      database_cleanup/tests/test_database_cleanup.py
  2. 5
      dead_mans_switch_client/tests/test_dead_mans_switch_client.py
  3. 32
      html_image_url_extractor/tests/test_extractor.py
  4. 31
      html_text/tests/test_extractor.py
  5. 2
      users_ldap_push/models/res_users.py

11
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')

5
dead_mans_switch_client/tests/test_dead_mans_switch_client.py

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# © 2015 Therp BV <http://therp.nl>
# 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')

32
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 <img> 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("<<bad>"):
self.assertTrue(False) # You should never get here
with mute_logger(self.logger):
for laps, text in self.imgs_from_html("<<bad>"):
self.assertTrue(False) # You should never get here
with self.assertRaises(etree.ParserError):
list(self.imgs_from_html("<<bad>", fail=True))
try:
# Newer versions of lxml parse this as
# '<html><body><p>&lt;<bad/></p></body></html>'
# so the exception is not guaranteed
with mute_logger(self.logger):
images = list(self.imgs_from_html("<<bad>", fail=True))
self.assertFalse(images)
except etree.ParserError:
pass

31
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("<<bad>"), "")
with self.assertRaises(etree.ParserError):
self.text_from_html("<<bad>", fail=True)
"""Bad HTML handled correctly.
Newer versions of lxml parse this as
'<html><body><p>&lt;<bad/></p></body></html>'
so the exception is not guaranteed and the result may vary. """
with mute_logger(self.logger):
self.assertIn(self.text_from_html("<<bad>"), ("<", ""))
try:
with mute_logger(self.logger):
res = self.text_from_html("<<bad>", fail=True)
self.assertEqual(res, "<")
except etree.ParserError:
pass

2
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(',')

Loading…
Cancel
Save