mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-12 19:38:57 +00:00
Test start / stop. And check if the mocked function is really called
This commit is contained in:
parent
87a089457f
commit
ce9fd3cb25
@ -21,5 +21,5 @@ X-ROUTE: /vpcs
|
||||
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80",
|
||||
"script_file": null,
|
||||
"startup_script": null,
|
||||
"uuid": "009a7260-e44c-4349-8df7-08668a3c4e17"
|
||||
"uuid": "6370f75e-0a48-4e2b-95a8-0140da6ef1fb"
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class Query:
|
||||
self._port = port
|
||||
self._host = host
|
||||
|
||||
def post(self, path, body, **kwargs):
|
||||
def post(self, path, body={}, **kwargs):
|
||||
return self._fetch("POST", path, body, **kwargs)
|
||||
|
||||
def get(self, path, **kwargs):
|
||||
|
@ -19,7 +19,7 @@ import pytest
|
||||
import os
|
||||
from tests.api.base import server, loop, project
|
||||
from tests.utils import asyncio_patch
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import patch, Mock
|
||||
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
|
||||
|
||||
|
||||
@ -99,11 +99,15 @@ def test_vpcs_delete_nio(server, vm):
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
|
||||
|
||||
|
||||
def test_vpcs_start():
|
||||
# assert True == False
|
||||
pass
|
||||
def test_vpcs_start(server, vm):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock:
|
||||
response = server.post("/vpcs/{}/start".format(vm["uuid"]))
|
||||
assert mock.called
|
||||
assert response.status == 200
|
||||
|
||||
|
||||
def test_vpcs_stop():
|
||||
# assert True == False
|
||||
pass
|
||||
def test_vpcs_stop(server, vm):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.stop", return_value=True) as mock:
|
||||
response = server.post("/vpcs/{}/stop".format(vm["uuid"]))
|
||||
assert mock.called
|
||||
assert response.status == 200
|
||||
|
@ -39,7 +39,8 @@ class _asyncio_patch:
|
||||
def __enter__(self):
|
||||
"""Used when enter in the with block"""
|
||||
self._patcher = patch(self.function, return_value=self._fake_anwser())
|
||||
self._patcher.start()
|
||||
mock_class = self._patcher.start()
|
||||
return mock_class
|
||||
|
||||
def __exit__(self, *exc_info):
|
||||
"""Used when leaving the with block"""
|
||||
|
Loading…
Reference in New Issue
Block a user