From 3881d0fd9d67ed5692326a28aabfcc14b2caacbc Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 19 Dec 2022 13:00:15 -0700 Subject: [PATCH] Only getting PDF title's once. --- wrolpi/files/pdfs.py | 3 ++- wrolpi/files/test/test_pdfs.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/wrolpi/files/pdfs.py b/wrolpi/files/pdfs.py index 26986816..5d3dc329 100644 --- a/wrolpi/files/pdfs.py +++ b/wrolpi/files/pdfs.py @@ -29,7 +29,8 @@ def model_pdf(groups: Dict[str, List[File]], _: Session): logger.warning(f'Cannot get title from PDF without PyPDF2') return - pdf_files = (file for group in groups.values() for file in group if file.mimetype == 'application/pdf') + pdf_files = (file for group in groups.values() for file in group if + file.indexed is not True and file.mimetype == 'application/pdf') for file in pdf_files: path: pathlib.Path = file.path.path if hasattr(file.path, 'path') else file.path diff --git a/wrolpi/files/test/test_pdfs.py b/wrolpi/files/test/test_pdfs.py index 264153b6..731efb66 100644 --- a/wrolpi/files/test/test_pdfs.py +++ b/wrolpi/files/test/test_pdfs.py @@ -1,3 +1,5 @@ +from unittest import mock + import pytest from wrolpi.files.lib import refresh_files @@ -9,5 +11,9 @@ async def test_pdf_title(test_session, example_pdf): """PDF modeler extracts the PDF's title.""" await refresh_files() + with mock.patch('wrolpi.files.pdfs.get_pdf_title') as mock_get_pdf_title: + mock_get_pdf_title.side_effect = Exception('should not be read again') + await refresh_files() + pdf: File = test_session.query(File).one() assert pdf.title == 'WROLPi Test PDF'