This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
M2OLA/backend/tests/tools/pdfjinja/testInsertTemplate.py

52 lines
1.4 KiB
Python
Raw Normal View History

2017-01-23 15:20:05 +01:00
import os
import unittest
from io import BytesIO
2017-01-23 15:37:12 +01:00
from pathlib import Path
2017-01-23 17:22:55 +01:00
2017-01-23 15:20:05 +01:00
from pdfjinja import PdfJinja
2017-01-23 17:40:17 +01:00
from app.tools.InsertTemplate import remplir_template
2017-01-23 15:37:12 +01:00
2017-01-23 15:20:05 +01:00
2017-01-24 11:14:19 +01:00
class InsertTemplateTestCase(unittest.TestCase):
2017-01-23 15:20:05 +01:00
datadir = os.path.join(os.path.dirname(__file__))
def setUp(self):
pdffile = os.path.join(self.datadir, "sample.pdf")
self.data = {
2017-01-24 11:14:19 +01:00
'firstName': 'Renan',
'lastName': 'Husson',
'address': {
'street': '24 rue de la pommes',
'apt': 'C317',
'city': 'TOULOUSE',
'zipcode': 31000
},
'universite': 'Jean Jaures',
'spirit': 'Panda',
'evil': True,
'language': {
'french': True,
'esperento': True
}
}
2017-01-23 15:20:05 +01:00
self.pdfjinja = PdfJinja(pdffile)
def tearDown(self):
del self.data
del self.pdfjinja
def test_render(self):
2017-01-23 17:22:55 +01:00
remplir_template(self.datadir, "sample.pdf", self.datadir, "output.pdf", self.data)
2017-01-23 15:20:05 +01:00
output = self.pdfjinja(self.data)
outfile = BytesIO()
output.write(outfile)
outfile.seek(0)
self.assertTrue(len(outfile.read()) > 0, "Output PDF is not empty.")
2017-01-24 11:14:19 +01:00
self.assertTrue(Path(self.datadir + "/output.pdf").is_file(), "Pdf généré inexistant")
os.remove(self.datadir + "/output.pdf")
2017-01-23 15:20:05 +01:00
if __name__ == '__main__':
2017-01-24 11:14:19 +01:00
unittest.main()