TG-35 : Typo

This commit is contained in:
Clément ARNAUDEAU 2017-01-23 15:50:20 +01:00
commit ed0f2b1808
9 changed files with 105 additions and 5 deletions

View File

@ -0,0 +1,25 @@
#pdfjinja 1.0.0
##Dependencies :
python-dev
python-pip
libtiff5-dev
libjpeg8-dev
zlib1g-dev
libfreetype6-dev
liblcms2-dev
libwebp-dev
tcl8.6-dev
tk8.6-dev
python-tk
pdftk
libmagickwand-dev
##Installation:
pip install pdfjinja
##Test :
pdfjinja -h

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
""" Script python qui remplie les pdf basés sur un template jinja. """
import os
from pdfjinja import PdfJinja
def remplirTemplate (dirname_template, pdf_template, dirname_output_file, pdf_output,dictionnaire):
"""
Fonction qui permet de remplir un pdf template
:param dirname_template: chemin du fichier de template
:param pdf_template: nom du fichier de template
:param dirname_output_file: chemin des pdf généré
:param pdf_output: nom du fichier pdf à générer
:param dictionnaire: dictionnaire contenant le nom des textfields des pdf ainsi que leurs valeurs
:return:
"""
template_pdf_file = os.path.join(dirname_template, pdf_template)
template_pdf = PdfJinja(template_pdf_file)
rendered_pdf = template_pdf(dictionnaire)
output_file = os.path.join(dirname_output_file, pdf_output)
rendered_pdf.write(open(output_file, 'wb'))

View File

@ -5,11 +5,11 @@ from hashlib import sha512
SIMPLE_CHARS = string.ascii_letters + string.digits
def get_random_string(length=24):
def get_random_string(length=32):
return ''.join(random.choice(SIMPLE_CHARS) for i in range(length))
def get_random_hash(length=24):
def get_random_hash(length=64):
hash = sha512()
hash.update(get_random_string())
return hash.hexdigest()[:length]

View File

@ -76,8 +76,6 @@ class RunTests(Command):
"""Seed the db """
def run(self):
Config.configure_app(config="test")
os.system("python manage.py -t db downgrade base")
os.system("python manage.py -t db upgrade")
test_loader = unittest.defaultTestLoader
test_runner = unittest.TextTestRunner()
test_suite = test_loader.discover('tests')

View File

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,53 @@
import json
import os
import unittest
from io import BytesIO
from pathlib import Path
from pdfjinja import PdfJinja
from app.tools.pdfjinja.insertTemplate import remplirTemplate
class insertTemplateTestCase(unittest.TestCase):
datadir = os.path.join(os.path.dirname(__file__))
def setUp(self):
pdffile = os.path.join(self.datadir, "sample.pdf")
self.data = {
'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
}
}
self.pdfjinja = PdfJinja(pdffile)
def tearDown(self):
del self.data
del self.pdfjinja
def test_render(self):
remplirTemplate(self.datadir,"sample.pdf",self.datadir,"output.pdf",self.data)
output = self.pdfjinja(self.data)
outfile = BytesIO()
output.write(outfile)
outfile.seek(0)
self.assertTrue(len(outfile.read()) > 0, "Output PDF is not empty.")
self.assertTrue(Path(self.datadir+"/output.pdf").is_file(),"Pdf généré inexistant")
os.remove(self.datadir+"/output.pdf")
if __name__ == '__main__':
unittest.main()

View File

@ -7,7 +7,7 @@ skipsdist = True
[testenv]
commands=
coverage run --source app/api --omit app/api/*/model.py manage.py runtests
coverage run --source app/api app/tools --omit app/api/*/model.py manage.py runtests
coverage report -m
coverage xml
coverage html