aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests/test_pdf.py
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2013-03-27 12:21:10 +0200
committerAlon Levy <alon@pobox.com>2013-04-15 09:51:21 +0300
commita80ebf3b64dce807d84ab3993984c211f55b47db (patch)
tree2e8eaebf18414ee511c0dc476a2be8d78253e46f /mediagoblin/tests/test_pdf.py
parent3cadb4a6cd1d5cfdef8712d00e4594345a15b4a7 (diff)
downloadmediagoblin-a80ebf3b64dce807d84ab3993984c211f55b47db.tar.lz
mediagoblin-a80ebf3b64dce807d84ab3993984c211f55b47db.tar.xz
mediagoblin-a80ebf3b64dce807d84ab3993984c211f55b47db.zip
add pdf media type
The new media type supports pdf and a subset of media recognized by libreoffice via unoconv. Every document added goes through: * conversion to pdf with unoconv if not already a pdf * creation of thumbnail and medium sized image, and pdfinfo generates some information (even for unoconv produces docs - should fix this) Poppler (pdftocairo, pdfinfo) is used. http://poppler.freedesktop.org/ A working but uglified pdf.js integration exists, which is enabled by setting pdf.pdf_js=true mediagoblin_local.ini (disabled in mediagoblin.ini) Adds one test to the test_submission test suite, and another separate test_pdf suite. The tests are only run if media_types.pdf.processing.check_prerequisites passes, so the test suite will not require any extra package. TODO: make test suite say 'skipped' in that case instead of just 'ok' Signed-off-by: Alon Levy <alon@pobox.com>
Diffstat (limited to 'mediagoblin/tests/test_pdf.py')
-rw-r--r--mediagoblin/tests/test_pdf.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/mediagoblin/tests/test_pdf.py b/mediagoblin/tests/test_pdf.py
new file mode 100644
index 00000000..ee3083ef
--- /dev/null
+++ b/mediagoblin/tests/test_pdf.py
@@ -0,0 +1,45 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2013 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import tempfile
+import shutil
+import os
+
+from mediagoblin.tests.tools import fixture_add_collection, fixture_add_user, \
+ get_app
+from mediagoblin.db.models import Collection, User
+from mediagoblin.db.base import Session
+from nose.tools import assert_equal
+
+from mediagoblin.media_types.pdf.processing import (
+ pdf_info, check_prerequisites, create_pdf_thumb)
+
+GOOD='mediagoblin/tests/test_submission/good.pdf'
+
+def test_pdf():
+ if not check_prerequisites():
+ return
+ good_dict = {'pdf_version_major': 1, 'pdf_title': '',
+ 'pdf_page_size_width': 612, 'pdf_author': '',
+ 'pdf_keywords': '', 'pdf_pages': 10,
+ 'pdf_producer': 'dvips + GNU Ghostscript 7.05',
+ 'pdf_version_minor': 3,
+ 'pdf_creator': 'LaTeX with hyperref package',
+ 'pdf_page_size_height': 792}
+ assert pdf_info(GOOD) == good_dict
+ temp_dir = tempfile.mkdtemp()
+ create_pdf_thumb(GOOD, os.path.join(temp_dir, 'good_256_256.png'), 256, 256)
+ shutil.rmtree(temp_dir)