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. 3
      database_cleanup/tests/test_database_cleanup.py
  2. 3
      dead_mans_switch_client/tests/test_dead_mans_switch_client.py
  3. 18
      html_image_url_extractor/tests/test_extractor.py
  4. 23
      html_text/tests/test_extractor.py
  5. 2
      users_ldap_push/models/res_users.py

3
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,6 +17,7 @@ class TestDatabaseCleanup(TransactionCase):
purge_columns.purge_all()
# must be removed by the wizard
with self.assertRaises(ProgrammingError):
with mute_logger('openerp.sql_db'):
with self.registry.cursor() as cr:
cr.execute('select database_cleanup_test from res_users')
@ -82,5 +84,6 @@ class TestDatabaseCleanup(TransactionCase):
lambda x: x.name == 'database_cleanup_test'
).purge()
with self.assertRaises(ProgrammingError):
with mute_logger('openerp.sql_db'):
with self.registry.cursor() as cr:
self.env.cr.execute('select * from database_cleanup_test')

3
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,6 +10,8 @@ class TestDeadMansSwitchClient(TransactionCase):
# test unconfigured case
self.env['ir.config_parameter'].search([
('key', '=', 'dead_mans_switch_client.url')]).unlink()
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(

18
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,14 +49,17 @@ class ExtractorCase(TransactionCase):
def test_empty_html(self):
"""Empty HTML handled correctly."""
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):
with mute_logger(self.logger):
list(self.imgs_from_html("", fail=True))
def test_false_html(self):
"""``False`` HTML handled correctly."""
with mute_logger(self.logger):
for laps, text in self.imgs_from_html(False):
self.assertTrue(False) # You should never get here
@ -62,8 +68,16 @@ class ExtractorCase(TransactionCase):
def test_bad_html(self):
"""Bad HTML handled correctly."""
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

23
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."""
with mute_logger(self.logger):
self.assertEqual(self.text_from_html(""), "")
with self.assertRaises(etree.XMLSyntaxError):
with mute_logger(self.logger):
self.text_from_html("", fail=True)
def test_false_html(self):
"""``False`` HTML handled correctly."""
with mute_logger(self.logger):
self.assertEqual(self.text_from_html(False), "")
with self.assertRaises(TypeError):
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