# HG changeset patch # User Aurelien Campeas # Date 1250844285 -7200 # Node ID 6e871df3005805b1d5bd5ff0193bc4f4c689c8fa # Parent a2aa2c51f3bed6d060a353b67f3e984651414e2b [pdf,tests] test the pdf tranformation diff -r a2aa2c51f3be -r 6e871df30058 web/test/data/sample1.pdf Binary file web/test/data/sample1.pdf has changed diff -r a2aa2c51f3be -r 6e871df30058 web/test/data/sample1.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/test/data/sample1.xml Fri Aug 21 10:44:45 2009 +0200 @@ -0,0 +1,138 @@ + + + + + ] > + + + + + + + +Comet 0.2.0 (unset title) + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+
+ +
+
+ + \ No newline at end of file diff -r a2aa2c51f3be -r 6e871df30058 web/test/unittest_pdf.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/test/unittest_pdf.py Fri Aug 21 10:44:45 2009 +0200 @@ -0,0 +1,34 @@ +from unittest import TestCase +import os.path as osp +from xml.etree.cElementTree import ElementTree, fromstring, tostring, dump + +from tempfile import NamedTemporaryFile +from subprocess import Popen as sub + +from cubicweb.utils import can_do_pdf_conversion + +from cubicweb.web.xhtml2fo import ReportTransformer + +DATADIR = osp.join(osp.dirname(__file__), 'data') + +class PDFTC(TestCase): + + def test_xhtml_to_fop_to_pdf(self): + if not can_do_pdf_conversion(): + self.skip('dependencies not available : check pysixt and fop') + xmltree = ElementTree() + xmltree.parse(osp.join(DATADIR, 'sample1.xml')) + foptree = ReportTransformer(u'contentmain').transform(xmltree) + # next + foptmp = NamedTemporaryFile() + foptree.write(foptmp) + foptmp.flush() + pdftmp = NamedTemporaryFile() + fopproc = sub(['/usr/bin/fop', foptmp.name, pdftmp.name]) + fopproc.wait() + del foptmp + pdftmp.seek(0) # a bit superstitious + reference = open(osp.join(DATADIR, 'sample1.pdf'), 'r').read() + output = pdftmp.read() + # XXX almost equals due to ID, creation date, so it seems to fail + self.assertTextEquals(output, reference)