mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Snapshot refactoring
This commit is contained in:
8 files changed
+125
-45
No files matched your search
@@ -68,7 +68,6 @@ def test_exportable_files():
|
||||
assert not _is_exportable("project-files/tmp")
|
||||
assert not _is_exportable("project-files/test_log.txt")
|
||||
assert not _is_exportable("project-files/test.log")
|
||||
assert not _is_exportable("test/snapshots")
|
||||
assert not _is_exportable("test/project-files/snapshots")
|
||||
assert not _is_exportable("test/project-files/snapshots/test.gns3p")
|
||||
|
||||
|
||||
@@ -16,22 +16,16 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
from uuid import uuid4
|
||||
|
||||
from gns3server.controller.project import Project
|
||||
import pytest
|
||||
from unittest import mock
|
||||
from unittest.mock import patch, MagicMock
|
||||
from gns3server.controller.snapshot import Snapshot
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
|
||||
# @pytest.fixture
|
||||
# def project(controller):
|
||||
# project = Project(controller=controller, name="Test")
|
||||
# controller._projects[project.id] = project
|
||||
# return project
|
||||
|
||||
|
||||
def test_snapshot_name(project):
|
||||
"""
|
||||
Test create a snapshot object with a name
|
||||
@@ -40,12 +34,7 @@ def test_snapshot_name(project):
|
||||
snapshot = Snapshot(project, name="test1")
|
||||
assert snapshot.name == "test1"
|
||||
assert snapshot._created_at > 0
|
||||
assert snapshot.path.startswith(os.path.join(project.path, "snapshots", "test1_"))
|
||||
assert snapshot.path.endswith(".gns3project")
|
||||
|
||||
# Check if UTC conversion doesn't corrupt the path
|
||||
snap2 = Snapshot(project, filename=os.path.basename(snapshot.path))
|
||||
assert snap2.path == snapshot.path
|
||||
assert snapshot.path == os.path.join(project.path, "snapshots", "test1.gns3snapshot")
|
||||
|
||||
|
||||
def test_snapshot_filename(project):
|
||||
@@ -53,22 +42,42 @@ def test_snapshot_filename(project):
|
||||
Test create a snapshot object with a filename
|
||||
"""
|
||||
|
||||
# legacy snapshot
|
||||
snapshot = Snapshot(project, filename="test1_260716_100439.gns3project")
|
||||
assert snapshot.name == "test1"
|
||||
assert snapshot._created_at == 1469527479.0
|
||||
assert snapshot._created_at == 1469527479
|
||||
assert snapshot.path == os.path.join(project.path, "snapshots", "test1_260716_100439.gns3project")
|
||||
|
||||
# new style snapshot
|
||||
snapshot_id = str(uuid4())
|
||||
snapshot = Snapshot(project, snapshot_id=snapshot_id, name="test2", created_at=1469527479)
|
||||
assert snapshot.id == snapshot_id
|
||||
assert snapshot.name == "test2"
|
||||
assert snapshot.path == os.path.join(project.path, "snapshots", "test2.gns3snapshot")
|
||||
assert snapshot._created_at == 1469527479
|
||||
|
||||
|
||||
def test_json(project):
|
||||
|
||||
# legacy snapshot
|
||||
snapshot = Snapshot(project, filename="snapshot_test_260716_100439.gns3project")
|
||||
assert snapshot.__json__() == {
|
||||
"snapshot_id": snapshot._id,
|
||||
"name": "snapshot_test",
|
||||
"project_id": project.id,
|
||||
"filename": "snapshot_test_260716_100439.gns3project",
|
||||
"created_at": 1469527479
|
||||
}
|
||||
|
||||
# new style snapshot
|
||||
snapshot = Snapshot(project, name="snapshot_test2")
|
||||
assert snapshot.__json__() == {
|
||||
"snapshot_id": snapshot._id,
|
||||
"name": "snapshot_test2",
|
||||
"project_id": project.id,
|
||||
"filename": "snapshot_test2.gns3snapshot",
|
||||
"created_at": mock.ANY
|
||||
}
|
||||
|
||||
def test_invalid_snapshot_filename(project):
|
||||
|
||||
|
||||
Reference in new issue
Block a user