Entirely removes the optipng, updates ghostscript fall back to also use WebP. Updates the conversion to use a multiprocessing pool

This commit is contained in:
Trenton Holmes
2022-06-11 08:38:49 -07:00
parent ec4630a846
commit ef6ebf9888
17 changed files with 65 additions and 162 deletions

View File

@@ -183,7 +183,7 @@ class DummyParser(DocumentParser):
_, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir)
self.archive_path = archive_path
def get_optimised_thumbnail(self, document_path, mime_type, file_name=None):
def get_thumbnail(self, document_path, mime_type, file_name=None):
return self.fake_thumb
def parse(self, document_path, mime_type, file_name=None):
@@ -194,7 +194,7 @@ class CopyParser(DocumentParser):
def get_thumbnail(self, document_path, mime_type, file_name=None):
return self.fake_thumb
def get_optimised_thumbnail(self, document_path, mime_type, file_name=None):
def get_thumbnail(self, document_path, mime_type, file_name=None):
return self.fake_thumb
def __init__(self, logging_group, progress_callback=None):
@@ -216,7 +216,7 @@ class FaultyParser(DocumentParser):
super().__init__(logging_group)
_, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir)
def get_optimised_thumbnail(self, document_path, mime_type, file_name=None):
def get_thumbnail(self, document_path, mime_type, file_name=None):
return self.fake_thumb
def parse(self, document_path, mime_type, file_name=None):

View File

@@ -137,32 +137,3 @@ class TestConvertThumbnails(TestCase):
run_convert_mock.assert_called_once()
self.assertIn("Error converting thumbnail", stderr)
self.assertTrue(thumb_file.exists())
@mock.patch("documents.management.commands.convert_thumbnails.run_convert")
def test_convert_single_thumbnail_no_output(self, run_convert_mock):
"""
GIVEN:
- Document exists with PNG thumbnail
WHEN:
- Thumbnail conversion is attempted, but there is no output WebP
THEN:
- Single thumbnail is converted
"""
with tempfile.TemporaryDirectory() as thumbnail_dir:
with override_settings(
THUMBNAIL_DIR=thumbnail_dir,
):
thumb_file = self.create_png_thumbnail_file(thumbnail_dir)
stdout, stderr = self.call_command()
run_convert_mock.assert_called_once()
self.assertIn(f"{thumb_file}", stdout)
self.assertNotIn("Conversion to WebP completed", stdout)
self.assertIn("Converted thumbnail doesn't exist", stderr)
self.assertTrue(thumb_file.exists())
self.assertFalse(thumb_file.with_suffix(".webp").exists())

View File

@@ -87,31 +87,6 @@ def fake_get_thumbnail(self, path, mimetype, file_name):
return os.path.join(os.path.dirname(__file__), "examples", "no-text.png")
class TestBaseParser(TestCase):
def setUp(self) -> None:
self.scratch = tempfile.mkdtemp()
override_settings(SCRATCH_DIR=self.scratch).enable()
def tearDown(self) -> None:
shutil.rmtree(self.scratch)
@mock.patch("documents.parsers.DocumentParser.get_thumbnail", fake_get_thumbnail)
@override_settings(OPTIMIZE_THUMBNAILS=True)
def test_get_optimised_thumbnail(self):
parser = DocumentParser(None)
parser.get_optimised_thumbnail("any", "not important", "document.pdf")
@mock.patch("documents.parsers.DocumentParser.get_thumbnail", fake_get_thumbnail)
@override_settings(OPTIMIZE_THUMBNAILS=False)
def test_get_optimised_thumb_disabled(self):
parser = DocumentParser(None)
path = parser.get_optimised_thumbnail("any", "not important", "document.pdf")
self.assertEqual(path, fake_get_thumbnail(None, None, None, None))
class TestParserAvailability(TestCase):
def test_file_extensions(self):