mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Fix project import to work with FastAPI.
This commit is contained in:
1 parent
5653a8afb6
commit
25494ca098
3 files changed
+22
-26
No files matched your search
@@ -259,6 +259,7 @@ def run_around_tests(monkeypatch, config, port_manager):#port_manager, controlle
|
||||
config.set("Server", "appliances_path", os.path.join(tmppath, 'appliances'))
|
||||
config.set("Server", "ubridge_path", os.path.join(tmppath, 'bin', 'ubridge'))
|
||||
config.set("Server", "auth", False)
|
||||
config.set("Server", "local", True)
|
||||
|
||||
# Prevent executions of the VM if we forgot to mock something
|
||||
config.set("VirtualBox", "vboxmanage_path", tmppath)
|
||||
|
||||
@@ -21,10 +21,8 @@ import pytest
|
||||
import zipfile
|
||||
import json
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from unittest.mock import patch, MagicMock
|
||||
from tests.utils import asyncio_patch
|
||||
from gns3server.app import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -362,22 +360,22 @@ async def test_write_and_get_file_with_leading_slashes_in_filename(controller_ap
|
||||
assert response.content == b"world"
|
||||
|
||||
|
||||
# @pytest.mark.asyncio
|
||||
# async def test_import(controller_api, tmpdir, controller):
|
||||
#
|
||||
# with zipfile.ZipFile(str(tmpdir / "test.zip"), 'w') as myzip:
|
||||
# myzip.writestr("project.gns3", b'{"project_id": "c6992992-ac72-47dc-833b-54aa334bcd05", "version": "2.0.0", "name": "test"}')
|
||||
# myzip.writestr("demo", b"hello")
|
||||
#
|
||||
# project_id = str(uuid.uuid4())
|
||||
# with open(str(tmpdir / "test.zip"), "rb") as f:
|
||||
# response = await controller_api.post("/projects/{project_id}/import".format(project_id=project_id), body=f.read(), raw=True)
|
||||
# assert response.status_code == 201
|
||||
#
|
||||
# project = controller.get_project(project_id)
|
||||
# with open(os.path.join(project.path, "demo")) as f:
|
||||
# content = f.read()
|
||||
# assert content == "hello"
|
||||
@pytest.mark.asyncio
|
||||
async def test_import(controller_api, tmpdir, controller):
|
||||
|
||||
with zipfile.ZipFile(str(tmpdir / "test.zip"), 'w') as myzip:
|
||||
myzip.writestr("project.gns3", b'{"project_id": "c6992992-ac72-47dc-833b-54aa334bcd05", "version": "2.0.0", "name": "test"}')
|
||||
myzip.writestr("demo", b"hello")
|
||||
|
||||
project_id = str(uuid.uuid4())
|
||||
with open(str(tmpdir / "test.zip"), "rb") as f:
|
||||
response = await controller_api.post("/projects/{project_id}/import".format(project_id=project_id), body=f.read(), raw=True)
|
||||
assert response.status_code == 201
|
||||
|
||||
project = controller.get_project(project_id)
|
||||
with open(os.path.join(project.path, "demo")) as f:
|
||||
content = f.read()
|
||||
assert content == "hello"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in new issue
Block a user