Files
odoo_source/addons/attachment_indexation/tests/test_indexation.py
T
Christophe Monniez 6fa4dbf204 [FIX] attachement_indexation: make pdfminer optional
As pdfminer does not have a Debian package in Ubuntu Bionic, it cannot
be declared as a strong requirement.

With this commit, a warning is logged if the library is not installed.
It does not prevent to index other types of documents.

closes odoo/odoo#44327

Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
2020-01-31 14:37:56 +00:00

24 lines
751 B
Python

# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase, tagged
from unittest import skipIf
import os
directory = os.path.dirname(__file__)
try:
from pdfminer.pdfinterp import PDFResourceManager
except ImportError:
PDFResourceManager = None
@tagged('post_install', '-at_install')
class TestCaseIndexation(TransactionCase):
@skipIf(PDFResourceManager is None, "pdfminer not installed")
def test_attachment_pdf_indexation(self):
with open(os.path.join(directory, 'files', 'test_content.pdf'), 'rb') as file:
pdf = file.read()
text = self.env['ir.attachment']._index(pdf, 'application/pdf')
self.assertEqual(text, 'TestContent!!\x0c', 'the index content should be correct')