mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-27 19:08:42 -06:00
[FIX] CI
[ADD] tests for attachments_to_filesystem
This commit is contained in:
parent
8d69a35d61
commit
d3a37e5010
@ -53,7 +53,7 @@ class IrAttachment(models.Model):
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = process.communicate(image_data.getvalue())
|
||||
if stderr:
|
||||
if process.returncode:
|
||||
_logger.error('Error during OCR: %s', stderr)
|
||||
return stdout
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from StringIO import StringIO
|
||||
from openerp.tests.common import TransactionCase
|
||||
from openerp.addons.document_ocr.models.ir_attachment import _MARKER_PHRASE
|
||||
from ..models.ir_attachment import _MARKER_PHRASE
|
||||
from openerp.tools.misc import mute_logger
|
||||
|
||||
|
||||
class TestDocumentOcr(TransactionCase):
|
||||
@ -21,7 +22,10 @@ class TestDocumentOcr(TransactionCase):
|
||||
result = self.env['ir.attachment']._index(
|
||||
data.getvalue(), 'test.png', None)
|
||||
self.assertEqual(result[1].strip(), 'Hello world')
|
||||
# should also work for pdfs
|
||||
# should also work for pdfs if supported, protect against
|
||||
# ancient pillows
|
||||
if hasattr(Image, 'registered_extensions') and\
|
||||
'PDF' in Image.registered_extensions().values():
|
||||
data = StringIO()
|
||||
test_image.save(data, 'pdf', resolution=300)
|
||||
result = self.env['ir.attachment']._index(
|
||||
@ -38,11 +42,17 @@ class TestDocumentOcr(TransactionCase):
|
||||
attachment._ocr_cron()
|
||||
self.assertEqual(attachment.index_content.strip(), 'Hello world')
|
||||
# and for an unreadable image, we expect an error
|
||||
if hasattr(Image, 'registered_extensions') and\
|
||||
'PALM' in Image.registered_extensions().values():
|
||||
self.env['ir.config_parameter'].set_param(
|
||||
'document_ocr.synchronous', 'True')
|
||||
data = StringIO()
|
||||
test_image = Image.new('1', (200, 30))
|
||||
test_image.save(data, 'Palm')
|
||||
with mute_logger(
|
||||
'openerp.addons.document_ocr.models.ir_attachment'
|
||||
):
|
||||
result = self.env['ir.attachment']._index(
|
||||
data.getvalue(), 'test.palm', None)
|
||||
data.getvalue(), 'test.palm', None
|
||||
)
|
||||
self.assertEqual(result[1], None)
|
||||
|
Loading…
Reference in New Issue
Block a user