From ab3c1934d5708aa843495d0eb56ce32e2b141245 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 8 Jun 2018 13:56:07 -0400 Subject: [PATCH] fix pdf tester boto3 storage returns unicode not str someplace --- core/pdf.py | 8 ++++++-- core/tests.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/pdf.py b/core/pdf.py index 5f0baf19..0931e46b 100644 --- a/core/pdf.py +++ b/core/pdf.py @@ -1,6 +1,7 @@ """ Utilities that manipulate pdf files """ +import logging import requests from xhtml2pdf import pisa # import python module from PyPDF2 import PdfFileMerger,PdfFileReader @@ -9,6 +10,7 @@ from tempfile import NamedTemporaryFile from django.template.loader import render_to_string from regluit import settings +logger = logging.getLogger(__name__) # Utility function def ask_pdf(context={}): @@ -35,7 +37,7 @@ def pdf_append( file1, file2, file_out ): def test_pdf(pdf_file): temp = None try: - if isinstance(pdf_file , str): + if isinstance(pdf_file , (str, unicode)): if pdf_file.startswith('http:') or pdf_file.startswith('https:'): temp = NamedTemporaryFile(delete=False) test_file_content = requests.get(pdf_file).content @@ -53,7 +55,9 @@ def test_pdf(pdf_file): except: success = False return success - except: + except Exception: + pdf_file = unicode(pdf_file) + logger.exception('error testing a pdf: %s' % pdf_file[:100]) return False def test_test_pdf(self): diff --git a/core/tests.py b/core/tests.py index ddd6311c..8532df09 100755 --- a/core/tests.py +++ b/core/tests.py @@ -1119,7 +1119,8 @@ class EbookFileTests(TestCase): #test the ask-appender c.add_ask_to_ebfs() if settings.AWS_SECRET_ACCESS_KEY: - assert test_pdf(c.work.ebookfiles().filter(asking=True)[0].file.url) + askingpdfurl = c.work.ebookfiles().filter(asking=True)[0].file.url + assert test_pdf(askingpdfurl) else: assert test_pdf(c.work.ebookfiles().filter(asking=True)[0].file)