TG-35 : Typo
This commit is contained in:
commit
e06455ca84
@ -2,9 +2,24 @@ import os
|
|||||||
from PyPDF2 import PdfFileReader, PdfFileMerger
|
from PyPDF2 import PdfFileReader, PdfFileMerger
|
||||||
|
|
||||||
|
|
||||||
def fusion_fichiers(chemin_des_pdf, chemin_merge_pdf, nom_merge_pdf):
|
def fusion_fichiers(chemin_merge_pdf, nom_merge_pdf, liste_de_pdf):
|
||||||
pdf_files = [f for f in os.listdir(chemin_des_pdf) if f.endswith("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()
|
merger = PdfFileMerger()
|
||||||
for filename in pdf_files:
|
for filename in liste_de_pdf:
|
||||||
merger.append(PdfFileReader(os.path.join(chemin_des_pdf, filename), "rb"))
|
merger.append(PdfFileReader(os.path.join(filename), "rb"))
|
||||||
merger.write(os.path.join(chemin_merge_pdf, nom_merge_pdf))
|
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
|
from app.tools.InsertTemplate import remplir_template
|
||||||
|
|
||||||
|
|
||||||
class insertTemplateTestCase(unittest.TestCase):
|
class InsertTemplateTestCase(unittest.TestCase):
|
||||||
|
|
||||||
datadir = os.path.join(os.path.dirname(__file__))
|
datadir = os.path.join(os.path.dirname(__file__))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pdffile = os.path.join(self.datadir, "sample.pdf")
|
pdffile = os.path.join(self.datadir, "sample.pdf")
|
||||||
self.data = {
|
self.data = {
|
||||||
'firstName': 'Renan',
|
'firstName': 'Renan',
|
||||||
'lastName': 'Husson',
|
'lastName': 'Husson',
|
||||||
'address': {
|
'address': {
|
||||||
'street': '24 rue de la pommes',
|
'street': '24 rue de la pommes',
|
||||||
'apt': 'C317',
|
'apt': 'C317',
|
||||||
'city': 'TOULOUSE',
|
'city': 'TOULOUSE',
|
||||||
'zipcode': 31000
|
'zipcode': 31000
|
||||||
},
|
},
|
||||||
'universite':'Jean Jaures',
|
'universite': 'Jean Jaures',
|
||||||
'spirit': 'Panda',
|
'spirit': 'Panda',
|
||||||
'evil': True,
|
'evil': True,
|
||||||
'language': {
|
'language': {
|
||||||
'french': True,
|
'french': True,
|
||||||
'esperento': True
|
'esperento': True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.pdfjinja = PdfJinja(pdffile)
|
self.pdfjinja = PdfJinja(pdffile)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
@ -44,9 +43,9 @@ class insertTemplateTestCase(unittest.TestCase):
|
|||||||
output.write(outfile)
|
output.write(outfile)
|
||||||
outfile.seek(0)
|
outfile.seek(0)
|
||||||
self.assertTrue(len(outfile.read()) > 0, "Output PDF is not empty.")
|
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")
|
self.assertTrue(Path(self.datadir + "/output.pdf").is_file(), "Pdf généré inexistant")
|
||||||
os.remove(self.datadir+"/output.pdf")
|
os.remove(self.datadir + "/output.pdf")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -11,3 +11,4 @@ commands = coverage run --source app/api,app/tools manage.py -t runtests
|
|||||||
coverage xml
|
coverage xml
|
||||||
coverage html
|
coverage html
|
||||||
deps=-r{toxinidir}/requirements/test.txt
|
deps=-r{toxinidir}/requirements/test.txt
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user