Odoo18-Base/addons/attachment_indexation/tests/test_indexation.py

25 lines
794 B
Python
Raw Permalink Normal View History

2025-01-06 10:57:38 +07:00
# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase, tagged
from odoo.tools.misc import file_open
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 file_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')