TG-35 : Typo
This commit is contained in:
commit
e06455ca84
@ -2,9 +2,24 @@ import os
|
||||
from PyPDF2 import PdfFileReader, PdfFileMerger
|
||||
|
||||
|
||||
def fusion_fichiers(chemin_des_pdf, chemin_merge_pdf, nom_merge_pdf):
|
||||
pdf_files = [f for f in os.listdir(chemin_des_pdf) if f.endswith("pdf")]
|
||||
def fusion_fichiers(chemin_merge_pdf, nom_merge_pdf, liste_de_pdf):
|
||||
"""
|
||||
Permet de fusionner un ensemble de pdf
|
||||
:param chemin_merge_pdf: chemin ou l'on souhaite fusioner l'ensemble des pdf
|
||||
:param nom_merge_pdf: nom que l'on souhaite donner au fichier pdf final
|
||||
:param liste_de_pdf: liste de pdf avec leur chemin inclu
|
||||
:return:
|
||||
"""
|
||||
merger = PdfFileMerger()
|
||||
for filename in pdf_files:
|
||||
merger.append(PdfFileReader(os.path.join(chemin_des_pdf, filename), "rb"))
|
||||
for filename in liste_de_pdf:
|
||||
merger.append(PdfFileReader(os.path.join(filename), "rb"))
|
||||
merger.write(os.path.join(chemin_merge_pdf, nom_merge_pdf))
|
||||
|
||||
|
||||
def get_pdf_from_directory(chemin_des_pdf):
|
||||
"""
|
||||
Permet de récuperer l'ensemble des pdf d'un chemin
|
||||
:param chemin_des_pdf:
|
||||
:return:
|
||||
"""
|
||||
return [f for f in os.listdir(chemin_des_pdf) if f.endswith("pdf")]
|
||||
|
@ -0,0 +1,21 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from builtins import print
|
||||
|
||||
from app.tools.FusionPdf import fusion_fichiers, get_pdf_from_directory
|
||||
|
||||
|
||||
class TestFusionTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.datadir = os.path.join(os.path.dirname(__file__))
|
||||
self.list_pdf = [self.datadir + "/page1.pdf", self.datadir + "/page2.pdf"]
|
||||
|
||||
def test_fusion(self):
|
||||
fusion_fichiers(self.datadir, "testFusion.pdf", self.list_pdf)
|
||||
print(self.datadir)
|
||||
self.assertTrue(Path(self.datadir + "/testFusion.pdf").is_file(), "Pdf fusionne inexistant")
|
||||
self.assertTrue(len(get_pdf_from_directory(self.datadir)) > 0, "pdf non trouve")
|
||||
os.remove(self.datadir + "/testFusion.pdf")
|
BIN
backend/tests/tools/PyPDF2/page1.pdf
Normal file
BIN
backend/tests/tools/PyPDF2/page1.pdf
Normal file
Binary file not shown.
BIN
backend/tests/tools/PyPDF2/page2.pdf
Normal file
BIN
backend/tests/tools/PyPDF2/page2.pdf
Normal file
Binary file not shown.
@ -8,29 +8,28 @@ from pdfjinja import PdfJinja
|
||||
from app.tools.InsertTemplate import remplir_template
|
||||
|
||||
|
||||
class insertTemplateTestCase(unittest.TestCase):
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
'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):
|
||||
@ -44,8 +43,8 @@ class insertTemplateTestCase(unittest.TestCase):
|
||||
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")
|
||||
self.assertTrue(Path(self.datadir + "/output.pdf").is_file(), "Pdf généré inexistant")
|
||||
os.remove(self.datadir + "/output.pdf")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -11,3 +11,4 @@ commands = coverage run --source app/api,app/tools manage.py -t runtests
|
||||
coverage xml
|
||||
coverage html
|
||||
deps=-r{toxinidir}/requirements/test.txt
|
||||
|
||||
|
Reference in New Issue
Block a user