mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Optimize storage of drawing
If the drawing contain an image we extract it Fix #591
This commit is contained in:
6 files changed
+244
-6
No files matched your search
@@ -18,6 +18,7 @@
|
||||
from unittest.mock import MagicMock
|
||||
import pytest
|
||||
import uuid
|
||||
import os
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
@@ -90,3 +91,33 @@ def test_update(drawing, project, async_run, controller):
|
||||
assert "svg" not in args[1]
|
||||
|
||||
assert project.dump.called
|
||||
|
||||
|
||||
def test_image_base64(project):
|
||||
"""
|
||||
If image are embed as base 64 we need to dump them on disk
|
||||
"""
|
||||
svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"128\" width=\"128\">\n<image height=\"128\" width=\"128\" xlink:href=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAACXBIWXMAAAN2AAADdgF91YLMAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAHm5JREFUeJztnXl8FGXSx7/VIYAKKCoe4IEIq6ALuQnI4YXXKihulCSACIIsu4qKNyqXByqK67EeiMtyJGrwXnfABSu/L3I31aclPub3oBIQ/YD2zdUBZ+T37l7Dt0OAKoIYcUf07mBhpkieonJe+FcAUOgeX8dL/4ysTCSmTiwwsx1FPLJfuas89mXsByu/N/BR43E09+xMafDrYFI6wmzINu7QreFo1kD4EQIW/m8ICm1iAdBXWp0wuusiJp+Q7ilok3VE02RR+MoWPTYMXTYNlarAx6c6iQU7X/RbQ4DZA2m1F44CnrdYjDPG8ZcLBe/1kzz2Z9ybfUZQALAS\" />\n</svg>"
|
||||
|
||||
drawing = Drawing(project, None, svg=svg)
|
||||
assert drawing._svg == "8418154b760b4e8023650e04c4992e24.png"
|
||||
assert os.path.exists(os.path.join(project.pictures_directory, "8418154b760b4e8023650e04c4992e24.png"))
|
||||
|
||||
assert drawing.svg == svg
|
||||
|
||||
|
||||
def test_image_svg(project):
|
||||
"""
|
||||
Large SVG are dump on disk
|
||||
"""
|
||||
svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"128\" width=\"128\">\n"
|
||||
|
||||
for i in range(0, 1000):
|
||||
svg += "<rect width=\"100\"></rect>"
|
||||
svg += "</svg>"
|
||||
|
||||
drawing = Drawing(project, None, svg=svg)
|
||||
assert drawing._svg == "fdf4d3035774a72ba165f7199b9431b2.svg"
|
||||
assert os.path.exists(os.path.join(project.pictures_directory, "fdf4d3035774a72ba165f7199b9431b2.svg"))
|
||||
|
||||
assert drawing.svg == svg
|
||||
@@ -265,6 +265,20 @@ def test_deleteDrawing(async_run, project, controller):
|
||||
assert len(project._drawings) == 0
|
||||
|
||||
|
||||
def test_cleanPictures(async_run, project, controller):
|
||||
"""
|
||||
When a project is close old pictures should be removed
|
||||
"""
|
||||
|
||||
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()
|
||||
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"))
|
||||
|
||||
|
||||
def test_delete(async_run, project, controller):
|
||||
assert os.path.exists(project.path)
|
||||
async_run(project.delete())
|
||||
|
||||
Reference in new issue
Block a user