From 0bcc657bf1ab10f38a1f3db6212b0ed025d81818 Mon Sep 17 00:00:00 2001 From: ziajka Date: Tue, 8 May 2018 16:22:35 +0200 Subject: [PATCH] Don't clean logo images when applied to the project --- gns3server/controller/project.py | 9 +++++++++ tests/controller/test_project.py | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index ceee6939..59bcfedc 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -725,6 +725,15 @@ class Project: except KeyError: pass + # don't remove supplier's logo + if self.supplier: + try: + logo = self.supplier['logo'] + pictures.remove(logo) + except KeyError: + pass + + for pict in pictures: os.remove(os.path.join(self.pictures_directory, pict)) except OSError as e: diff --git a/tests/controller/test_project.py b/tests/controller/test_project.py index 5c788a1b..1e76d39e 100644 --- a/tests/controller/test_project.py +++ b/tests/controller/test_project.py @@ -397,6 +397,26 @@ def test_clean_pictures(async_run, project, controller): assert not os.path.exists(os.path.join(project.pictures_directory, "test2.png")) +def test_clean_pictures_and_keep_supplier_logo(async_run, project, controller): + """ + When a project is close old pictures should be removed + """ + project.supplier = { + 'logo': 'logo.png' + } + + drawing = async_run(project.add_drawing()) + drawing._svg = "test.png" + open(os.path.join(project.pictures_directory, "test.png"), "w+").close() + open(os.path.join(project.pictures_directory, "test2.png"), "w+").close() + open(os.path.join(project.pictures_directory, "logo.png"), "w+").close() + + async_run(project.close()) + assert os.path.exists(os.path.join(project.pictures_directory, "test.png")) + assert not os.path.exists(os.path.join(project.pictures_directory, "test2.png")) + assert os.path.exists(os.path.join(project.pictures_directory, "logo.png")) + + def test_delete(async_run, project, controller): assert os.path.exists(project.path) async_run(project.delete())