diff --git a/backend/app/tools/LibPdf.py b/backend/app/tools/LibPdf.py index 03b9a10..da93aa5 100644 --- a/backend/app/tools/LibPdf.py +++ b/backend/app/tools/LibPdf.py @@ -53,14 +53,14 @@ def allowed_file(filename): filename.rsplit('.', 1)[1].lower() in allowed_extensions -def upload_file(file, upload_folder): +def upload_file(file_to_upload, upload_folder): """ rep de l'etu avec id :param file: :param upload_folder: :return: """ - file.save(secure_filename(os.path.join(upload_folder, file.filename))) + file_to_upload.save(os.path.join(upload_folder, secure_filename(file_to_upload.filename))) diff --git a/backend/tests/tools/PyPDF2/__init__.py b/backend/tests/tools/libPdf/PyPDF2/__init__.py similarity index 100% rename from backend/tests/tools/PyPDF2/__init__.py rename to backend/tests/tools/libPdf/PyPDF2/__init__.py diff --git a/backend/tests/tools/PyPDF2/page1.pdf b/backend/tests/tools/libPdf/PyPDF2/page1.pdf similarity index 100% rename from backend/tests/tools/PyPDF2/page1.pdf rename to backend/tests/tools/libPdf/PyPDF2/page1.pdf diff --git a/backend/tests/tools/PyPDF2/page2.pdf b/backend/tests/tools/libPdf/PyPDF2/page2.pdf similarity index 100% rename from backend/tests/tools/PyPDF2/page2.pdf rename to backend/tests/tools/libPdf/PyPDF2/page2.pdf diff --git a/backend/tests/tools/PyPDF2/testFusionFichiers.py b/backend/tests/tools/libPdf/PyPDF2/testFusionFichiers.py similarity index 99% rename from backend/tests/tools/PyPDF2/testFusionFichiers.py rename to backend/tests/tools/libPdf/PyPDF2/testFusionFichiers.py index 0fb6737..02cccaf 100644 --- a/backend/tests/tools/PyPDF2/testFusionFichiers.py +++ b/backend/tests/tools/libPdf/PyPDF2/testFusionFichiers.py @@ -1,9 +1,7 @@ import os import unittest - -from pathlib import Path - from builtins import print +from pathlib import Path from app.tools.FusionPdf import fusion_fichiers, get_pdf_from_directory diff --git a/backend/tests/tools/libPdf/UploadPDF/page1.pdf b/backend/tests/tools/libPdf/UploadPDF/page1.pdf new file mode 100644 index 0000000..6b4e9cc Binary files /dev/null and b/backend/tests/tools/libPdf/UploadPDF/page1.pdf differ diff --git a/backend/tests/tools/libPdf/UploadPDF/testUploadPdf.py b/backend/tests/tools/libPdf/UploadPDF/testUploadPdf.py new file mode 100644 index 0000000..45e1940 --- /dev/null +++ b/backend/tests/tools/libPdf/UploadPDF/testUploadPdf.py @@ -0,0 +1,20 @@ +import os +import unittest + +from werkzeug.datastructures import FileStorage + +from app.tools.LibPdf import upload_file + + +class TestFusionTestCase(unittest.TestCase): + def setUp(self): + self.datadir = os.path.join(os.path.dirname(__file__)) + + def test_fusion(self): + with open("page1.pdf", 'rb') as fp: + file = FileStorage(fp) + upload_file(file, "upload") + + # 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") diff --git a/backend/tests/tools/pdfjinja/__init__.py b/backend/tests/tools/libPdf/__init__.py similarity index 100% rename from backend/tests/tools/pdfjinja/__init__.py rename to backend/tests/tools/libPdf/__init__.py diff --git a/backend/tests/tools/libPdf/pdfjinja/__init__.py b/backend/tests/tools/libPdf/pdfjinja/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/tests/tools/pdfjinja/sample.pdf b/backend/tests/tools/libPdf/pdfjinja/sample.pdf similarity index 100% rename from backend/tests/tools/pdfjinja/sample.pdf rename to backend/tests/tools/libPdf/pdfjinja/sample.pdf diff --git a/backend/tests/tools/pdfjinja/sample_backup.pdf b/backend/tests/tools/libPdf/pdfjinja/sample_backup.pdf similarity index 100% rename from backend/tests/tools/pdfjinja/sample_backup.pdf rename to backend/tests/tools/libPdf/pdfjinja/sample_backup.pdf diff --git a/backend/tests/tools/pdfjinja/testInsertTemplate.py b/backend/tests/tools/libPdf/pdfjinja/testInsertTemplate.py similarity index 99% rename from backend/tests/tools/pdfjinja/testInsertTemplate.py rename to backend/tests/tools/libPdf/pdfjinja/testInsertTemplate.py index 68911c2..9cf6078 100644 --- a/backend/tests/tools/pdfjinja/testInsertTemplate.py +++ b/backend/tests/tools/libPdf/pdfjinja/testInsertTemplate.py @@ -3,9 +3,8 @@ import unittest from io import BytesIO from pathlib import Path -from pdfjinja import PdfJinja - from app.tools.InsertTemplate import remplir_template +from pdfjinja import PdfJinja class InsertTemplateTestCase(unittest.TestCase):