mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-18 15:33:49 +02:00
Fix tests and clean.
This commit is contained in:
parent
3b7d08a80e
commit
1a43ff118c
@ -20,10 +20,6 @@ This test suite check /project endpoint
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from tests.utils import asyncio_patch
|
|
||||||
from gns3server.version import __version__
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_project_with_dir(server, tmpdir):
|
def test_create_project_with_dir(server, tmpdir):
|
||||||
response = server.post("/project", {"location": str(tmpdir)})
|
response = server.post("/project", {"location": str(tmpdir)})
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
|
@ -20,7 +20,6 @@ This test suite check /version endpoint
|
|||||||
It's also used for unittest the HTTP implementation.
|
It's also used for unittest the HTTP implementation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from tests.utils import asyncio_patch
|
|
||||||
from gns3server.version import __version__
|
from gns3server.version import __version__
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,14 +15,25 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import pytest
|
||||||
from tests.utils import asyncio_patch
|
from tests.utils import asyncio_patch
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def vm(server, project):
|
||||||
|
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock:
|
||||||
|
response = server.post("/virtualbox", {"name": "VM1",
|
||||||
|
"vmname": "VM1",
|
||||||
|
"linked_clone": False,
|
||||||
|
"project_uuid": project.uuid})
|
||||||
|
assert mock.called
|
||||||
|
assert response.status == 201
|
||||||
|
return response.json
|
||||||
|
|
||||||
|
|
||||||
def test_vbox_create(server, project):
|
def test_vbox_create(server, project):
|
||||||
|
|
||||||
with asyncio_patch("gns3server.modules.VirtualBox.create_vm", return_value={"name": "VM1",
|
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True):
|
||||||
"uuid": "61d61bdd-aa7d-4912-817f-65a9eb54d3ab",
|
|
||||||
"project_uuid": project.uuid}):
|
|
||||||
response = server.post("/virtualbox", {"name": "VM1",
|
response = server.post("/virtualbox", {"name": "VM1",
|
||||||
"vmname": "VM1",
|
"vmname": "VM1",
|
||||||
"linked_clone": False,
|
"linked_clone": False,
|
||||||
@ -33,15 +44,29 @@ def test_vbox_create(server, project):
|
|||||||
assert response.json["project_uuid"] == project.uuid
|
assert response.json["project_uuid"] == project.uuid
|
||||||
|
|
||||||
|
|
||||||
def test_vbox_start(server):
|
def test_vbox_start(server, vm):
|
||||||
with asyncio_patch("gns3server.modules.VirtualBox.start_vm", return_value=True) as mock:
|
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock:
|
||||||
response = server.post("/virtualbox/61d61bdd-aa7d-4912-817f-65a9eb54d3ab/start", {}, example=True)
|
response = server.post("/virtualbox/{}/start".format(vm["uuid"]))
|
||||||
assert mock.called
|
assert mock.called
|
||||||
assert response.status == 204
|
assert response.status == 204
|
||||||
|
|
||||||
|
|
||||||
def test_vbox_stop(server):
|
def test_vbox_stop(server, vm):
|
||||||
with asyncio_patch("gns3server.modules.VirtualBox.stop_vm", return_value=True) as mock:
|
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.stop", return_value=True) as mock:
|
||||||
response = server.post("/virtualbox/61d61bdd-aa7d-4912-817f-65a9eb54d3ab/stop", {}, example=True)
|
response = server.post("/virtualbox/{}/stop".format(vm["uuid"]))
|
||||||
|
assert mock.called
|
||||||
|
assert response.status == 204
|
||||||
|
|
||||||
|
|
||||||
|
def test_vbox_suspend(server, vm):
|
||||||
|
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.suspend", return_value=True) as mock:
|
||||||
|
response = server.post("/virtualbox/{}/suspend".format(vm["uuid"]))
|
||||||
|
assert mock.called
|
||||||
|
assert response.status == 204
|
||||||
|
|
||||||
|
|
||||||
|
def test_vbox_resume(server, vm):
|
||||||
|
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.resume", return_value=True) as mock:
|
||||||
|
response = server.post("/virtualbox/{}/resume".format(vm["uuid"]))
|
||||||
assert mock.called
|
assert mock.called
|
||||||
assert response.status == 204
|
assert response.status == 204
|
||||||
|
@ -18,8 +18,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import os
|
import os
|
||||||
from tests.utils import asyncio_patch
|
from tests.utils import asyncio_patch
|
||||||
from unittest.mock import patch, Mock
|
from unittest.mock import patch
|
||||||
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
|
@ -48,4 +48,4 @@ def test_json(tmpdir):
|
|||||||
def test_vm_working_directory(tmpdir):
|
def test_vm_working_directory(tmpdir):
|
||||||
p = Project(location=str(tmpdir))
|
p = Project(location=str(tmpdir))
|
||||||
assert os.path.exists(p.vm_working_directory('vpcs', '00010203-0405-0607-0809-0a0b0c0d0e0f'))
|
assert os.path.exists(p.vm_working_directory('vpcs', '00010203-0405-0607-0809-0a0b0c0d0e0f'))
|
||||||
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, 'vms', 'vpcs', '00010203-0405-0607-0809-0a0b0c0d0e0f'))
|
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, 'vpcs', '00010203-0405-0607-0809-0a0b0c0d0e0f'))
|
||||||
|
@ -21,12 +21,10 @@ import os
|
|||||||
from tests.utils import asyncio_patch
|
from tests.utils import asyncio_patch
|
||||||
|
|
||||||
|
|
||||||
from asyncio.subprocess import Process
|
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
|
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
|
||||||
from gns3server.modules.vpcs.vpcs_error import VPCSError
|
from gns3server.modules.vpcs.vpcs_error import VPCSError
|
||||||
from gns3server.modules.vpcs import VPCS
|
from gns3server.modules.vpcs import VPCS
|
||||||
from gns3server.modules.port_manager import PortManager
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
|
Loading…
Reference in New Issue
Block a user