Migration to FastAPI

This commit is contained in:
grossmj committed 2020-10-02 16:07:50 +09:30
1 parent c12b675691
commit eb3cb8a41f
224 files changed
+11254 -13517

No files matched your search

+17 -5
View File
@@ -19,7 +19,6 @@
import os
import json
import pytest
import aiohttp
import zipfile
from pathlib import Path
@@ -30,10 +29,12 @@ from tests.utils import AsyncioMagicMock, AsyncioBytesIO
from gns3server.controller.project import Project
from gns3server.controller.export_project import export_project, _is_exportable
from gns3server.utils.asyncio import aiozipstream
from gns3server.controller.controller_error import ControllerError
@pytest.fixture
async def project(loop, controller):
@pytest.mark.asyncio
async def project(controller):
p = Project(controller=controller, name="test")
p.dump = MagicMock()
@@ -41,6 +42,7 @@ async def project(loop, controller):
@pytest.fixture
@pytest.mark.asyncio
async def node(controller, project):
compute = MagicMock()
@@ -54,6 +56,7 @@ async def node(controller, project):
return node
@pytest.mark.asyncio
async def write_file(path, z):
with open(path, 'wb') as f:
@@ -72,6 +75,7 @@ def test_exportable_files():
assert not _is_exportable("test/project-files/snapshots/test.gns3p")
@pytest.mark.asyncio
async def test_export(tmpdir, project):
path = project.path
@@ -138,6 +142,7 @@ async def test_export(tmpdir, project):
assert topo["computes"] == []
@pytest.mark.asyncio
async def test_export_vm(tmpdir, project):
"""
If data is on a remote server export it locally before
@@ -175,6 +180,7 @@ async def test_export_vm(tmpdir, project):
assert content == b"HELLO"
@pytest.mark.asyncio
async def test_export_disallow_running(tmpdir, project, node):
"""
Disallow export when a node is running
@@ -196,11 +202,12 @@ async def test_export_disallow_running(tmpdir, project, node):
json.dump(topology, f)
node._status = "started"
with pytest.raises(aiohttp.web.HTTPConflict):
with pytest.raises(ControllerError):
with aiozipstream.ZipFile() as z:
await export_project(z, project, str(tmpdir))
@pytest.mark.asyncio
async def test_export_disallow_some_type(tmpdir, project):
"""
Disallow export for some node type
@@ -221,7 +228,7 @@ async def test_export_disallow_some_type(tmpdir, project):
with open(os.path.join(path, "test.gns3"), 'w+') as f:
json.dump(topology, f)
with pytest.raises(aiohttp.web.HTTPConflict):
with pytest.raises(ControllerError):
with aiozipstream.ZipFile() as z:
await export_project(z, project, str(tmpdir))
with aiozipstream.ZipFile() as z:
@@ -242,11 +249,12 @@ async def test_export_disallow_some_type(tmpdir, project):
}
with open(os.path.join(path, "test.gns3"), 'w+') as f:
json.dump(topology, f)
with pytest.raises(aiohttp.web.HTTPConflict):
with pytest.raises(ControllerError):
with aiozipstream.ZipFile() as z:
await export_project(z, project, str(tmpdir), allow_all_nodes=True)
@pytest.mark.asyncio
async def test_export_fix_path(tmpdir, project):
"""
Fix absolute image path, except for Docker
@@ -288,6 +296,7 @@ async def test_export_fix_path(tmpdir, project):
assert topology["topology"]["nodes"][1]["properties"]["image"] == "gns3/webterm:lastest"
@pytest.mark.asyncio
async def test_export_with_images(tmpdir, project):
"""
Fix absolute image path
@@ -323,6 +332,7 @@ async def test_export_with_images(tmpdir, project):
myzip.getinfo("images/IOS/test.image")
@pytest.mark.asyncio
async def test_export_keep_compute_id(tmpdir, project):
"""
If we want to restore the same computes we could ask to keep them
@@ -362,6 +372,7 @@ async def test_export_keep_compute_id(tmpdir, project):
assert len(topo["computes"]) == 1
@pytest.mark.asyncio
async def test_export_images_from_vm(tmpdir, project):
"""
If data is on a remote server export it locally before
@@ -426,6 +437,7 @@ async def test_export_images_from_vm(tmpdir, project):
assert content == b"IMAGE"
@pytest.mark.asyncio
async def test_export_with_ignoring_snapshots(tmpdir, project):
with open(os.path.join(project.path, "test.gns3"), 'w+') as f: