fix pdf tester

boto3 storage returns unicode not str someplace
pull/91/head
eric 2018-06-08 13:56:07 -04:00
parent ca5e5bed0c
commit ab3c1934d5
2 changed files with 8 additions and 3 deletions

View File

@ -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):

View File

@ -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)