Commit db5115d8 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Cédric Le Ninivin

wkhtmltopdf: reduce test code

parent e86de962
...@@ -37,38 +37,31 @@ class TestHandler(HandlerTestCase): ...@@ -37,38 +37,31 @@ class TestHandler(HandlerTestCase):
def afterSetUp(self): def afterSetUp(self):
self.kw = dict(env=dict(PATH=self.env_path)) self.kw = dict(env=dict(PATH=self.env_path))
def testConvertHtmlWithPngDataUrlToPdf(self): def _testBase(self, html_path, **conversion_kw):
"""Test conversion of html with png data url to pdf""" html_file = open(html_path).read()
html_file = open("data/test_with_png_dataurl.html").read()
handler = Handler(self.tmp_url, html_file, "html", **self.kw) handler = Handler(self.tmp_url, html_file, "html", **self.kw)
pdf_file = handler.convert("pdf") pdf_file = handler.convert("pdf", **conversion_kw)
mime = magic.Magic(mime=True) mime = magic.Magic(mime=True)
pdf_mimetype = mime.from_buffer(pdf_file) pdf_mimetype = mime.from_buffer(pdf_file)
self.assertEquals("application/pdf", pdf_mimetype) self.assertEquals("application/pdf", pdf_mimetype)
def testConvertHtmlWithPngDataUrlToPdf(self):
"""Test conversion of html with png data url to pdf"""
self._testBase("data/test_with_png_dataurl.html")
def testConvertHtmlWithScriptToPdf(self): def testConvertHtmlWithScriptToPdf(self):
"""Test conversion of html with script to pdf""" """Test conversion of html with script to pdf"""
html_file = open("data/test_with_script.html").read() self._testBase("data/test_with_script.html")
handler = Handler(self.tmp_url, html_file, "html", **self.kw)
pdf_file = handler.convert("pdf")
mime = magic.Magic(mime=True)
pdf_mimetype = mime.from_buffer(pdf_file)
self.assertEquals("application/pdf", pdf_mimetype)
# TODO: def testConvertHtmlWithHeaderAndFooter(self): # TODO: def testConvertHtmlWithHeaderAndFooter(self):
def testConvertHtmlWithTableOfContent(self): def testConvertHtmlWithTableOfContent(self):
"""Test conversion of html with an additional table of content""" """Test conversion of html with an additional table of content"""
html_file = open("data/test_with_toc.html").read() self._testBase(
handler = Handler(self.tmp_url, html_file, "html", **self.kw) "data/test_with_toc.html",
pdf_file = handler.convert(
"pdf",
toc=True, toc=True,
xsl_style_sheet_data=b64encode(open("data/test_toc.xsl").read()), xsl_style_sheet_data=b64encode(open("data/test_toc.xsl").read()),
) )
mime = magic.Magic(mime=True)
pdf_mimetype = mime.from_buffer(pdf_file)
self.assertEquals("application/pdf", pdf_mimetype)
# XXX how to check for table of content presence ? # XXX how to check for table of content presence ?
def testsetMetadata(self): def testsetMetadata(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment