Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

more test

Jonas Winkler39fa02dcb1cc
diff --git a/.travis.yml b/.travis.yml
index 248eebb64..d5b3c2efb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,7 +33,7 @@ jobs:
before_install:
- sudo apt-get update -qq
- - sudo apt-get install -qq libpoppler-cpp-dev unpaper tesseract-ocr imagemagick ghostscript
+ - sudo apt-get install -qq libpoppler-cpp-dev unpaper tesseract-ocr imagemagick ghostscript optipng
install:
- pip install --upgrade pipenv
diff --git a/src/documents/tests/examples/no-text.png b/src/documents/tests/examples/no-text.png
new file mode 100644
index 000000000..e78b22bfb
Binary files /dev/null and b/src/documents/tests/examples/no-text.png differ
diff --git a/src/documents/tests/test_parsers.py b/src/documents/tests/test_parsers.py
index 239203186..705dcb08d 100644
--- a/src/documents/tests/test_parsers.py
+++ b/src/documents/tests/test_parsers.py
@@ -1,10 +1,12 @@
import os
+import shutil
+import tempfile
from tempfile import TemporaryDirectory
from unittest import mock
-from django.test import TestCase
+from django.test import TestCase, override_settings
-from documents.parsers import get_parser_class
+from documents.parsers import get_parser_class, DocumentParser
def fake_magic_from_file(file, mime=False):
@@ -61,3 +63,35 @@ class TestParserDiscovery(TestCase):
self.assertIsNone(
get_parser_class("doc.pdf")
)
+
+
+def fake_get_thumbnail(self, path, mimetype):
+ 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)
+ def test_get_optimised_thumbnail(self):
+ parser = DocumentParser(None)
+
+ parser.get_optimised_thumbnail("any", "not important")
+
+ @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")
+ self.assertEqual(path, fake_get_thumbnail(None, None, None))
+