web/test/unittest_pdf.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 04 Jan 2010 18:58:35 +0100
branchstable
changeset 4206 cebdf8ee5ad7
parent 3259 2c5c1f434640
child 4676 b0937a191f94
permissions -rw-r--r--
[forms] edited_entity must be set before calling session_key() EntityFieldsForm.__init__ calls FieldsForm.__init__ which in turn calls self.session_key(). self.session_key() uses self.edited_key to compute the correct session key. We thus need edited_entity to be set **before** calling super's __init__. The bug only occured when EntityFieldsForm was selected because of its one_line_rset() selector instead of match_kwargs('entity').

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.ext.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.assertEquals( len(output), len(reference) )
        # cut begin & end 'cause they contain variyng data
        self.assertTextEquals(output[150:1500], reference[150:1500])