1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-15 12:59:06 +00:00

Fix tests and clean.

This commit is contained in:
Jeremy 2015-01-21 19:30:24 -07:00
parent 3b7d08a80e
commit 1a43ff118c
6 changed files with 36 additions and 19 deletions

View File

@ -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):
response = server.post("/project", {"location": str(tmpdir)})
assert response.status == 200

View File

@ -20,7 +20,6 @@ This test suite check /version endpoint
It's also used for unittest the HTTP implementation.
"""
from tests.utils import asyncio_patch
from gns3server.version import __version__

View File

@ -15,14 +15,25 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
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):
with asyncio_patch("gns3server.modules.VirtualBox.create_vm", return_value={"name": "VM1",
"uuid": "61d61bdd-aa7d-4912-817f-65a9eb54d3ab",
"project_uuid": project.uuid}):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True):
response = server.post("/virtualbox", {"name": "VM1",
"vmname": "VM1",
"linked_clone": False,
@ -33,15 +44,29 @@ def test_vbox_create(server, project):
assert response.json["project_uuid"] == project.uuid
def test_vbox_start(server):
with asyncio_patch("gns3server.modules.VirtualBox.start_vm", return_value=True) as mock:
response = server.post("/virtualbox/61d61bdd-aa7d-4912-817f-65a9eb54d3ab/start", {}, example=True)
def test_vbox_start(server, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock:
response = server.post("/virtualbox/{}/start".format(vm["uuid"]))
assert mock.called
assert response.status == 204
def test_vbox_stop(server):
with asyncio_patch("gns3server.modules.VirtualBox.stop_vm", return_value=True) as mock:
response = server.post("/virtualbox/61d61bdd-aa7d-4912-817f-65a9eb54d3ab/stop", {}, example=True)
def test_vbox_stop(server, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.stop", return_value=True) as mock:
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 response.status == 204

View File

@ -18,8 +18,7 @@
import pytest
import os
from tests.utils import asyncio_patch
from unittest.mock import patch, Mock
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
from unittest.mock import patch
@pytest.fixture(scope="module")

View File

@ -48,4 +48,4 @@ def test_json(tmpdir):
def test_vm_working_directory(tmpdir):
p = Project(location=str(tmpdir))
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'))

View File

@ -21,12 +21,10 @@ import os
from tests.utils import asyncio_patch
from asyncio.subprocess import Process
from unittest.mock import patch, MagicMock
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
from gns3server.modules.vpcs.vpcs_error import VPCSError
from gns3server.modules.vpcs import VPCS
from gns3server.modules.port_manager import PortManager
@pytest.fixture(scope="module")